OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox_impl.h" | 5 #include "sandbox_impl.h" |
6 | 6 |
7 #include "library.h" | 7 #include "library.h" |
8 #include "syscall_entrypoint.h" | 8 #include "syscall_entrypoint.h" |
9 #include "system_call_table.h" | 9 #include "system_call_table.h" |
10 | 10 |
11 namespace playground { | 11 namespace playground { |
12 | 12 |
13 // Global variables | 13 // Global variables |
14 int Sandbox::proc_ = -1; | |
15 int Sandbox::proc_self_maps_ = -1; | 14 int Sandbox::proc_self_maps_ = -1; |
16 enum Sandbox::SandboxStatus Sandbox::status_ = STATUS_UNKNOWN; | 15 enum Sandbox::SandboxStatus Sandbox::status_ = STATUS_UNKNOWN; |
17 int Sandbox::pid_; | 16 int Sandbox::pid_; |
18 int Sandbox::processFdPub_; | 17 int Sandbox::processFdPub_; |
19 int Sandbox::cloneFdPub_ | 18 int Sandbox::cloneFdPub_ |
20 // This is necessary to locate the symbol from assembly code on | 19 // This is necessary to locate the symbol from assembly code on |
21 // x86-64 (with %rip-relative addressing) in order for this to work | 20 // x86-64 (with %rip-relative addressing) in order for this to work |
22 // in relocatable code (a .so or a PIE). On i386 this is not | 21 // in relocatable code (a .so or a PIE). On i386 this is not |
23 // necessary but it does not hurt. | 22 // necessary but it does not hurt. |
24 __attribute__((visibility("internal"))); | 23 __attribute__((visibility("internal"))); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 status_ = STATUS_AVAILABLE; | 244 status_ = STATUS_AVAILABLE; |
246 } | 245 } |
247 int rc; | 246 int rc; |
248 (void)NOINTR_SYS(sys.waitpid(pid, &rc, 0)); | 247 (void)NOINTR_SYS(sys.waitpid(pid, &rc, 0)); |
249 (void)NOINTR_SYS(sys.close(fds[0])); | 248 (void)NOINTR_SYS(sys.close(fds[0])); |
250 return status_ != STATUS_UNSUPPORTED; | 249 return status_ != STATUS_UNSUPPORTED; |
251 } | 250 } |
252 } | 251 } |
253 | 252 |
254 void Sandbox::setProcFd(int proc) { | 253 void Sandbox::setProcFd(int proc) { |
255 proc_ = proc; | 254 if (proc >= 0) { |
| 255 SysCalls sys; |
| 256 proc_self_maps_ = sys.openat(proc, "self/maps", O_RDONLY, 0); |
| 257 if (NOINTR_SYS(sys.close(proc))) { |
| 258 die("Failed to close file descriptor pointing to /proc"); |
| 259 } |
| 260 } |
256 } | 261 } |
257 | 262 |
258 void Sandbox::startSandbox() { | 263 void Sandbox::startSandbox() { |
259 if (status_ == STATUS_UNSUPPORTED) { | 264 if (status_ == STATUS_UNSUPPORTED) { |
260 die("The seccomp sandbox is not supported on this computer"); | 265 die("The seccomp sandbox is not supported on this computer"); |
261 } else if (status_ == STATUS_ENABLED) { | 266 } else if (status_ == STATUS_ENABLED) { |
262 return; | 267 return; |
263 } | 268 } |
264 | 269 |
265 SysCalls sys; | 270 SysCalls sys; |
266 if (proc_ >= 0) { | |
267 proc_self_maps_ = sys.openat(proc_, "self/maps", O_RDONLY, 0); | |
268 if (NOINTR_SYS(sys.close(proc_))) { | |
269 die("Failed to close file descriptor pointing to /proc"); | |
270 } | |
271 proc_ = -1; | |
272 } | |
273 if (proc_self_maps_ < 0) { | 271 if (proc_self_maps_ < 0) { |
274 proc_self_maps_ = sys.open("/proc/self/maps", O_RDONLY, 0); | 272 proc_self_maps_ = sys.open("/proc/self/maps", O_RDONLY, 0); |
275 if (proc_self_maps_ < 0) { | 273 if (proc_self_maps_ < 0) { |
276 die("Cannot access \"/proc/self/maps\""); | 274 die("Cannot access \"/proc/self/maps\""); |
277 } | 275 } |
278 } | 276 } |
279 | 277 |
280 // The pid is unchanged for the entire program, so we can retrieve it once | 278 // The pid is unchanged for the entire program, so we can retrieve it once |
281 // and store it in a global variable. | 279 // and store it in a global variable. |
282 pid_ = sys.getpid(); | 280 pid_ = sys.getpid(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 } entrypoint; | 384 } entrypoint; |
387 *entrypoint.get_syscall_entrypoint() = syscallEntryPointNoFrame; | 385 *entrypoint.get_syscall_entrypoint() = syscallEntryPointNoFrame; |
388 | 386 |
389 // We can no longer check for sandboxing support at this point, but we also | 387 // We can no longer check for sandboxing support at this point, but we also |
390 // know for a fact that it is available (as we just turned it on). So update | 388 // know for a fact that it is available (as we just turned it on). So update |
391 // the status to reflect this information. | 389 // the status to reflect this information. |
392 status_ = STATUS_ENABLED; | 390 status_ = STATUS_ENABLED; |
393 } | 391 } |
394 | 392 |
395 } // namespace | 393 } // namespace |
OLD | NEW |