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

Side by Side Diff: sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h" 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <linux/filter.h> 8 #include <linux/filter.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 13 matching lines...) Expand all
24 SandboxBPFTestRunner::~SandboxBPFTestRunner() { 24 SandboxBPFTestRunner::~SandboxBPFTestRunner() {
25 } 25 }
26 26
27 void SandboxBPFTestRunner::Run() { 27 void SandboxBPFTestRunner::Run() {
28 DCHECK(bpf_tester_delegate_); 28 DCHECK(bpf_tester_delegate_);
29 sandbox::Die::EnableSimpleExit(); 29 sandbox::Die::EnableSimpleExit();
30 30
31 scoped_ptr<bpf_dsl::Policy> policy = 31 scoped_ptr<bpf_dsl::Policy> policy =
32 bpf_tester_delegate_->GetSandboxBPFPolicy(); 32 bpf_tester_delegate_->GetSandboxBPFPolicy();
33 33
34 if (sandbox::SandboxBPF::SupportsSeccompSandbox(-1) == 34 if (sandbox::SandboxBPF::SupportsSeccompSandbox(
35 sandbox::SandboxBPF::STATUS_AVAILABLE) { 35 SandboxBPF::SeccompLevel::SINGLE_THREADED)) {
36 // Ensure the the sandbox is actually available at this time
37 int proc_fd;
38 SANDBOX_ASSERT((proc_fd = open("/proc", O_RDONLY | O_DIRECTORY)) >= 0);
39 SANDBOX_ASSERT(sandbox::SandboxBPF::SupportsSeccompSandbox(proc_fd) ==
40 sandbox::SandboxBPF::STATUS_AVAILABLE);
41
42 // Initialize and then start the sandbox with our custom policy 36 // Initialize and then start the sandbox with our custom policy
43 sandbox::SandboxBPF sandbox; 37 sandbox::SandboxBPF sandbox(policy.release());
44 sandbox.set_proc_fd(proc_fd); 38 SANDBOX_ASSERT(sandbox.StartSandbox(
45 sandbox.SetSandboxPolicy(policy.release()); 39 sandbox::SandboxBPF::SeccompLevel::SINGLE_THREADED));
46 SANDBOX_ASSERT(
47 sandbox.StartSandbox(sandbox::SandboxBPF::PROCESS_SINGLE_THREADED));
48 40
49 // Run the actual test. 41 // Run the actual test.
50 bpf_tester_delegate_->RunTestFunction(); 42 bpf_tester_delegate_->RunTestFunction();
51 } else { 43 } else {
52 printf("This BPF test is not fully running in this configuration!\n"); 44 printf("This BPF test is not fully running in this configuration!\n");
53 // Android and Valgrind are the only configurations where we accept not 45 // Android and Valgrind are the only configurations where we accept not
54 // having kernel BPF support. 46 // having kernel BPF support.
55 if (!IsAndroid() && !IsRunningOnValgrind()) { 47 if (!IsAndroid() && !IsRunningOnValgrind()) {
56 const bool seccomp_bpf_is_supported = false; 48 const bool seccomp_bpf_is_supported = false;
57 SANDBOX_ASSERT(seccomp_bpf_is_supported); 49 SANDBOX_ASSERT(seccomp_bpf_is_supported);
58 } 50 }
59 // Call the compiler and verify the policy. That's the least we can do, 51 // Call the compiler and verify the policy. That's the least we can do,
60 // if we don't have kernel support. 52 // if we don't have kernel support.
61 sandbox::SandboxBPF sandbox; 53 sandbox::SandboxBPF sandbox(policy.release());
62 sandbox.SetSandboxPolicy(policy.release());
63 sandbox.AssembleFilter(true /* force_verification */); 54 sandbox.AssembleFilter(true /* force_verification */);
64 sandbox::UnitTests::IgnoreThisTest(); 55 sandbox::UnitTests::IgnoreThisTest();
65 } 56 }
66 } 57 }
67 58
68 bool SandboxBPFTestRunner::ShouldCheckForLeaks() const { 59 bool SandboxBPFTestRunner::ShouldCheckForLeaks() const {
69 // LSAN requires being able to use ptrace() and other system calls that could 60 // LSAN requires being able to use ptrace() and other system calls that could
70 // be denied. 61 // be denied.
71 return false; 62 return false;
72 } 63 }
73 64
74 } // namespace sandbox 65 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf.cc ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698