OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <asm/unistd.h> | 5 #include <asm/unistd.h> |
6 #include <dlfcn.h> | 6 #include <dlfcn.h> |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <linux/audit.h> | 9 #include <linux/audit.h> |
10 #include <linux/filter.h> | 10 #include <linux/filter.h> |
11 #include <signal.h> | 11 #include <signal.h> |
12 #include <string.h> | 12 #include <string.h> |
13 #include <sys/prctl.h> | 13 #include <sys/prctl.h> |
14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 #include <ucontext.h> | 16 #include <ucontext.h> |
17 #include <unistd.h> | 17 #include <unistd.h> |
18 | 18 |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/logging.h" | 22 #include "base/logging.h" |
23 #include "content/common/sandbox_linux.h" | 23 #include "content/common/sandbox_linux.h" |
24 #include "content/common/sandbox_seccomp_bpf_linux.h" | 24 #include "content/common/sandbox_seccomp_bpf_linux.h" |
25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
26 | 26 |
27 // These are the only architectures supported for now. | 27 // These are the only architectures supported for now. |
28 #if defined(__i386__) || defined(__x86_64__) | 28 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) |
29 #define SECCOMP_BPF_SANDBOX | 29 #define SECCOMP_BPF_SANDBOX |
30 #endif | 30 #endif |
31 | 31 |
32 #if defined(SECCOMP_BPF_SANDBOX) | 32 #if defined(SECCOMP_BPF_SANDBOX) |
33 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 33 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
34 | |
35 #if defined(__i386__) || defined(__x86_64__) | |
34 #include "sandbox/linux/services/x86_linux_syscalls.h" | 36 #include "sandbox/linux/services/x86_linux_syscalls.h" |
37 #elif defined(__arm__) | |
38 #include "sandbox/linux/services/arm_linux_syscalls.h" | |
jln (very slow on Chromium)
2012/08/14 22:19:32
Please add a comment saying that this file is not
Jorge Lucangeli Obes
2012/08/14 22:40:45
Done.
| |
39 #endif | |
35 | 40 |
36 namespace { | 41 namespace { |
37 | 42 |
38 inline bool IsChromeOS() { | 43 inline bool IsChromeOS() { |
39 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
40 return true; | 45 return true; |
41 #else | 46 #else |
42 return false; | 47 return false; |
43 #endif | 48 #endif |
44 } | 49 } |
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 } | 1190 } |
1186 #endif // defined(__x86_64__) || defined(__i386__) | 1191 #endif // defined(__x86_64__) || defined(__i386__) |
1187 | 1192 |
1188 playground2::Sandbox::ErrorCode BlacklistPtracePolicy(int sysno) { | 1193 playground2::Sandbox::ErrorCode BlacklistPtracePolicy(int sysno) { |
1189 if (sysno < static_cast<int>(MIN_SYSCALL) || | 1194 if (sysno < static_cast<int>(MIN_SYSCALL) || |
1190 sysno > static_cast<int>(MAX_SYSCALL)) { | 1195 sysno > static_cast<int>(MAX_SYSCALL)) { |
1191 // TODO(jln) we should not have to do that in a trivial policy. | 1196 // TODO(jln) we should not have to do that in a trivial policy. |
1192 return ENOSYS; | 1197 return ENOSYS; |
1193 } | 1198 } |
1194 switch (sysno) { | 1199 switch (sysno) { |
1200 // __NR_migrate_pages is not available for EABI ARM. | |
jln (very slow on Chromium)
2012/08/14 22:19:32
I think it's fine to leave this without a comment
Jorge Lucangeli Obes
2012/08/14 22:40:45
Done.
| |
1201 // See </arch/arm/include/asm/unistd.h> in the Linux kernel. | |
1202 #if defined(__x86_64__) || defined(__i386__) | |
1195 case __NR_migrate_pages: | 1203 case __NR_migrate_pages: |
1204 #endif | |
1196 case __NR_move_pages: | 1205 case __NR_move_pages: |
1197 case __NR_process_vm_readv: | 1206 case __NR_process_vm_readv: |
1198 case __NR_process_vm_writev: | 1207 case __NR_process_vm_writev: |
1199 case __NR_ptrace: | 1208 case __NR_ptrace: |
1200 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); | 1209 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); |
1201 default: | 1210 default: |
1202 return playground2::Sandbox::SB_ALLOWED; | 1211 return playground2::Sandbox::SB_ALLOWED; |
1203 } | 1212 } |
1204 } | 1213 } |
1205 | 1214 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1251 return FlashProcessPolicy_x86_64; | 1260 return FlashProcessPolicy_x86_64; |
1252 } | 1261 } |
1253 | 1262 |
1254 if (process_type == switches::kRendererProcess || | 1263 if (process_type == switches::kRendererProcess || |
1255 process_type == switches::kWorkerProcess) { | 1264 process_type == switches::kWorkerProcess) { |
1256 return BlacklistPtracePolicy; | 1265 return BlacklistPtracePolicy; |
1257 } | 1266 } |
1258 NOTREACHED(); | 1267 NOTREACHED(); |
1259 // This will be our default if we need one. | 1268 // This will be our default if we need one. |
1260 return AllowAllPolicy; | 1269 return AllowAllPolicy; |
1261 #else | 1270 #elif defined(__i386__) || defined(__arm__) |
jln (very slow on Chromium)
2012/08/14 22:19:32
I would prefer just leaving a #else here.
It simp
Jorge Lucangeli Obes
2012/08/14 22:40:45
Done.
| |
1262 // On IA32, we only have a small blacklist at the moment. | 1271 // On IA32 or ARM, we only have a small blacklist at the moment. |
1263 (void) process_type; | 1272 (void) process_type; |
1264 return BlacklistPtracePolicy; | 1273 return BlacklistPtracePolicy; |
1265 #endif // __x86_64__ | 1274 #else |
1275 // This should not happen, we're compiling only on x86_64 or i386 or ARM. | |
1276 (void) process_type; | |
1277 NOTREACHED(); | |
1278 #endif | |
1266 } | 1279 } |
1267 | 1280 |
1268 // Initialize the seccomp-bpf sandbox. | 1281 // Initialize the seccomp-bpf sandbox. |
1269 bool StartBpfSandbox_x86(const CommandLine& command_line, | 1282 bool StartBpfSandbox(const CommandLine& command_line, |
1270 const std::string& process_type) { | 1283 const std::string& process_type) { |
jln (very slow on Chromium)
2012/08/14 22:19:32
Nit: re-indent.
Jorge Lucangeli Obes
2012/08/14 22:40:45
Done.
| |
1271 playground2::Sandbox::EvaluateSyscall SyscallPolicy = | 1284 playground2::Sandbox::EvaluateSyscall SyscallPolicy = |
1272 GetProcessSyscallPolicy(command_line, process_type); | 1285 GetProcessSyscallPolicy(command_line, process_type); |
1273 | 1286 |
1274 // Warms up resources needed by the policy we're about to enable. | 1287 // Warms up resources needed by the policy we're about to enable. |
1275 WarmupPolicy(SyscallPolicy); | 1288 WarmupPolicy(SyscallPolicy); |
1276 | 1289 |
1277 playground2::Sandbox::setSandboxPolicy(SyscallPolicy, NULL); | 1290 playground2::Sandbox::setSandboxPolicy(SyscallPolicy, NULL); |
1278 playground2::Sandbox::startSandbox(); | 1291 playground2::Sandbox::startSandbox(); |
1279 | 1292 |
1280 return true; | 1293 return true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1322 } | 1335 } |
1323 | 1336 |
1324 bool SandboxSeccompBpf::StartSandbox(const std::string& process_type) { | 1337 bool SandboxSeccompBpf::StartSandbox(const std::string& process_type) { |
1325 #if defined(SECCOMP_BPF_SANDBOX) | 1338 #if defined(SECCOMP_BPF_SANDBOX) |
1326 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 1339 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
1327 | 1340 |
1328 if (IsSeccompBpfDesired() && // Global switches policy. | 1341 if (IsSeccompBpfDesired() && // Global switches policy. |
1329 // Process-specific policy. | 1342 // Process-specific policy. |
1330 ShouldEnableSeccompBpf(process_type) && | 1343 ShouldEnableSeccompBpf(process_type) && |
1331 SupportsSandbox()) { | 1344 SupportsSandbox()) { |
1332 return StartBpfSandbox_x86(command_line, process_type); | 1345 return StartBpfSandbox(command_line, process_type); |
1333 } | 1346 } |
1334 #endif | 1347 #endif |
1335 return false; | 1348 return false; |
1336 } | 1349 } |
1337 | 1350 |
1338 } // namespace content | 1351 } // namespace content |
OLD | NEW |