Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: components/nacl/loader/nonsfi/nonsfi_sandbox.cc

Issue 563043005: Linux sandbox: move RestrictClockID() to sandbox/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add header. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/futex.h> 9 #include <linux/futex.h>
10 #include <linux/net.h> 10 #include <linux/net.h>
11 #include <sys/mman.h> 11 #include <sys/mman.h>
12 #include <sys/prctl.h> 12 #include <sys/prctl.h>
13 #include <sys/ptrace.h> 13 #include <sys/ptrace.h>
14 #include <sys/socket.h> 14 #include <sys/socket.h>
15 #include <sys/syscall.h> 15 #include <sys/syscall.h>
16 #include <sys/time.h> 16 #include <sys/time.h>
17 17
18 #include "base/basictypes.h" 18 #include "base/basictypes.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "content/public/common/sandbox_init.h" 22 #include "content/public/common/sandbox_init.h"
23 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" 23 #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
24 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" 24 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
25 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h"
25 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h" 26 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h"
26 #include "sandbox/linux/services/linux_syscalls.h" 27 #include "sandbox/linux/services/linux_syscalls.h"
27 28
28 #if defined(__arm__) && !defined(MAP_STACK) 29 #if defined(__arm__) && !defined(MAP_STACK)
29 // Chrome OS Daisy (ARM) build environment has old headers. 30 // Chrome OS Daisy (ARM) build environment has old headers.
30 #define MAP_STACK 0x20000 31 #define MAP_STACK 0x20000
31 #endif 32 #endif
32 33
33 #define CASES SANDBOX_BPF_DSL_CASES 34 #define CASES SANDBOX_BPF_DSL_CASES
34 35
(...skipping 25 matching lines...) Expand all
60 // 3. F_SETFL: Used by evutil_make_socket_nonblocking in 61 // 3. F_SETFL: Used by evutil_make_socket_nonblocking in
61 // libevent and SetNonBlocking. As the latter mix O_NONBLOCK to 62 // libevent and SetNonBlocking. As the latter mix O_NONBLOCK to
62 // the return value of F_GETFL, so we need to allow O_ACCMODE in 63 // the return value of F_GETFL, so we need to allow O_ACCMODE in
63 // addition to O_NONBLOCK. 64 // addition to O_NONBLOCK.
64 const unsigned long denied_mask = ~(O_ACCMODE | O_NONBLOCK); 65 const unsigned long denied_mask = ~(O_ACCMODE | O_NONBLOCK);
65 return If((cmd == F_SETFD && long_arg == FD_CLOEXEC) || cmd == F_GETFL || 66 return If((cmd == F_SETFD && long_arg == FD_CLOEXEC) || cmd == F_GETFL ||
66 (cmd == F_SETFL && (long_arg & denied_mask) == 0), 67 (cmd == F_SETFL && (long_arg & denied_mask) == 0),
67 Allow()).Else(CrashSIGSYS()); 68 Allow()).Else(CrashSIGSYS());
68 } 69 }
69 70
70 ResultExpr RestrictClockID() {
71 // We allow accessing only CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID,
72 // CLOCK_REALTIME, and CLOCK_THREAD_CPUTIME_ID. In particular, this disallows
73 // access to arbitrary per-{process,thread} CPU-time clock IDs (such as those
74 // returned by {clock,pthread}_getcpuclockid), which can leak information
75 // about the state of the host OS.
76 COMPILE_ASSERT(4 == sizeof(clockid_t), clockid_is_not_32bit);
77 const Arg<clockid_t> clockid(0);
78 return If(
79 #if defined(OS_CHROMEOS)
80 // Allow the special clock for Chrome OS used by Chrome tracing.
81 clockid == base::TimeTicks::kClockSystemTrace ||
82 #endif
83 clockid == CLOCK_MONOTONIC ||
84 clockid == CLOCK_PROCESS_CPUTIME_ID ||
85 clockid == CLOCK_REALTIME ||
86 clockid == CLOCK_THREAD_CPUTIME_ID,
87 Allow()).Else(CrashSIGSYS());
88 }
89
90 ResultExpr RestrictClone() { 71 ResultExpr RestrictClone() {
91 // We allow clone only for new thread creation. 72 // We allow clone only for new thread creation.
92 const Arg<int> flags(0); 73 const Arg<int> flags(0);
93 return If(flags == (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | 74 return If(flags == (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
94 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | 75 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS |
95 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID), 76 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID),
96 Allow()).Else(CrashSIGSYSClone()); 77 Allow()).Else(CrashSIGSYSClone());
97 } 78 }
98 79
99 ResultExpr RestrictFutexOperation() { 80 ResultExpr RestrictFutexOperation() {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // See crbug.com/264856 for details. 233 // See crbug.com/264856 for details.
253 case __NR_times: 234 case __NR_times:
254 case __NR_write: 235 case __NR_write:
255 #if defined(__arm__) 236 #if defined(__arm__)
256 case __ARM_NR_cacheflush: 237 case __ARM_NR_cacheflush:
257 #endif 238 #endif
258 return Allow(); 239 return Allow();
259 240
260 case __NR_clock_getres: 241 case __NR_clock_getres:
261 case __NR_clock_gettime: 242 case __NR_clock_gettime:
262 return RestrictClockID(); 243 return sandbox::RestrictClockID();
263 244
264 case __NR_clone: 245 case __NR_clone:
265 return RestrictClone(); 246 return RestrictClone();
266 247
267 #if defined(__x86_64__) 248 #if defined(__x86_64__)
268 case __NR_fcntl: 249 case __NR_fcntl:
269 #endif 250 #endif
270 #if defined(__i386__) || defined(__arm__) 251 #if defined(__i386__) || defined(__arm__)
271 case __NR_fcntl64: 252 case __NR_fcntl64:
272 #endif 253 #endif
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 scoped_ptr<sandbox::SandboxBPFPolicy>( 307 scoped_ptr<sandbox::SandboxBPFPolicy>(
327 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); 308 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy()));
328 if (!sandbox_is_initialized) 309 if (!sandbox_is_initialized)
329 return false; 310 return false;
330 RunSandboxSanityChecks(); 311 RunSandboxSanityChecks();
331 return true; 312 return true;
332 } 313 }
333 314
334 } // namespace nonsfi 315 } // namespace nonsfi
335 } // namespace nacl 316 } // namespace nacl
OLDNEW
« no previous file with comments | « no previous file | components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698