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/futex.h> |
9 #include <linux/net.h> | 10 #include <linux/net.h> |
10 #include <sys/prctl.h> | 11 #include <sys/prctl.h> |
11 #include <sys/ptrace.h> | 12 #include <sys/ptrace.h> |
12 #include <sys/mman.h> | 13 #include <sys/mman.h> |
13 #include <sys/socket.h> | 14 #include <sys/socket.h> |
14 #include <sys/syscall.h> | 15 #include <sys/syscall.h> |
15 | 16 |
16 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "content/public/common/sandbox_init.h" | 20 #include "content/public/common/sandbox_init.h" |
20 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" | 21 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" |
21 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 22 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
22 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h" | 23 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h" |
23 #include "sandbox/linux/seccomp-bpf/trap.h" | 24 #include "sandbox/linux/seccomp-bpf/trap.h" |
24 #include "sandbox/linux/services/linux_syscalls.h" | 25 #include "sandbox/linux/services/linux_syscalls.h" |
25 | 26 |
26 #if defined(__arm__) && !defined(MAP_STACK) | 27 #if defined(__arm__) && !defined(MAP_STACK) |
27 // Chrome OS Daisy (ARM) build environment has old headers. | 28 // Chrome OS Daisy (ARM) build environment has old headers. |
28 #define MAP_STACK 0x20000 | 29 #define MAP_STACK 0x20000 |
29 #endif | 30 #endif |
30 | 31 |
31 using sandbox::ErrorCode; | 32 using sandbox::ErrorCode; |
32 using sandbox::SandboxBPF; | 33 using sandbox::SandboxBPF; |
33 | 34 |
34 namespace nacl { | 35 namespace nacl { |
35 namespace nonsfi { | 36 namespace nonsfi { |
36 namespace { | 37 namespace { |
37 | 38 |
| 39 ErrorCode RestrictFutexCommands(SandboxBPF* sb) { |
| 40 // For now, we allow non-PRIVATE FUTEX_WAIT for lll_wait_tid in |
| 41 // glibc's pthread_join. |
| 42 // TODO(hamaji): Disallow FUTEX_WAIT by switching to newlib or |
| 43 // detaching threads. |
| 44 return sb->Cond(1, ErrorCode::TP_32BIT, |
| 45 ErrorCode::OP_EQUAL, FUTEX_WAIT, |
| 46 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 47 sb->Cond(1, ErrorCode::TP_32BIT, |
| 48 ErrorCode::OP_HAS_ALL_BITS, FUTEX_PRIVATE_FLAG, |
| 49 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 50 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL))); |
| 51 } |
| 52 |
38 ErrorCode RestrictFcntlCommands(SandboxBPF* sb) { | 53 ErrorCode RestrictFcntlCommands(SandboxBPF* sb) { |
39 ErrorCode::ArgType mask_long_type; | 54 ErrorCode::ArgType mask_long_type; |
40 if (sizeof(long) == 8) { | 55 if (sizeof(long) == 8) { |
41 mask_long_type = ErrorCode::TP_64BIT; | 56 mask_long_type = ErrorCode::TP_64BIT; |
42 } else if (sizeof(long) == 4) { | 57 } else if (sizeof(long) == 4) { |
43 mask_long_type = ErrorCode::TP_32BIT; | 58 mask_long_type = ErrorCode::TP_32BIT; |
44 } else { | 59 } else { |
45 NOTREACHED(); | 60 NOTREACHED(); |
46 } | 61 } |
47 // We allow following cases: | 62 // We allow following cases: |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 case __NR_epoll_create: | 234 case __NR_epoll_create: |
220 case __NR_epoll_ctl: | 235 case __NR_epoll_ctl: |
221 case __NR_epoll_wait: | 236 case __NR_epoll_wait: |
222 case __NR_exit: | 237 case __NR_exit: |
223 case __NR_exit_group: | 238 case __NR_exit_group: |
224 #if defined(__i386__) || defined(__arm__) | 239 #if defined(__i386__) || defined(__arm__) |
225 case __NR_fstat64: | 240 case __NR_fstat64: |
226 #elif defined(__x86_64__) | 241 #elif defined(__x86_64__) |
227 case __NR_fstat: | 242 case __NR_fstat: |
228 #endif | 243 #endif |
229 // TODO(hamaji): Allow only FUTEX_PRIVATE_FLAG. | |
230 case __NR_futex: | |
231 // TODO(hamaji): Remove the need of gettid. Currently, this is | 244 // TODO(hamaji): Remove the need of gettid. Currently, this is |
232 // called from PlatformThread::CurrentId(). | 245 // called from PlatformThread::CurrentId(). |
233 case __NR_gettid: | 246 case __NR_gettid: |
234 case __NR_gettimeofday: | 247 case __NR_gettimeofday: |
235 case __NR_munmap: | 248 case __NR_munmap: |
236 case __NR_nanosleep: | 249 case __NR_nanosleep: |
237 // TODO(hamaji): Remove the need of pipe. Currently, this is | 250 // TODO(hamaji): Remove the need of pipe. Currently, this is |
238 // called from base::MessagePumpLibevent::Init(). | 251 // called from base::MessagePumpLibevent::Init(). |
239 case __NR_pipe: | 252 case __NR_pipe: |
240 case __NR_pread64: | 253 case __NR_pread64: |
(...skipping 15 matching lines...) Expand all Loading... |
256 return RestrictClone(sb); | 269 return RestrictClone(sb); |
257 | 270 |
258 #if defined(__x86_64__) | 271 #if defined(__x86_64__) |
259 case __NR_fcntl: | 272 case __NR_fcntl: |
260 #endif | 273 #endif |
261 #if defined(__i386__) || defined(__arm__) | 274 #if defined(__i386__) || defined(__arm__) |
262 case __NR_fcntl64: | 275 case __NR_fcntl64: |
263 #endif | 276 #endif |
264 return RestrictFcntlCommands(sb); | 277 return RestrictFcntlCommands(sb); |
265 | 278 |
| 279 case __NR_futex: |
| 280 return RestrictFutexCommands(sb); |
| 281 |
266 #if defined(__x86_64__) | 282 #if defined(__x86_64__) |
267 case __NR_mmap: | 283 case __NR_mmap: |
268 #endif | 284 #endif |
269 #if defined(__i386__) || defined(__arm__) | 285 #if defined(__i386__) || defined(__arm__) |
270 case __NR_mmap2: | 286 case __NR_mmap2: |
271 #endif | 287 #endif |
272 return RestrictMmap(sb); | 288 return RestrictMmap(sb); |
273 case __NR_mprotect: | 289 case __NR_mprotect: |
274 return RestrictMemoryProtection(sb, 2); | 290 return RestrictMemoryProtection(sb, 2); |
275 | 291 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 scoped_ptr<sandbox::SandboxBPFPolicy>( | 326 scoped_ptr<sandbox::SandboxBPFPolicy>( |
311 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); | 327 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); |
312 if (!sandbox_is_initialized) | 328 if (!sandbox_is_initialized) |
313 return false; | 329 return false; |
314 RunSandboxSanityChecks(); | 330 RunSandboxSanityChecks(); |
315 return true; | 331 return true; |
316 } | 332 } |
317 | 333 |
318 } // namespace nonsfi | 334 } // namespace nonsfi |
319 } // namespace nacl | 335 } // namespace nacl |
OLD | NEW |