forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox_bpf_test_runner.cc
65 lines (53 loc) · 2.1 KB
/
sandbox_bpf_test_runner.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sandbox/linux/seccomp-bpf/sandbox_bpf_test_runner.h"
#include <fcntl.h>
#include <linux/filter.h>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "sandbox/linux/bpf_dsl/policy.h"
#include "sandbox/linux/seccomp-bpf/die.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
#include "sandbox/linux/tests/unit_tests.h"
namespace sandbox {
SandboxBPFTestRunner::SandboxBPFTestRunner(
BPFTesterDelegate* bpf_tester_delegate)
: bpf_tester_delegate_(bpf_tester_delegate) {
}
SandboxBPFTestRunner::~SandboxBPFTestRunner() {
}
void SandboxBPFTestRunner::Run() {
DCHECK(bpf_tester_delegate_);
sandbox::Die::EnableSimpleExit();
scoped_ptr<bpf_dsl::Policy> policy =
bpf_tester_delegate_->GetSandboxBPFPolicy();
if (sandbox::SandboxBPF::SupportsSeccompSandbox(
SandboxBPF::SeccompLevel::SINGLE_THREADED)) {
// Initialize and then start the sandbox with our custom policy
sandbox::SandboxBPF sandbox(policy.release());
SANDBOX_ASSERT(sandbox.StartSandbox(
sandbox::SandboxBPF::SeccompLevel::SINGLE_THREADED));
// Run the actual test.
bpf_tester_delegate_->RunTestFunction();
} else {
printf("This BPF test is not fully running in this configuration!\n");
// Android and Valgrind are the only configurations where we accept not
// having kernel BPF support.
if (!IsAndroid() && !IsRunningOnValgrind()) {
const bool seccomp_bpf_is_supported = false;
SANDBOX_ASSERT(seccomp_bpf_is_supported);
}
// Call the compiler and verify the policy. That's the least we can do,
// if we don't have kernel support.
sandbox::SandboxBPF sandbox(policy.release());
sandbox.AssembleFilter(true /* force_verification */);
sandbox::UnitTests::IgnoreThisTest();
}
}
bool SandboxBPFTestRunner::ShouldCheckForLeaks() const {
// LSAN requires being able to use ptrace() and other system calls that could
// be denied.
return false;
}
} // namespace sandbox