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

Side by Side Diff: content/common/sandbox_seccomp_bpf_linux.cc

Issue 10836243: Add basic ARM policy to seccomp-bpf sandbox. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix nits. Created 8 years, 4 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 | sandbox/linux/services/arm_linux_syscalls.h » ('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 (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 // This file doesn't yet list all syscalls.
39 #include "sandbox/linux/services/arm_linux_syscalls.h"
40 #endif
35 41
36 namespace { 42 namespace {
37 43
38 inline bool IsChromeOS() { 44 inline bool IsChromeOS() {
39 #if defined(OS_CHROMEOS) 45 #if defined(OS_CHROMEOS)
40 return true; 46 return true;
41 #else 47 #else
42 return false; 48 return false;
43 #endif 49 #endif
44 } 50 }
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 // These are under investigation, and hopefully not here for the long 1182 // These are under investigation, and hopefully not here for the long
1177 // term. 1183 // term.
1178 if (IsAllowedSystemVSharedMemory(sysno)) 1184 if (IsAllowedSystemVSharedMemory(sysno))
1179 return playground2::Sandbox::SB_ALLOWED; 1185 return playground2::Sandbox::SB_ALLOWED;
1180 #endif 1186 #endif
1181 1187
1182 // Default on the baseline policy. 1188 // Default on the baseline policy.
1183 return BaselinePolicy_x86_64(sysno); 1189 return BaselinePolicy_x86_64(sysno);
1184 } 1190 }
1185 } 1191 }
1186 #endif // defined(__x86_64__) || defined(__i386__) 1192 #endif // defined(__i386__) || defined(__x86_64__)
1187 1193
1188 playground2::Sandbox::ErrorCode BlacklistPtracePolicy(int sysno) { 1194 playground2::Sandbox::ErrorCode BlacklistPtracePolicy(int sysno) {
1189 if (sysno < static_cast<int>(MIN_SYSCALL) || 1195 if (sysno < static_cast<int>(MIN_SYSCALL) ||
1190 sysno > static_cast<int>(MAX_SYSCALL)) { 1196 sysno > static_cast<int>(MAX_SYSCALL)) {
1191 // TODO(jln) we should not have to do that in a trivial policy. 1197 // TODO(jln) we should not have to do that in a trivial policy.
1192 return ENOSYS; 1198 return ENOSYS;
1193 } 1199 }
1194 switch (sysno) { 1200 switch (sysno) {
1201 #if defined(__i386__) || defined(__x86_64__)
1195 case __NR_migrate_pages: 1202 case __NR_migrate_pages:
1203 #endif
1196 case __NR_move_pages: 1204 case __NR_move_pages:
1197 case __NR_process_vm_readv: 1205 case __NR_process_vm_readv:
1198 case __NR_process_vm_writev: 1206 case __NR_process_vm_writev:
1199 case __NR_ptrace: 1207 case __NR_ptrace:
1200 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); 1208 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL);
1201 default: 1209 default:
1202 return playground2::Sandbox::SB_ALLOWED; 1210 return playground2::Sandbox::SB_ALLOWED;
1203 } 1211 }
1204 } 1212 }
1205 1213
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 } 1260 }
1253 1261
1254 if (process_type == switches::kRendererProcess || 1262 if (process_type == switches::kRendererProcess ||
1255 process_type == switches::kWorkerProcess) { 1263 process_type == switches::kWorkerProcess) {
1256 return BlacklistPtracePolicy; 1264 return BlacklistPtracePolicy;
1257 } 1265 }
1258 NOTREACHED(); 1266 NOTREACHED();
1259 // This will be our default if we need one. 1267 // This will be our default if we need one.
1260 return AllowAllPolicy; 1268 return AllowAllPolicy;
1261 #else 1269 #else
1262 // On IA32, we only have a small blacklist at the moment. 1270 // On other architectures (currently IA32 or ARM),
1271 // 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 #endif // __x86_64__
1266 } 1275 }
1267 1276
1268 // Initialize the seccomp-bpf sandbox. 1277 // Initialize the seccomp-bpf sandbox.
1269 bool StartBpfSandbox_x86(const CommandLine& command_line, 1278 bool StartBpfSandbox(const CommandLine& command_line,
1270 const std::string& process_type) { 1279 const std::string& process_type) {
1271 playground2::Sandbox::EvaluateSyscall SyscallPolicy = 1280 playground2::Sandbox::EvaluateSyscall SyscallPolicy =
1272 GetProcessSyscallPolicy(command_line, process_type); 1281 GetProcessSyscallPolicy(command_line, process_type);
1273 1282
1274 // Warms up resources needed by the policy we're about to enable. 1283 // Warms up resources needed by the policy we're about to enable.
1275 WarmupPolicy(SyscallPolicy); 1284 WarmupPolicy(SyscallPolicy);
1276 1285
1277 playground2::Sandbox::setSandboxPolicy(SyscallPolicy, NULL); 1286 playground2::Sandbox::setSandboxPolicy(SyscallPolicy, NULL);
1278 playground2::Sandbox::startSandbox(); 1287 playground2::Sandbox::startSandbox();
1279 1288
1280 return true; 1289 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 } 1331 }
1323 1332
1324 bool SandboxSeccompBpf::StartSandbox(const std::string& process_type) { 1333 bool SandboxSeccompBpf::StartSandbox(const std::string& process_type) {
1325 #if defined(SECCOMP_BPF_SANDBOX) 1334 #if defined(SECCOMP_BPF_SANDBOX)
1326 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 1335 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1327 1336
1328 if (IsSeccompBpfDesired() && // Global switches policy. 1337 if (IsSeccompBpfDesired() && // Global switches policy.
1329 // Process-specific policy. 1338 // Process-specific policy.
1330 ShouldEnableSeccompBpf(process_type) && 1339 ShouldEnableSeccompBpf(process_type) &&
1331 SupportsSandbox()) { 1340 SupportsSandbox()) {
1332 return StartBpfSandbox_x86(command_line, process_type); 1341 return StartBpfSandbox(command_line, process_type);
1333 } 1342 }
1334 #endif 1343 #endif
1335 return false; 1344 return false;
1336 } 1345 }
1337 1346
1338 } // namespace content 1347 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | sandbox/linux/services/arm_linux_syscalls.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698