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

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

Issue 11411254: SECCOMP-BPF: Added supported for inspection system call arguments from BPF filters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another attempt at fixing the rebase Created 8 years 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
« no previous file with comments | « no previous file | sandbox/linux/seccomp-bpf/bpf_tests.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>
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 if (IsSystemVIpc(sysno)) 1290 if (IsSystemVIpc(sysno))
1291 return ErrorCode(ErrorCode::ERR_ALLOWED); 1291 return ErrorCode(ErrorCode::ERR_ALLOWED);
1292 #endif 1292 #endif
1293 1293
1294 // Default on the baseline policy. 1294 // Default on the baseline policy.
1295 return BaselinePolicy(sysno); 1295 return BaselinePolicy(sysno);
1296 } 1296 }
1297 } 1297 }
1298 1298
1299 ErrorCode BlacklistDebugAndNumaPolicy(int sysno, void *) { 1299 ErrorCode BlacklistDebugAndNumaPolicy(int sysno, void *) {
1300 if (!Sandbox::isValidSyscallNumber(sysno)) { 1300 if (!Sandbox::IsValidSyscallNumber(sysno)) {
1301 // TODO(jln) we should not have to do that in a trivial policy. 1301 // TODO(jln) we should not have to do that in a trivial policy.
1302 return ErrorCode(ENOSYS); 1302 return ErrorCode(ENOSYS);
1303 } 1303 }
1304 1304
1305 if (IsDebug(sysno) || IsNuma(sysno)) 1305 if (IsDebug(sysno) || IsNuma(sysno))
1306 return Sandbox::Trap(CrashSIGSYS_Handler, NULL); 1306 return Sandbox::Trap(CrashSIGSYS_Handler, NULL);
1307 1307
1308 return ErrorCode(ErrorCode::ERR_ALLOWED); 1308 return ErrorCode(ErrorCode::ERR_ALLOWED);
1309 } 1309 }
1310 1310
1311 // Allow all syscalls. 1311 // Allow all syscalls.
1312 // This will still deny x32 or IA32 calls in 64 bits mode or 1312 // This will still deny x32 or IA32 calls in 64 bits mode or
1313 // 64 bits system calls in compatibility mode. 1313 // 64 bits system calls in compatibility mode.
1314 ErrorCode AllowAllPolicy(int sysno, void *) { 1314 ErrorCode AllowAllPolicy(int sysno, void *) {
1315 if (!Sandbox::isValidSyscallNumber(sysno)) { 1315 if (!Sandbox::IsValidSyscallNumber(sysno)) {
1316 // TODO(jln) we should not have to do that in a trivial policy. 1316 // TODO(jln) we should not have to do that in a trivial policy.
1317 return ErrorCode(ENOSYS); 1317 return ErrorCode(ENOSYS);
1318 } else { 1318 } else {
1319 return ErrorCode(ErrorCode::ERR_ALLOWED); 1319 return ErrorCode(ErrorCode::ERR_ALLOWED);
1320 } 1320 }
1321 } 1321 }
1322 1322
1323 bool EnableGpuBrokerPolicyCallBack() { 1323 bool EnableGpuBrokerPolicyCallBack() {
1324 StartSandboxWithPolicy(GpuBrokerProcessPolicy_x86_64, NULL); 1324 StartSandboxWithPolicy(GpuBrokerProcessPolicy_x86_64, NULL);
1325 return true; 1325 return true;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 1395
1396 NOTREACHED(); 1396 NOTREACHED();
1397 // This will be our default if we need one. 1397 // This will be our default if we need one.
1398 return AllowAllPolicy; 1398 return AllowAllPolicy;
1399 } 1399 }
1400 1400
1401 // broker_process can be NULL if there is no need for one. 1401 // broker_process can be NULL if there is no need for one.
1402 void StartSandboxWithPolicy(Sandbox::EvaluateSyscall syscall_policy, 1402 void StartSandboxWithPolicy(Sandbox::EvaluateSyscall syscall_policy,
1403 BrokerProcess* broker_process) { 1403 BrokerProcess* broker_process) {
1404 1404
1405 Sandbox::setSandboxPolicy(syscall_policy, broker_process); 1405 Sandbox::SetSandboxPolicy(syscall_policy, broker_process);
1406 Sandbox::startSandbox(); 1406 Sandbox::StartSandbox();
1407 } 1407 }
1408 1408
1409 // Initialize the seccomp-bpf sandbox. 1409 // Initialize the seccomp-bpf sandbox.
1410 bool StartBpfSandbox(const CommandLine& command_line, 1410 bool StartBpfSandbox(const CommandLine& command_line,
1411 const std::string& process_type) { 1411 const std::string& process_type) {
1412 Sandbox::EvaluateSyscall syscall_policy = 1412 Sandbox::EvaluateSyscall syscall_policy =
1413 GetProcessSyscallPolicy(command_line, process_type); 1413 GetProcessSyscallPolicy(command_line, process_type);
1414 1414
1415 BrokerProcess* broker_process = NULL; 1415 BrokerProcess* broker_process = NULL;
1416 // Warm up resources needed by the policy we're about to enable and 1416 // Warm up resources needed by the policy we're about to enable and
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 return true; 1449 return true;
1450 #endif // SECCOMP_BPF_SANDBOX 1450 #endif // SECCOMP_BPF_SANDBOX
1451 return false; 1451 return false;
1452 } 1452 }
1453 1453
1454 bool SandboxSeccompBpf::SupportsSandbox() { 1454 bool SandboxSeccompBpf::SupportsSandbox() {
1455 #if defined(SECCOMP_BPF_SANDBOX) 1455 #if defined(SECCOMP_BPF_SANDBOX)
1456 // TODO(jln): pass the saved proc_fd_ from the LinuxSandbox singleton 1456 // TODO(jln): pass the saved proc_fd_ from the LinuxSandbox singleton
1457 // here. 1457 // here.
1458 Sandbox::SandboxStatus bpf_sandbox_status = 1458 Sandbox::SandboxStatus bpf_sandbox_status =
1459 Sandbox::supportsSeccompSandbox(-1); 1459 Sandbox::SupportsSeccompSandbox(-1);
1460 // Kernel support is what we are interested in here. Other status 1460 // Kernel support is what we are interested in here. Other status
1461 // such as STATUS_UNAVAILABLE (has threads) still indicate kernel support. 1461 // such as STATUS_UNAVAILABLE (has threads) still indicate kernel support.
1462 // We make this a negative check, since if there is a bug, we would rather 1462 // We make this a negative check, since if there is a bug, we would rather
1463 // "fail closed" (expect a sandbox to be available and try to start it). 1463 // "fail closed" (expect a sandbox to be available and try to start it).
1464 if (bpf_sandbox_status != Sandbox::STATUS_UNSUPPORTED) { 1464 if (bpf_sandbox_status != Sandbox::STATUS_UNSUPPORTED) {
1465 return true; 1465 return true;
1466 } 1466 }
1467 #endif 1467 #endif
1468 return false; 1468 return false;
1469 } 1469 }
1470 1470
1471 bool SandboxSeccompBpf::StartSandbox(const std::string& process_type) { 1471 bool SandboxSeccompBpf::StartSandbox(const std::string& process_type) {
1472 #if defined(SECCOMP_BPF_SANDBOX) 1472 #if defined(SECCOMP_BPF_SANDBOX)
1473 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 1473 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1474 1474
1475 if (IsSeccompBpfDesired() && // Global switches policy. 1475 if (IsSeccompBpfDesired() && // Global switches policy.
1476 ShouldEnableSeccompBpf(process_type) && // Process-specific policy. 1476 ShouldEnableSeccompBpf(process_type) && // Process-specific policy.
1477 SupportsSandbox()) { 1477 SupportsSandbox()) {
1478 // If the kernel supports the sandbox, and if the command line says we 1478 // If the kernel supports the sandbox, and if the command line says we
1479 // should enable it, enable it or die. 1479 // should enable it, enable it or die.
1480 bool started_sandbox = StartBpfSandbox(command_line, process_type); 1480 bool started_sandbox = StartBpfSandbox(command_line, process_type);
1481 CHECK(started_sandbox); 1481 CHECK(started_sandbox);
1482 return true; 1482 return true;
1483 } 1483 }
1484 #endif 1484 #endif
1485 return false; 1485 return false;
1486 } 1486 }
1487 1487
1488 } // namespace content 1488 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | sandbox/linux/seccomp-bpf/bpf_tests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698