| 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/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 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 #if defined(__arm__) | 1225 #if defined(__arm__) |
| 1224 IsArmPciConfig(sysno) || | 1226 IsArmPciConfig(sysno) || |
| 1225 #endif | 1227 #endif |
| 1226 IsTimer(sysno)) { | 1228 IsTimer(sysno)) { |
| 1227 return true; | 1229 return true; |
| 1228 } else { | 1230 } else { |
| 1229 return false; | 1231 return false; |
| 1230 } | 1232 } |
| 1231 } | 1233 } |
| 1232 | 1234 |
| 1233 ErrorCode BaselinePolicy(int sysno) { | 1235 ErrorCode BaselinePolicy(Sandbox *sandbox, int sysno) { |
| 1234 #if defined(__x86_64__) || defined(__arm__) | 1236 #if defined(__x86_64__) || defined(__arm__) |
| 1235 if (sysno == __NR_socketpair) { | 1237 if (sysno == __NR_socketpair) { |
| 1236 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. | 1238 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. |
| 1237 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); | 1239 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); |
| 1238 return Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, AF_UNIX, | 1240 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, AF_UNIX, |
| 1239 ErrorCode(ErrorCode::ERR_ALLOWED), | 1241 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1240 Sandbox::Trap(CrashSIGSYS_Handler, NULL)); | 1242 sandbox->Trap(CrashSIGSYS_Handler, NULL)); |
| 1241 } | 1243 } |
| 1242 #endif | 1244 #endif |
| 1243 if (IsBaselinePolicyAllowed(sysno)) { | 1245 if (IsBaselinePolicyAllowed(sysno)) { |
| 1244 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1246 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1245 } | 1247 } |
| 1246 | 1248 |
| 1247 #if defined(__i386__) | 1249 #if defined(__i386__) |
| 1248 // socketcall(2) should be tightened. | 1250 // socketcall(2) should be tightened. |
| 1249 if (IsSocketCall(sysno)) { | 1251 if (IsSocketCall(sysno)) { |
| 1250 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1252 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1251 } | 1253 } |
| 1252 #endif | 1254 #endif |
| 1253 | 1255 |
| 1254 // TODO(jln): some system calls in those sets are not supposed to | 1256 // TODO(jln): some system calls in those sets are not supposed to |
| 1255 // return ENOENT. Return the appropriate error. | 1257 // return ENOENT. Return the appropriate error. |
| 1256 if (IsFileSystem(sysno) || IsCurrentDirectory(sysno)) { | 1258 if (IsFileSystem(sysno) || IsCurrentDirectory(sysno)) { |
| 1257 return ErrorCode(ENOENT); | 1259 return ErrorCode(ENOENT); |
| 1258 } | 1260 } |
| 1259 | 1261 |
| 1260 if (IsUmask(sysno) || IsDeniedFileSystemAccessViaFd(sysno) || | 1262 if (IsUmask(sysno) || IsDeniedFileSystemAccessViaFd(sysno) || |
| 1261 IsDeniedGetOrModifySocket(sysno)) { | 1263 IsDeniedGetOrModifySocket(sysno)) { |
| 1262 return ErrorCode(EPERM); | 1264 return ErrorCode(EPERM); |
| 1263 } | 1265 } |
| 1264 | 1266 |
| 1265 if (IsBaselinePolicyWatched(sysno)) { | 1267 if (IsBaselinePolicyWatched(sysno)) { |
| 1266 // Previously unseen syscalls. TODO(jln): some of these should | 1268 // Previously unseen syscalls. TODO(jln): some of these should |
| 1267 // be denied gracefully right away. | 1269 // be denied gracefully right away. |
| 1268 return Sandbox::Trap(CrashSIGSYS_Handler, NULL); | 1270 return sandbox->Trap(CrashSIGSYS_Handler, NULL); |
| 1269 } | 1271 } |
| 1270 // In any other case crash the program with our SIGSYS handler | 1272 // In any other case crash the program with our SIGSYS handler |
| 1271 return Sandbox::Trap(CrashSIGSYS_Handler, NULL); | 1273 return sandbox->Trap(CrashSIGSYS_Handler, NULL); |
| 1272 } | 1274 } |
| 1273 | 1275 |
| 1274 // x86_64/i386 for now. Needs to be adapted and tested for ARM. | 1276 // x86_64/i386 for now. Needs to be adapted and tested for ARM. |
| 1275 ErrorCode GpuProcessPolicy(int sysno, void *broker_process) { | 1277 ErrorCode GpuProcessPolicy(Sandbox *sandbox, int sysno, |
| 1278 void *broker_process) { |
| 1276 switch(sysno) { | 1279 switch(sysno) { |
| 1277 case __NR_ioctl: | 1280 case __NR_ioctl: |
| 1278 #if defined(ADDRESS_SANITIZER) | 1281 #if defined(ADDRESS_SANITIZER) |
| 1279 // Allow to call sched_getaffinity under AddressSanitizer. | 1282 // Allow to call sched_getaffinity under AddressSanitizer. |
| 1280 case __NR_sched_getaffinity: | 1283 case __NR_sched_getaffinity: |
| 1281 #endif | 1284 #endif |
| 1282 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1285 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1283 case __NR_open: | 1286 case __NR_open: |
| 1284 case __NR_openat: | 1287 case __NR_openat: |
| 1285 return Sandbox::Trap(GpuOpenSIGSYS_Handler, broker_process); | 1288 return sandbox->Trap(GpuOpenSIGSYS_Handler, broker_process); |
| 1286 default: | 1289 default: |
| 1287 #if defined(__x86_64__) || defined(__arm__) | 1290 #if defined(__x86_64__) || defined(__arm__) |
| 1288 if (IsSystemVSharedMemory(sysno)) | 1291 if (IsSystemVSharedMemory(sysno)) |
| 1289 return ErrorCode(EACCES); | 1292 return ErrorCode(EACCES); |
| 1290 #endif | 1293 #endif |
| 1291 if (IsEventFd(sysno)) | 1294 if (IsEventFd(sysno)) |
| 1292 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1295 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1293 | 1296 |
| 1294 // Default on the baseline policy. | 1297 // Default on the baseline policy. |
| 1295 return BaselinePolicy(sysno); | 1298 return BaselinePolicy(sandbox, sysno); |
| 1296 } | 1299 } |
| 1297 } | 1300 } |
| 1298 | 1301 |
| 1299 // x86_64/i386 for now. Needs to be adapted and tested for ARM. | 1302 // x86_64/i386 for now. Needs to be adapted and tested for ARM. |
| 1300 // A GPU broker policy is the same as a GPU policy with open and | 1303 // A GPU broker policy is the same as a GPU policy with open and |
| 1301 // openat allowed. | 1304 // openat allowed. |
| 1302 ErrorCode GpuBrokerProcessPolicy(int sysno, void*) { | 1305 ErrorCode GpuBrokerProcessPolicy(Sandbox *sandbox, int sysno, void *aux) { |
| 1306 // "aux" would typically be NULL, when called from |
| 1307 // "EnableGpuBrokerPolicyCallBack" |
| 1303 switch(sysno) { | 1308 switch(sysno) { |
| 1304 case __NR_open: | 1309 case __NR_open: |
| 1305 case __NR_openat: | 1310 case __NR_openat: |
| 1306 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1311 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1307 default: | 1312 default: |
| 1308 return GpuProcessPolicy(sysno, NULL); | 1313 return GpuProcessPolicy(sandbox, sysno, aux); |
| 1309 } | 1314 } |
| 1310 } | 1315 } |
| 1311 | 1316 |
| 1312 // Allow clone for threads, crash if anything else is attempted. | 1317 // Allow clone for threads, crash if anything else is attempted. |
| 1313 // Don't restrict on ASAN. | 1318 // Don't restrict on ASAN. |
| 1314 ErrorCode RestrictCloneToThreads() { | 1319 ErrorCode RestrictCloneToThreads(Sandbox *sandbox) { |
| 1315 // Glibc's pthread. | 1320 // Glibc's pthread. |
| 1316 if (!RunningOnASAN()) { | 1321 if (!RunningOnASAN()) { |
| 1317 return Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 1322 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
| 1318 CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | | 1323 CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | |
| 1319 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | | 1324 CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | |
| 1320 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID, | 1325 CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID, |
| 1321 ErrorCode(ErrorCode::ERR_ALLOWED), | 1326 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1322 Sandbox::Trap(ReportCloneFailure, NULL)); | 1327 sandbox->Trap(ReportCloneFailure, NULL)); |
| 1323 } else { | 1328 } else { |
| 1324 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1329 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1325 } | 1330 } |
| 1326 } | 1331 } |
| 1327 | 1332 |
| 1328 ErrorCode RestrictPrctl() { | 1333 ErrorCode RestrictPrctl(Sandbox *sandbox) { |
| 1329 // Allow PR_SET_NAME, PR_SET_DUMPABLE, PR_GET_DUMPABLE. Will need to add | 1334 // Allow PR_SET_NAME, PR_SET_DUMPABLE, PR_GET_DUMPABLE. Will need to add |
| 1330 // seccomp compositing in the future. | 1335 // seccomp compositing in the future. |
| 1331 // PR_SET_PTRACER is used by breakpad but not needed anymore. | 1336 // PR_SET_PTRACER is used by breakpad but not needed anymore. |
| 1332 return Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 1337 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
| 1333 PR_SET_NAME, ErrorCode(ErrorCode::ERR_ALLOWED), | 1338 PR_SET_NAME, ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1334 Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 1339 sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
| 1335 PR_SET_DUMPABLE, ErrorCode(ErrorCode::ERR_ALLOWED), | 1340 PR_SET_DUMPABLE, ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1336 Sandbox::Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 1341 sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
| 1337 PR_GET_DUMPABLE, ErrorCode(ErrorCode::ERR_ALLOWED), | 1342 PR_GET_DUMPABLE, ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1338 Sandbox::Trap(ReportPrctlFailure, NULL)))); | 1343 sandbox->Trap(ReportPrctlFailure, NULL)))); |
| 1339 } | 1344 } |
| 1340 | 1345 |
| 1341 ErrorCode RestrictIoctl() { | 1346 ErrorCode RestrictIoctl(Sandbox *sandbox) { |
| 1342 // Allow TCGETS and FIONREAD, trap to ReportIoctlFailure otherwise. | 1347 // Allow TCGETS and FIONREAD, trap to ReportIoctlFailure otherwise. |
| 1343 return Sandbox::Cond(1, ErrorCode::TP_64BIT, ErrorCode::OP_EQUAL, TCGETS, | 1348 return sandbox->Cond(1, ErrorCode::TP_64BIT, ErrorCode::OP_EQUAL, TCGETS, |
| 1344 ErrorCode(ErrorCode::ERR_ALLOWED), | 1349 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1345 Sandbox::Cond(1, ErrorCode::TP_64BIT, ErrorCode::OP_EQUAL, FIONREAD, | 1350 sandbox->Cond(1, ErrorCode::TP_64BIT, ErrorCode::OP_EQUAL, FIONREAD, |
| 1346 ErrorCode(ErrorCode::ERR_ALLOWED), | 1351 ErrorCode(ErrorCode::ERR_ALLOWED), |
| 1347 Sandbox::Trap(ReportIoctlFailure, NULL))); | 1352 sandbox->Trap(ReportIoctlFailure, NULL))); |
| 1348 } | 1353 } |
| 1349 | 1354 |
| 1350 ErrorCode RendererOrWorkerProcessPolicy(int sysno, void *) { | 1355 ErrorCode RendererOrWorkerProcessPolicy(Sandbox *sandbox, int sysno, void *) { |
| 1351 switch (sysno) { | 1356 switch (sysno) { |
| 1352 case __NR_clone: | 1357 case __NR_clone: |
| 1353 return RestrictCloneToThreads(); | 1358 return RestrictCloneToThreads(sandbox); |
| 1354 case __NR_ioctl: | 1359 case __NR_ioctl: |
| 1355 // Restrict IOCTL on x86_64. | 1360 // Restrict IOCTL on x86_64. |
| 1356 if (IsArchitectureX86_64()) { | 1361 if (IsArchitectureX86_64()) { |
| 1357 return RestrictIoctl(); | 1362 return RestrictIoctl(sandbox); |
| 1358 } else { | 1363 } else { |
| 1359 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1364 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1360 } | 1365 } |
| 1361 case __NR_prctl: | 1366 case __NR_prctl: |
| 1362 return RestrictPrctl(); | 1367 return RestrictPrctl(sandbox); |
| 1363 // Allow the system calls below. | 1368 // Allow the system calls below. |
| 1364 case __NR_fdatasync: | 1369 case __NR_fdatasync: |
| 1365 case __NR_fsync: | 1370 case __NR_fsync: |
| 1366 #if defined(__i386__) || defined(__x86_64__) | 1371 #if defined(__i386__) || defined(__x86_64__) |
| 1367 case __NR_getrlimit: | 1372 case __NR_getrlimit: |
| 1368 #endif | 1373 #endif |
| 1369 case __NR_mremap: // See crbug.com/149834. | 1374 case __NR_mremap: // See crbug.com/149834. |
| 1370 case __NR_pread64: | 1375 case __NR_pread64: |
| 1371 case __NR_pwrite64: | 1376 case __NR_pwrite64: |
| 1372 #if defined(ADDRESS_SANITIZER) | 1377 #if defined(ADDRESS_SANITIZER) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1390 #if defined(__x86_64__) || defined(__arm__) | 1395 #if defined(__x86_64__) || defined(__arm__) |
| 1391 if (IsSystemVSharedMemory(sysno)) | 1396 if (IsSystemVSharedMemory(sysno)) |
| 1392 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1397 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1393 #endif | 1398 #endif |
| 1394 #if defined(__i386__) | 1399 #if defined(__i386__) |
| 1395 if (IsSystemVIpc(sysno)) | 1400 if (IsSystemVIpc(sysno)) |
| 1396 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1401 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1397 #endif | 1402 #endif |
| 1398 | 1403 |
| 1399 // Default on the baseline policy. | 1404 // Default on the baseline policy. |
| 1400 return BaselinePolicy(sysno); | 1405 return BaselinePolicy(sandbox, sysno); |
| 1401 } | 1406 } |
| 1402 } | 1407 } |
| 1403 | 1408 |
| 1404 ErrorCode FlashProcessPolicy(int sysno, void *) { | 1409 ErrorCode FlashProcessPolicy(Sandbox *sandbox, int sysno, void *) { |
| 1405 switch (sysno) { | 1410 switch (sysno) { |
| 1406 case __NR_sched_getaffinity: | 1411 case __NR_sched_getaffinity: |
| 1407 case __NR_sched_setscheduler: | 1412 case __NR_sched_setscheduler: |
| 1408 case __NR_times: | 1413 case __NR_times: |
| 1409 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1414 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1410 case __NR_ioctl: | 1415 case __NR_ioctl: |
| 1411 return ErrorCode(ENOTTY); // Flash Access. | 1416 return ErrorCode(ENOTTY); // Flash Access. |
| 1412 default: | 1417 default: |
| 1413 // These need further tightening. | 1418 // These need further tightening. |
| 1414 #if defined(__x86_64__) || defined(__arm__) | 1419 #if defined(__x86_64__) || defined(__arm__) |
| 1415 if (IsSystemVSharedMemory(sysno)) | 1420 if (IsSystemVSharedMemory(sysno)) |
| 1416 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1421 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1417 #endif | 1422 #endif |
| 1418 #if defined(__i386__) | 1423 #if defined(__i386__) |
| 1419 if (IsSystemVIpc(sysno)) | 1424 if (IsSystemVIpc(sysno)) |
| 1420 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1425 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1421 #endif | 1426 #endif |
| 1422 | 1427 |
| 1423 // Default on the baseline policy. | 1428 // Default on the baseline policy. |
| 1424 return BaselinePolicy(sysno); | 1429 return BaselinePolicy(sandbox, sysno); |
| 1425 } | 1430 } |
| 1426 } | 1431 } |
| 1427 | 1432 |
| 1428 ErrorCode BlacklistDebugAndNumaPolicy(int sysno, void *) { | 1433 ErrorCode BlacklistDebugAndNumaPolicy(Sandbox *sandbox, int sysno, void *) { |
| 1429 if (!Sandbox::IsValidSyscallNumber(sysno)) { | 1434 if (!Sandbox::IsValidSyscallNumber(sysno)) { |
| 1430 // TODO(jln) we should not have to do that in a trivial policy. | 1435 // TODO(jln) we should not have to do that in a trivial policy. |
| 1431 return ErrorCode(ENOSYS); | 1436 return ErrorCode(ENOSYS); |
| 1432 } | 1437 } |
| 1433 | 1438 |
| 1434 if (IsDebug(sysno) || IsNuma(sysno)) | 1439 if (IsDebug(sysno) || IsNuma(sysno)) |
| 1435 return Sandbox::Trap(CrashSIGSYS_Handler, NULL); | 1440 return sandbox->Trap(CrashSIGSYS_Handler, NULL); |
| 1436 | 1441 |
| 1437 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1442 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1438 } | 1443 } |
| 1439 | 1444 |
| 1440 // Allow all syscalls. | 1445 // Allow all syscalls. |
| 1441 // This will still deny x32 or IA32 calls in 64 bits mode or | 1446 // This will still deny x32 or IA32 calls in 64 bits mode or |
| 1442 // 64 bits system calls in compatibility mode. | 1447 // 64 bits system calls in compatibility mode. |
| 1443 ErrorCode AllowAllPolicy(int sysno, void *) { | 1448 ErrorCode AllowAllPolicy(Sandbox *, int sysno, void *) { |
| 1444 if (!Sandbox::IsValidSyscallNumber(sysno)) { | 1449 if (!Sandbox::IsValidSyscallNumber(sysno)) { |
| 1445 // TODO(jln) we should not have to do that in a trivial policy. | 1450 // TODO(jln) we should not have to do that in a trivial policy. |
| 1446 return ErrorCode(ENOSYS); | 1451 return ErrorCode(ENOSYS); |
| 1447 } else { | 1452 } else { |
| 1448 return ErrorCode(ErrorCode::ERR_ALLOWED); | 1453 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 1449 } | 1454 } |
| 1450 } | 1455 } |
| 1451 | 1456 |
| 1452 bool EnableGpuBrokerPolicyCallBack() { | 1457 bool EnableGpuBrokerPolicyCallBack() { |
| 1453 StartSandboxWithPolicy(GpuBrokerProcessPolicy, NULL); | 1458 StartSandboxWithPolicy(GpuBrokerProcessPolicy, NULL); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 } | 1534 } |
| 1530 | 1535 |
| 1531 NOTREACHED(); | 1536 NOTREACHED(); |
| 1532 // This will be our default if we need one. | 1537 // This will be our default if we need one. |
| 1533 return AllowAllPolicy; | 1538 return AllowAllPolicy; |
| 1534 } | 1539 } |
| 1535 | 1540 |
| 1536 // broker_process can be NULL if there is no need for one. | 1541 // broker_process can be NULL if there is no need for one. |
| 1537 void StartSandboxWithPolicy(Sandbox::EvaluateSyscall syscall_policy, | 1542 void StartSandboxWithPolicy(Sandbox::EvaluateSyscall syscall_policy, |
| 1538 BrokerProcess* broker_process) { | 1543 BrokerProcess* broker_process) { |
| 1539 | 1544 // Starting the sandbox is a one-way operation. The kernel doesn't allow |
| 1540 Sandbox::SetSandboxPolicy(syscall_policy, broker_process); | 1545 // us to unload a sandbox policy after it has been started. Nonetheless, |
| 1541 Sandbox::StartSandbox(); | 1546 // in order to make the use of the "Sandbox" object easier, we allow for |
| 1547 // the object to be destroyed after the sandbox has been started. Note that |
| 1548 // doing so does not stop the sandbox. |
| 1549 Sandbox sandbox; |
| 1550 sandbox.SetSandboxPolicy(syscall_policy, broker_process); |
| 1551 sandbox.StartSandbox(); |
| 1542 } | 1552 } |
| 1543 | 1553 |
| 1544 // Initialize the seccomp-bpf sandbox. | 1554 // Initialize the seccomp-bpf sandbox. |
| 1545 bool StartBpfSandbox(const CommandLine& command_line, | 1555 bool StartBpfSandbox(const CommandLine& command_line, |
| 1546 const std::string& process_type) { | 1556 const std::string& process_type) { |
| 1547 Sandbox::EvaluateSyscall syscall_policy = | 1557 Sandbox::EvaluateSyscall syscall_policy = |
| 1548 GetProcessSyscallPolicy(command_line, process_type); | 1558 GetProcessSyscallPolicy(command_line, process_type); |
| 1549 | 1559 |
| 1550 BrokerProcess* broker_process = NULL; | 1560 BrokerProcess* broker_process = NULL; |
| 1551 // Warm up resources needed by the policy we're about to enable and | 1561 // Warm up resources needed by the policy we're about to enable and |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 // should enable it, enable it or die. | 1624 // should enable it, enable it or die. |
| 1615 bool started_sandbox = StartBpfSandbox(command_line, process_type); | 1625 bool started_sandbox = StartBpfSandbox(command_line, process_type); |
| 1616 CHECK(started_sandbox); | 1626 CHECK(started_sandbox); |
| 1617 return true; | 1627 return true; |
| 1618 } | 1628 } |
| 1619 #endif | 1629 #endif |
| 1620 return false; | 1630 return false; |
| 1621 } | 1631 } |
| 1622 | 1632 |
| 1623 } // namespace content | 1633 } // namespace content |
| OLD | NEW |