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

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

Issue 12223109: SECCOMP-BPF: Refactor the BPF sandbox API to use fewer "static" fields and methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make sure unnamed namespaces are always top-level Created 7 years, 10 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 | Annotate | Revision Log
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/ioctl.h>
13 #include <sys/prctl.h> 14 #include <sys/prctl.h>
15 #include <sys/socket.h>
14 #include <sys/stat.h> 16 #include <sys/stat.h>
15 #include <sys/types.h> 17 #include <sys/types.h>
16 #include <ucontext.h> 18 #include <ucontext.h>
17 #include <unistd.h> 19 #include <unistd.h>
18 20
19 #include <vector> 21 #include <vector>
20 22
21 #include "base/basictypes.h" 23 #include "base/basictypes.h"
22 #include "base/command_line.h" 24 #include "base/command_line.h"
23 #include "base/logging.h" 25 #include "base/logging.h"
(...skipping 12 matching lines...) Expand all
36 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 38 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
37 #include "sandbox/linux/services/linux_syscalls.h" 39 #include "sandbox/linux/services/linux_syscalls.h"
38 40
39 using playground2::arch_seccomp_data; 41 using playground2::arch_seccomp_data;
40 using playground2::ErrorCode; 42 using playground2::ErrorCode;
41 using playground2::Sandbox; 43 using playground2::Sandbox;
42 using sandbox::BrokerProcess; 44 using sandbox::BrokerProcess;
43 45
44 namespace { 46 namespace {
45 47
46 void StartSandboxWithPolicy(Sandbox::EvaluateSyscall syscall_policy, 48 void StartSandboxWithPolicy(Sandbox *sandbox,
49 Sandbox::EvaluateSyscall syscall_policy,
47 BrokerProcess* broker_process); 50 BrokerProcess* broker_process);
48 51
49 inline bool RunningOnASAN() { 52 inline bool RunningOnASAN() {
50 #if defined(ADDRESS_SANITIZER) 53 #if defined(ADDRESS_SANITIZER)
51 return true; 54 return true;
52 #else 55 #else
53 return false; 56 return false;
54 #endif 57 #endif
55 } 58 }
56 59
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 #if defined(__arm__) 1226 #if defined(__arm__)
1224 IsArmPciConfig(sysno) || 1227 IsArmPciConfig(sysno) ||
1225 #endif 1228 #endif
1226 IsTimer(sysno)) { 1229 IsTimer(sysno)) {
1227 return true; 1230 return true;
1228 } else { 1231 } else {
1229 return false; 1232 return false;
1230 } 1233 }
1231 } 1234 }
1232 1235
1233 ErrorCode BaselinePolicy(int sysno) { 1236 ErrorCode BaselinePolicy(Sandbox *sandbox, int sysno) {
1234 #if defined(__x86_64__) || defined(__arm__) 1237 #if defined(__x86_64__) || defined(__arm__)
1235 if (sysno == __NR_socketpair) { 1238 if (sysno == __NR_socketpair) {
1236 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. 1239 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen.
1237 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); 1240 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different);
1238 return Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, AF_UNIX, 1241 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, AF_UNIX,
1239 ErrorCode(ErrorCode::ERR_ALLOWED), 1242 ErrorCode(ErrorCode::ERR_ALLOWED),
1240 Sandbox::Trap(CrashSIGSYS_Handler, NULL)); 1243 sandbox->Trap(CrashSIGSYS_Handler, NULL));
1241 } 1244 }
1242 #endif 1245 #endif
1243 if (IsBaselinePolicyAllowed(sysno)) { 1246 if (IsBaselinePolicyAllowed(sysno)) {
1244 return ErrorCode(ErrorCode::ERR_ALLOWED); 1247 return ErrorCode(ErrorCode::ERR_ALLOWED);
1245 } 1248 }
1246 1249
1247 #if defined(__i386__) 1250 #if defined(__i386__)
1248 // socketcall(2) should be tightened. 1251 // socketcall(2) should be tightened.
1249 if (IsSocketCall(sysno)) { 1252 if (IsSocketCall(sysno)) {
1250 return ErrorCode(ErrorCode::ERR_ALLOWED); 1253 return ErrorCode(ErrorCode::ERR_ALLOWED);
1251 } 1254 }
1252 #endif 1255 #endif
1253 1256
1254 // TODO(jln): some system calls in those sets are not supposed to 1257 // TODO(jln): some system calls in those sets are not supposed to
1255 // return ENOENT. Return the appropriate error. 1258 // return ENOENT. Return the appropriate error.
1256 if (IsFileSystem(sysno) || IsCurrentDirectory(sysno)) { 1259 if (IsFileSystem(sysno) || IsCurrentDirectory(sysno)) {
1257 return ErrorCode(ENOENT); 1260 return ErrorCode(ENOENT);
1258 } 1261 }
1259 1262
1260 if (IsUmask(sysno) || IsDeniedFileSystemAccessViaFd(sysno) || 1263 if (IsUmask(sysno) || IsDeniedFileSystemAccessViaFd(sysno) ||
1261 IsDeniedGetOrModifySocket(sysno)) { 1264 IsDeniedGetOrModifySocket(sysno)) {
1262 return ErrorCode(EPERM); 1265 return ErrorCode(EPERM);
1263 } 1266 }
1264 1267
1265 if (IsBaselinePolicyWatched(sysno)) { 1268 if (IsBaselinePolicyWatched(sysno)) {
1266 // Previously unseen syscalls. TODO(jln): some of these should 1269 // Previously unseen syscalls. TODO(jln): some of these should
1267 // be denied gracefully right away. 1270 // be denied gracefully right away.
1268 return Sandbox::Trap(CrashSIGSYS_Handler, NULL); 1271 return sandbox->Trap(CrashSIGSYS_Handler, NULL);
1269 } 1272 }
1270 // In any other case crash the program with our SIGSYS handler 1273 // In any other case crash the program with our SIGSYS handler
1271 return Sandbox::Trap(CrashSIGSYS_Handler, NULL); 1274 return sandbox->Trap(CrashSIGSYS_Handler, NULL);
1272 } 1275 }
1273 1276
1274 // x86_64/i386 for now. Needs to be adapted and tested for ARM. 1277 // x86_64/i386 for now. Needs to be adapted and tested for ARM.
1275 ErrorCode GpuProcessPolicy(int sysno, void *broker_process) { 1278 ErrorCode GpuProcessPolicy(Sandbox *sandbox, int sysno,
1279 void *broker_process) {
1276 switch(sysno) { 1280 switch(sysno) {
1277 case __NR_ioctl: 1281 case __NR_ioctl:
1278 #if defined(ADDRESS_SANITIZER) 1282 #if defined(ADDRESS_SANITIZER)
1279 // Allow to call sched_getaffinity under AddressSanitizer. 1283 // Allow to call sched_getaffinity under AddressSanitizer.
1280 case __NR_sched_getaffinity: 1284 case __NR_sched_getaffinity:
1281 #endif 1285 #endif
1282 return ErrorCode(ErrorCode::ERR_ALLOWED); 1286 return ErrorCode(ErrorCode::ERR_ALLOWED);
1283 case __NR_open: 1287 case __NR_open:
1284 case __NR_openat: 1288 case __NR_openat:
1285 return Sandbox::Trap(GpuOpenSIGSYS_Handler, broker_process); 1289 return sandbox->Trap(GpuOpenSIGSYS_Handler, broker_process);
1286 default: 1290 default:
1287 if (IsEventFd(sysno)) 1291 if (IsEventFd(sysno))
1288 return ErrorCode(ErrorCode::ERR_ALLOWED); 1292 return ErrorCode(ErrorCode::ERR_ALLOWED);
1289 1293
1290 // Default on the baseline policy. 1294 // Default on the baseline policy.
1291 return BaselinePolicy(sysno); 1295 return BaselinePolicy(sandbox, sysno);
1292 } 1296 }
1293 } 1297 }
1294 1298
1295 // x86_64/i386 for now. Needs to be adapted and tested for ARM. 1299 // x86_64/i386 for now. Needs to be adapted and tested for ARM.
1296 // A GPU broker policy is the same as a GPU policy with open and 1300 // A GPU broker policy is the same as a GPU policy with open and
1297 // openat allowed. 1301 // openat allowed.
1298 ErrorCode GpuBrokerProcessPolicy(int sysno, void*) { 1302 ErrorCode GpuBrokerProcessPolicy(Sandbox *sandbox, int sysno, void *aux) {
1303 // "aux" would typically be NULL, when called from
1304 // "EnableGpuBrokerPolicyCallBack"
1299 switch(sysno) { 1305 switch(sysno) {
1300 case __NR_open: 1306 case __NR_open:
1301 case __NR_openat: 1307 case __NR_openat:
1302 return ErrorCode(ErrorCode::ERR_ALLOWED); 1308 return ErrorCode(ErrorCode::ERR_ALLOWED);
1303 default: 1309 default:
1304 return GpuProcessPolicy(sysno, NULL); 1310 return GpuProcessPolicy(sandbox, sysno, aux);
1305 } 1311 }
1306 } 1312 }
1307 1313
1308 // Allow clone for threads, crash if anything else is attempted. 1314 // Allow clone for threads, crash if anything else is attempted.
1309 // Don't restrict on ASAN. 1315 // Don't restrict on ASAN.
1310 ErrorCode RestrictCloneToThreads() { 1316 ErrorCode RestrictCloneToThreads(Sandbox *sandbox) {
1311 // Glibc's pthread. 1317 // Glibc's pthread.
1312 if (!RunningOnASAN()) { 1318 if (!RunningOnASAN()) {
1313 return Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, 1319 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL,
1314 CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | 1320 CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
1315 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | 1321 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS |
1316 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID, 1322 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID,
1317 ErrorCode(ErrorCode::ERR_ALLOWED), 1323 ErrorCode(ErrorCode::ERR_ALLOWED),
1318 Sandbox::Trap(ReportCloneFailure, NULL)); 1324 sandbox->Trap(ReportCloneFailure, NULL));
1319 } else { 1325 } else {
1320 return ErrorCode(ErrorCode::ERR_ALLOWED); 1326 return ErrorCode(ErrorCode::ERR_ALLOWED);
1321 } 1327 }
1322 } 1328 }
1323 1329
1324 ErrorCode RestrictPrctl() { 1330 ErrorCode RestrictPrctl(Sandbox *sandbox) {
1325 // Allow PR_SET_NAME, PR_SET_DUMPABLE, PR_GET_DUMPABLE. Will need to add 1331 // Allow PR_SET_NAME, PR_SET_DUMPABLE, PR_GET_DUMPABLE. Will need to add
1326 // seccomp compositing in the future. 1332 // seccomp compositing in the future.
1327 // PR_SET_PTRACER is used by breakpad but not needed anymore. 1333 // PR_SET_PTRACER is used by breakpad but not needed anymore.
1328 return Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, 1334 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL,
1329 PR_SET_NAME, ErrorCode(ErrorCode::ERR_ALLOWED), 1335 PR_SET_NAME, ErrorCode(ErrorCode::ERR_ALLOWED),
1330 Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, 1336 sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL,
1331 PR_SET_DUMPABLE, ErrorCode(ErrorCode::ERR_ALLOWED), 1337 PR_SET_DUMPABLE, ErrorCode(ErrorCode::ERR_ALLOWED),
1332 Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, 1338 sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL,
1333 PR_GET_DUMPABLE, ErrorCode(ErrorCode::ERR_ALLOWED), 1339 PR_GET_DUMPABLE, ErrorCode(ErrorCode::ERR_ALLOWED),
1334 Sandbox::Trap(ReportPrctlFailure, NULL)))); 1340 sandbox->Trap(ReportPrctlFailure, NULL))));
1335 } 1341 }
1336 1342
1337 ErrorCode RestrictIoctl() { 1343 ErrorCode RestrictIoctl(Sandbox *sandbox) {
1338 // Allow TCGETS and FIONREAD, trap to ReportIoctlFailure otherwise. 1344 // Allow TCGETS and FIONREAD, trap to ReportIoctlFailure otherwise.
1339 return Sandbox::Cond(1, ErrorCode::TP_64BIT, ErrorCode::OP_EQUAL, TCGETS, 1345 return sandbox->Cond(1, ErrorCode::TP_64BIT, ErrorCode::OP_EQUAL, TCGETS,
1340 ErrorCode(ErrorCode::ERR_ALLOWED), 1346 ErrorCode(ErrorCode::ERR_ALLOWED),
1341 Sandbox::Cond(1, ErrorCode::TP_64BIT, ErrorCode::OP_EQUAL, FIONREAD, 1347 sandbox->Cond(1, ErrorCode::TP_64BIT, ErrorCode::OP_EQUAL, FIONREAD,
1342 ErrorCode(ErrorCode::ERR_ALLOWED), 1348 ErrorCode(ErrorCode::ERR_ALLOWED),
1343 Sandbox::Trap(ReportIoctlFailure, NULL))); 1349 sandbox->Trap(ReportIoctlFailure, NULL)));
1344 } 1350 }
1345 1351
1346 ErrorCode RendererOrWorkerProcessPolicy(int sysno, void *) { 1352 ErrorCode RendererOrWorkerProcessPolicy(Sandbox *sandbox, int sysno, void *) {
1347 switch (sysno) { 1353 switch (sysno) {
1348 case __NR_clone: 1354 case __NR_clone:
1349 return RestrictCloneToThreads(); 1355 return RestrictCloneToThreads(sandbox);
1350 case __NR_ioctl: 1356 case __NR_ioctl:
1351 // Restrict IOCTL on x86_64 on Linux but not Chrome OS. 1357 // Restrict IOCTL on x86_64 on Linux but not Chrome OS.
1352 if (IsArchitectureX86_64() && !IsChromeOS()) { 1358 if (IsArchitectureX86_64() && !IsChromeOS()) {
1353 return RestrictIoctl(); 1359 return RestrictIoctl(sandbox);
1354 } else { 1360 } else {
1355 return ErrorCode(ErrorCode::ERR_ALLOWED); 1361 return ErrorCode(ErrorCode::ERR_ALLOWED);
1356 } 1362 }
1357 case __NR_prctl: 1363 case __NR_prctl:
1358 return RestrictPrctl(); 1364 return RestrictPrctl(sandbox);
1359 // Allow the system calls below. 1365 // Allow the system calls below.
1360 case __NR_fdatasync: 1366 case __NR_fdatasync:
1361 case __NR_fsync: 1367 case __NR_fsync:
1362 #if defined(__i386__) || defined(__x86_64__) 1368 #if defined(__i386__) || defined(__x86_64__)
1363 case __NR_getrlimit: 1369 case __NR_getrlimit:
1364 #endif 1370 #endif
1365 case __NR_mremap: // See crbug.com/149834. 1371 case __NR_mremap: // See crbug.com/149834.
1366 case __NR_pread64: 1372 case __NR_pread64:
1367 case __NR_pwrite64: 1373 case __NR_pwrite64:
1368 #if defined(ADDRESS_SANITIZER) 1374 #if defined(ADDRESS_SANITIZER)
(...skipping 17 matching lines...) Expand all
1386 #if defined(__x86_64__) || defined(__arm__) 1392 #if defined(__x86_64__) || defined(__arm__)
1387 if (IsSystemVSharedMemory(sysno)) 1393 if (IsSystemVSharedMemory(sysno))
1388 return ErrorCode(ErrorCode::ERR_ALLOWED); 1394 return ErrorCode(ErrorCode::ERR_ALLOWED);
1389 #endif 1395 #endif
1390 #if defined(__i386__) 1396 #if defined(__i386__)
1391 if (IsSystemVIpc(sysno)) 1397 if (IsSystemVIpc(sysno))
1392 return ErrorCode(ErrorCode::ERR_ALLOWED); 1398 return ErrorCode(ErrorCode::ERR_ALLOWED);
1393 #endif 1399 #endif
1394 1400
1395 // Default on the baseline policy. 1401 // Default on the baseline policy.
1396 return BaselinePolicy(sysno); 1402 return BaselinePolicy(sandbox, sysno);
1397 } 1403 }
1398 } 1404 }
1399 1405
1400 ErrorCode FlashProcessPolicy(int sysno, void *) { 1406 ErrorCode FlashProcessPolicy(Sandbox *sandbox, int sysno, void *) {
1401 switch (sysno) { 1407 switch (sysno) {
1402 case __NR_sched_getaffinity: 1408 case __NR_sched_getaffinity:
1403 case __NR_sched_setscheduler: 1409 case __NR_sched_setscheduler:
1404 case __NR_times: 1410 case __NR_times:
1405 return ErrorCode(ErrorCode::ERR_ALLOWED); 1411 return ErrorCode(ErrorCode::ERR_ALLOWED);
1406 case __NR_ioctl: 1412 case __NR_ioctl:
1407 return ErrorCode(ENOTTY); // Flash Access. 1413 return ErrorCode(ENOTTY); // Flash Access.
1408 default: 1414 default:
1409 // These need further tightening. 1415 // These need further tightening.
1410 #if defined(__x86_64__) || defined(__arm__) 1416 #if defined(__x86_64__) || defined(__arm__)
1411 if (IsSystemVSharedMemory(sysno)) 1417 if (IsSystemVSharedMemory(sysno))
1412 return ErrorCode(ErrorCode::ERR_ALLOWED); 1418 return ErrorCode(ErrorCode::ERR_ALLOWED);
1413 #endif 1419 #endif
1414 #if defined(__i386__) 1420 #if defined(__i386__)
1415 if (IsSystemVIpc(sysno)) 1421 if (IsSystemVIpc(sysno))
1416 return ErrorCode(ErrorCode::ERR_ALLOWED); 1422 return ErrorCode(ErrorCode::ERR_ALLOWED);
1417 #endif 1423 #endif
1418 1424
1419 // Default on the baseline policy. 1425 // Default on the baseline policy.
1420 return BaselinePolicy(sysno); 1426 return BaselinePolicy(sandbox, sysno);
1421 } 1427 }
1422 } 1428 }
1423 1429
1424 ErrorCode BlacklistDebugAndNumaPolicy(int sysno, void *) { 1430 ErrorCode BlacklistDebugAndNumaPolicy(Sandbox *sandbox, int sysno, void *) {
1425 if (!Sandbox::IsValidSyscallNumber(sysno)) { 1431 if (!Sandbox::IsValidSyscallNumber(sysno)) {
1426 // TODO(jln) we should not have to do that in a trivial policy. 1432 // TODO(jln) we should not have to do that in a trivial policy.
1427 return ErrorCode(ENOSYS); 1433 return ErrorCode(ENOSYS);
1428 } 1434 }
1429 1435
1430 if (IsDebug(sysno) || IsNuma(sysno)) 1436 if (IsDebug(sysno) || IsNuma(sysno))
1431 return Sandbox::Trap(CrashSIGSYS_Handler, NULL); 1437 return sandbox->Trap(CrashSIGSYS_Handler, NULL);
1432 1438
1433 return ErrorCode(ErrorCode::ERR_ALLOWED); 1439 return ErrorCode(ErrorCode::ERR_ALLOWED);
1434 } 1440 }
1435 1441
1436 // Allow all syscalls. 1442 // Allow all syscalls.
1437 // This will still deny x32 or IA32 calls in 64 bits mode or 1443 // This will still deny x32 or IA32 calls in 64 bits mode or
1438 // 64 bits system calls in compatibility mode. 1444 // 64 bits system calls in compatibility mode.
1439 ErrorCode AllowAllPolicy(int sysno, void *) { 1445 ErrorCode AllowAllPolicy(Sandbox *, int sysno, void *) {
1440 if (!Sandbox::IsValidSyscallNumber(sysno)) { 1446 if (!Sandbox::IsValidSyscallNumber(sysno)) {
1441 // TODO(jln) we should not have to do that in a trivial policy. 1447 // TODO(jln) we should not have to do that in a trivial policy.
1442 return ErrorCode(ENOSYS); 1448 return ErrorCode(ENOSYS);
1443 } else { 1449 } else {
1444 return ErrorCode(ErrorCode::ERR_ALLOWED); 1450 return ErrorCode(ErrorCode::ERR_ALLOWED);
1445 } 1451 }
1446 } 1452 }
1447 1453
1448 bool EnableGpuBrokerPolicyCallBack() { 1454 bool EnableGpuBrokerPolicyCallBack() {
1449 StartSandboxWithPolicy(GpuBrokerProcessPolicy, NULL); 1455 Sandbox sandbox;
1456 StartSandboxWithPolicy(&sandbox, GpuBrokerProcessPolicy, NULL);
1450 return true; 1457 return true;
1451 } 1458 }
1452 1459
1453 // Start a broker process to handle open() inside the sandbox. 1460 // Start a broker process to handle open() inside the sandbox.
1454 void InitGpuBrokerProcess(BrokerProcess** broker_process) { 1461 void InitGpuBrokerProcess(BrokerProcess** broker_process) {
1455 static const char kDriRcPath[] = "/etc/drirc"; 1462 static const char kDriRcPath[] = "/etc/drirc";
1456 static const char kDriCard0Path[] = "/dev/dri/card0"; 1463 static const char kDriCard0Path[] = "/dev/dri/card0";
1457 1464
1458 CHECK(broker_process); 1465 CHECK(broker_process);
1459 CHECK(*broker_process == NULL); 1466 CHECK(*broker_process == NULL);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 if (process_type == switches::kUtilityProcess) { 1530 if (process_type == switches::kUtilityProcess) {
1524 return BlacklistDebugAndNumaPolicy; 1531 return BlacklistDebugAndNumaPolicy;
1525 } 1532 }
1526 1533
1527 NOTREACHED(); 1534 NOTREACHED();
1528 // This will be our default if we need one. 1535 // This will be our default if we need one.
1529 return AllowAllPolicy; 1536 return AllowAllPolicy;
1530 } 1537 }
1531 1538
1532 // broker_process can be NULL if there is no need for one. 1539 // broker_process can be NULL if there is no need for one.
1533 void StartSandboxWithPolicy(Sandbox::EvaluateSyscall syscall_policy, 1540 void StartSandboxWithPolicy(Sandbox *sandbox,
1541 Sandbox::EvaluateSyscall syscall_policy,
1534 BrokerProcess* broker_process) { 1542 BrokerProcess* broker_process) {
1535 1543 sandbox->SetSandboxPolicy(syscall_policy, broker_process);
jln (very slow on Chromium) 2013/02/20 01:35:49 It looks like this is where the Sandbox object sho
1536 Sandbox::SetSandboxPolicy(syscall_policy, broker_process); 1544 sandbox->StartSandbox();
1537 Sandbox::StartSandbox();
1538 } 1545 }
1539 1546
1540 // Initialize the seccomp-bpf sandbox. 1547 // Initialize the seccomp-bpf sandbox.
1541 bool StartBpfSandbox(const CommandLine& command_line, 1548 bool StartBpfSandbox(const CommandLine& command_line,
1542 const std::string& process_type) { 1549 const std::string& process_type) {
1543 Sandbox::EvaluateSyscall syscall_policy = 1550 Sandbox::EvaluateSyscall syscall_policy =
1544 GetProcessSyscallPolicy(command_line, process_type); 1551 GetProcessSyscallPolicy(command_line, process_type);
1545 1552
1546 BrokerProcess* broker_process = NULL; 1553 BrokerProcess* broker_process = NULL;
1547 // Warm up resources needed by the policy we're about to enable and 1554 // Warm up resources needed by the policy we're about to enable and
1548 // eventually start a broker process. 1555 // eventually start a broker process.
1549 WarmupPolicy(syscall_policy, &broker_process); 1556 WarmupPolicy(syscall_policy, &broker_process);
1550 1557
1551 StartSandboxWithPolicy(syscall_policy, broker_process); 1558 Sandbox sandbox;
jln (very slow on Chromium) 2013/02/20 01:35:49 This looks very suspicious to have a sandbox objec
1559 StartSandboxWithPolicy(&sandbox, syscall_policy, broker_process);
1552 1560
1553 return true; 1561 return true;
1554 } 1562 }
1555 1563
1556 } // namespace 1564 } // namespace
1557 1565
1558 #endif // SECCOMP_BPF_SANDBOX 1566 #endif // SECCOMP_BPF_SANDBOX
1559 1567
1560 namespace content { 1568 namespace content {
1561 1569
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 // should enable it, enable it or die. 1618 // should enable it, enable it or die.
1611 bool started_sandbox = StartBpfSandbox(command_line, process_type); 1619 bool started_sandbox = StartBpfSandbox(command_line, process_type);
1612 CHECK(started_sandbox); 1620 CHECK(started_sandbox);
1613 return true; 1621 return true;
1614 } 1622 }
1615 #endif 1623 #endif
1616 return false; 1624 return false;
1617 } 1625 }
1618 1626
1619 } // namespace content 1627 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | sandbox/linux/sandbox_linux.gypi » ('j') | sandbox/linux/seccomp-bpf/sandbox_bpf.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698