| Index: sandbox/linux/bpf_dsl/policy_compiler.cc
|
| diff --git a/sandbox/linux/bpf_dsl/policy_compiler.cc b/sandbox/linux/bpf_dsl/policy_compiler.cc
|
| index 9d94968b0af22073d1540332e4fb24d772421639..f508b309f2149348d60461410d65b96cc3e10bf6 100644
|
| --- a/sandbox/linux/bpf_dsl/policy_compiler.cc
|
| +++ b/sandbox/linux/bpf_dsl/policy_compiler.cc
|
| @@ -15,9 +15,11 @@
|
| #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
|
| #include "sandbox/linux/bpf_dsl/bpf_dsl_impl.h"
|
| #include "sandbox/linux/bpf_dsl/codegen.h"
|
| +#include "sandbox/linux/bpf_dsl/dump_bpf.h"
|
| #include "sandbox/linux/bpf_dsl/policy.h"
|
| #include "sandbox/linux/bpf_dsl/seccomp_macros.h"
|
| #include "sandbox/linux/bpf_dsl/syscall_set.h"
|
| +#include "sandbox/linux/bpf_dsl/verifier.h"
|
| #include "sandbox/linux/seccomp-bpf/errorcode.h"
|
| #include "sandbox/linux/system_headers/linux_seccomp.h"
|
|
|
| @@ -94,7 +96,7 @@ PolicyCompiler::PolicyCompiler(const Policy* policy, TrapRegistry* registry)
|
| PolicyCompiler::~PolicyCompiler() {
|
| }
|
|
|
| -scoped_ptr<CodeGen::Program> PolicyCompiler::Compile() {
|
| +scoped_ptr<CodeGen::Program> PolicyCompiler::Compile(bool verify) {
|
| CHECK(policy_->InvalidSyscall()->IsDeny())
|
| << "Policies should deny invalid system calls";
|
|
|
| @@ -115,6 +117,18 @@ scoped_ptr<CodeGen::Program> PolicyCompiler::Compile() {
|
| // Assemble the BPF filter program.
|
| scoped_ptr<CodeGen::Program> program(new CodeGen::Program());
|
| gen_.Compile(AssemblePolicy(), program.get());
|
| +
|
| + // Make sure compilation resulted in a BPF program that executes
|
| + // correctly. Otherwise, there is an internal error in our BPF compiler.
|
| + // There is really nothing the caller can do until the bug is fixed.
|
| + if (verify) {
|
| + const char* err = nullptr;
|
| + if (!Verifier::VerifyBPF(this, *program, *policy_, &err)) {
|
| + DumpBPF::PrintProgram(*program);
|
| + LOG(FATAL) << err;
|
| + }
|
| + }
|
| +
|
| return program.Pass();
|
| }
|
|
|
|
|