OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/nacl/nacl_sandbox_linux.h" | 5 #include "chrome/nacl/nacl_sandbox_linux.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <sys/ptrace.h> | 8 #include <sys/ptrace.h> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "content/public/common/sandbox_init.h" | 13 #include "content/public/common/sandbox_init.h" |
14 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 14 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
15 #include "sandbox/linux/services/linux_syscalls.h" | 15 #include "sandbox/linux/services/linux_syscalls.h" |
16 | 16 |
17 using playground2::ErrorCode; | 17 using playground2::ErrorCode; |
18 using playground2::Sandbox; | 18 using playground2::Sandbox; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // This policy does very little: | 22 // On arm and x86_64, System V shared memory calls have each their own system |
Mark Seaborn
2013/07/23 17:13:03
Nit: 'arm' -> 'ARM'
jln (very slow on Chromium)
2013/07/23 18:56:26
Done.
| |
23 // - Any invalid system call for the current architecture is handled by | 23 // call, while on i386 they are multiplexed. |
24 // the baseline policy. | 24 #if defined(__x86_64__) || defined(__arm__) |
25 // - ptrace() is denied. | 25 bool IsSystemVSharedMemory(int sysno) { |
26 // - Anything else is allowed. | 26 switch (sysno) { |
27 // Note that the seccomp-bpf sandbox always prevents cross-architecture | 27 case __NR_shmat: |
28 // system calls (on x86, long/compatibility/x32). | 28 case __NR_shmctl: |
29 // So even this trivial policy has a security benefit. | 29 case __NR_shmdt: |
30 case __NR_shmget: | |
31 return true; | |
32 default: | |
33 return false; | |
34 } | |
35 } | |
36 #endif | |
37 | |
38 #if defined(__i386__) | |
39 // Big system V multiplexing system call. | |
40 bool IsSystemVIpc(int sysno) { | |
41 switch (sysno) { | |
42 case __NR_ipc: | |
43 return true; | |
44 default: | |
45 return false; | |
46 } | |
47 } | |
48 #endif | |
49 | |
30 ErrorCode NaClBpfSandboxPolicy( | 50 ErrorCode NaClBpfSandboxPolicy( |
31 playground2::Sandbox* sb, int sysnum, void* aux) { | 51 playground2::Sandbox* sb, int sysno, void* aux) { |
32 const playground2::BpfSandboxPolicyCallback baseline_policy = | 52 const playground2::BpfSandboxPolicyCallback baseline_policy = |
33 content::GetBpfSandboxBaselinePolicy(); | 53 content::GetBpfSandboxBaselinePolicy(); |
34 if (!playground2::Sandbox::IsValidSyscallNumber(sysnum)) { | 54 switch (sysno) { |
35 return baseline_policy.Run(sb, sysnum, aux); | 55 // TODO(jln): NaClGdbDebugStubTest.Breakpoint needs the following 4 system |
Mark Seaborn
2013/07/23 17:13:03
Can you change this to: "NaCl's GDB debug stub use
jln (very slow on Chromium)
2013/07/23 18:56:26
Done.
| |
36 } | 56 // calls, see if it can be restricted a bit. |
37 switch (sysnum) { | 57 #if defined(__x86_64__) || defined(__arm__) |
58 // transport_common.cc needs this. | |
59 case __NR_accept: | |
60 case __NR_setsockopt: | |
61 #elif defined(__i386__) | |
62 case __NR_socketcall: | |
63 #endif | |
64 // trusted/service_runtime/linux/thread_suspension.cc needs this. | |
Mark Seaborn
2013/07/23 17:13:03
Make this "trusted/service_runtime/linux/thread_su
jln (very slow on Chromium)
2013/07/23 18:56:26
Done.
jln (very slow on Chromium)
2013/07/23 18:56:26
Done.
| |
65 case __NR_rt_sigtimedwait: | |
66 #if defined(__i386__) | |
67 // Needed on i386 to set-up the custom segments. | |
68 case __NR_modify_ldt: | |
69 #endif | |
70 // NaClAddrSpaceBeforeAlloc needs this. | |
Mark Seaborn
2013/07/23 17:13:03
"this" -> "prlimit64"
jln (very slow on Chromium)
2013/07/23 18:56:26
Done.
jln (very slow on Chromium)
2013/07/23 18:56:26
Done.
| |
71 case __NR_prlimit64: | |
72 // NaCl uses custom signal stacks. | |
73 case __NR_sigaltstack: | |
74 // Below is fairly similar to the policy for a Chromium renderer. | |
75 // TODO(jln): restrict clone(), ioctl() and prctl(). | |
76 case __NR_ioctl: | |
77 #if defined(__i386__) || defined(__x86_64__) | |
78 case __NR_getrlimit: | |
79 #endif | |
80 #if defined(__i386__) || defined(__arm__) | |
81 case __NR_ugetrlimit: | |
82 #endif | |
83 case __NR_pread64: | |
84 case __NR_pwrite64: | |
85 case __NR_sched_get_priority_max: | |
86 case __NR_sched_get_priority_min: | |
87 case __NR_sched_getaffinity: | |
88 case __NR_sched_getparam: | |
89 case __NR_sched_getscheduler: | |
90 case __NR_sched_setscheduler: | |
91 case __NR_setpriority: | |
92 case __NR_sysinfo: | |
93 case __NR_uname: | |
94 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
38 case __NR_ptrace: | 95 case __NR_ptrace: |
39 return ErrorCode(EPERM); | 96 return ErrorCode(EPERM); |
40 default: | 97 default: |
41 return ErrorCode(ErrorCode::ERR_ALLOWED); | 98 // TODO(jln): look into getting rid of System V shared memory. |
99 #if defined(__x86_64__) || defined(__arm__) | |
100 if (IsSystemVSharedMemory(sysno)) | |
101 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
102 #elif defined(__i386__) | |
103 if (IsSystemVIpc(sysno)) | |
104 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
105 #endif | |
106 return baseline_policy.Run(sb, sysno, aux); | |
42 } | 107 } |
43 NOTREACHED(); | 108 NOTREACHED(); |
44 // GCC wants this. | 109 // GCC wants this. |
45 return ErrorCode(EPERM); | 110 return ErrorCode(EPERM); |
46 } | 111 } |
47 | 112 |
48 void RunSandboxSanityChecks() { | 113 void RunSandboxSanityChecks() { |
49 errno = 0; | 114 errno = 0; |
50 // Make a ptrace request with an invalid PID. | 115 // Make a ptrace request with an invalid PID. |
51 long ptrace_ret = ptrace(PTRACE_PEEKUSER, -1 /* pid */, NULL, NULL); | 116 long ptrace_ret = ptrace(PTRACE_PEEKUSER, -1 /* pid */, NULL, NULL); |
(...skipping 11 matching lines...) Expand all Loading... | |
63 RunSandboxSanityChecks(); | 128 RunSandboxSanityChecks(); |
64 // TODO(jln): Find a way to fix this. | 129 // TODO(jln): Find a way to fix this. |
65 // The sandbox' SIGSYS handler trips NaCl, so we disable it. | 130 // The sandbox' SIGSYS handler trips NaCl, so we disable it. |
66 // If SIGSYS is triggered it'll now execute the default action | 131 // If SIGSYS is triggered it'll now execute the default action |
67 // (CORE). This will make it hard to track down bugs and sandbox violations. | 132 // (CORE). This will make it hard to track down bugs and sandbox violations. |
68 CHECK(signal(SIGSYS, SIG_DFL) != SIG_ERR); | 133 CHECK(signal(SIGSYS, SIG_DFL) != SIG_ERR); |
69 return true; | 134 return true; |
70 } | 135 } |
71 return false; | 136 return false; |
72 } | 137 } |
OLD | NEW |