| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/nacl/loader/nonsfi/nonsfi_sandbox.h" | 5 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <linux/net.h> | 9 #include <linux/net.h> |
| 10 #include <sys/prctl.h> | 10 #include <sys/prctl.h> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL)))); | 73 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL)))); |
| 74 } | 74 } |
| 75 | 75 |
| 76 ErrorCode RestrictClockID(SandboxBPF* sb) { | 76 ErrorCode RestrictClockID(SandboxBPF* sb) { |
| 77 // We allow accessing only CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, | 77 // We allow accessing only CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, |
| 78 // CLOCK_REALTIME, and CLOCK_THREAD_CPUTIME_ID. In particular, this disallows | 78 // CLOCK_REALTIME, and CLOCK_THREAD_CPUTIME_ID. In particular, this disallows |
| 79 // access to arbitrary per-{process,thread} CPU-time clock IDs (such as those | 79 // access to arbitrary per-{process,thread} CPU-time clock IDs (such as those |
| 80 // returned by {clock,pthread}_getcpuclockid), which can leak information | 80 // returned by {clock,pthread}_getcpuclockid), which can leak information |
| 81 // about the state of the host OS. | 81 // about the state of the host OS. |
| 82 COMPILE_ASSERT(4 == sizeof(clockid_t), clockid_is_not_32bit); | 82 COMPILE_ASSERT(4 == sizeof(clockid_t), clockid_is_not_32bit); |
| 83 return sb->Cond(0, ErrorCode::TP_32BIT, | 83 ErrorCode result = sb->Cond(0, ErrorCode::TP_32BIT, |
| 84 ErrorCode::OP_EQUAL, CLOCK_MONOTONIC, | 84 ErrorCode::OP_EQUAL, CLOCK_MONOTONIC, |
| 85 ErrorCode(ErrorCode::ERR_ALLOWED), | 85 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 86 sb->Cond(0, ErrorCode::TP_32BIT, | 86 sb->Cond(0, ErrorCode::TP_32BIT, |
| 87 ErrorCode::OP_EQUAL, CLOCK_PROCESS_CPUTIME_ID, | 87 ErrorCode::OP_EQUAL, CLOCK_PROCESS_CPUTIME_ID, |
| 88 ErrorCode(ErrorCode::ERR_ALLOWED), | 88 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 89 sb->Cond(0, ErrorCode::TP_32BIT, | 89 sb->Cond(0, ErrorCode::TP_32BIT, |
| 90 ErrorCode::OP_EQUAL, CLOCK_REALTIME, | 90 ErrorCode::OP_EQUAL, CLOCK_REALTIME, |
| 91 ErrorCode(ErrorCode::ERR_ALLOWED), | 91 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 92 sb->Cond(0, ErrorCode::TP_32BIT, | 92 sb->Cond(0, ErrorCode::TP_32BIT, |
| 93 ErrorCode::OP_EQUAL, CLOCK_THREAD_CPUTIME_ID, | 93 ErrorCode::OP_EQUAL, CLOCK_THREAD_CPUTIME_ID, |
| 94 ErrorCode(ErrorCode::ERR_ALLOWED), | 94 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 95 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL))))); | 95 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL))))); |
| 96 #if defined(OS_CHROMEOS) |
| 97 // Allow the special clock for Chrome OS used by Chrome tracing. |
| 98 result = sb->Cond(0, ErrorCode::TP_32BIT, |
| 99 ErrorCode::OP_EQUAL, CLOCK_SYSTEM_TRACE, |
| 100 ErrorCode(ErrorCode::ERR_ALLOWED), result); |
| 101 #endif |
| 102 return result; |
| 96 } | 103 } |
| 97 | 104 |
| 98 ErrorCode RestrictClone(SandboxBPF* sb) { | 105 ErrorCode RestrictClone(SandboxBPF* sb) { |
| 99 // We allow clone only for new thread creation. | 106 // We allow clone only for new thread creation. |
| 100 return sb->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 107 return sb->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
| 101 CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | | 108 CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | |
| 102 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | | 109 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | |
| 103 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID, | 110 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID, |
| 104 ErrorCode(ErrorCode::ERR_ALLOWED), | 111 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 105 sb->Trap(sandbox::SIGSYSCloneFailure, NULL)); | 112 sb->Trap(sandbox::SIGSYSCloneFailure, NULL)); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 scoped_ptr<sandbox::SandboxBPFPolicy>( | 340 scoped_ptr<sandbox::SandboxBPFPolicy>( |
| 334 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); | 341 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); |
| 335 if (!sandbox_is_initialized) | 342 if (!sandbox_is_initialized) |
| 336 return false; | 343 return false; |
| 337 RunSandboxSanityChecks(); | 344 RunSandboxSanityChecks(); |
| 338 return true; | 345 return true; |
| 339 } | 346 } |
| 340 | 347 |
| 341 } // namespace nonsfi | 348 } // namespace nonsfi |
| 342 } // namespace nacl | 349 } // namespace nacl |
| OLD | NEW |