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

Unified Diff: sandbox/linux/bpf_dsl/policy_compiler.cc

Issue 944763004: Revert of bpf_dsl: switch PolicyCompiler from seccomp-bpf/die.h to base/logging.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sandbox/linux/bpf_dsl/trap_registry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..bcfd21b77658d9abc8bb1abd4260b66b7f12fd23 100644
--- a/sandbox/linux/bpf_dsl/policy_compiler.cc
+++ b/sandbox/linux/bpf_dsl/policy_compiler.cc
@@ -18,6 +18,7 @@
#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/seccomp-bpf/die.h"
#include "sandbox/linux/seccomp-bpf/errorcode.h"
#include "sandbox/linux/system_headers/linux_seccomp.h"
@@ -95,21 +96,35 @@
}
scoped_ptr<CodeGen::Program> PolicyCompiler::Compile() {
- CHECK(policy_->InvalidSyscall()->IsDeny())
- << "Policies should deny invalid system calls";
+ if (!policy_->InvalidSyscall()->IsDeny()) {
+ SANDBOX_DIE("Policies should deny invalid system calls.");
+ }
// If our BPF program has unsafe traps, enable support for them.
if (has_unsafe_traps_) {
+ // As support for unsafe jumps essentially defeats all the security
+ // measures that the sandbox provides, we print a big warning message --
+ // and of course, we make sure to only ever enable this feature if it
+ // is actually requested by the sandbox policy.
+
CHECK_NE(0U, escapepc_) << "UnsafeTrap() requires a valid escape PC";
for (int sysnum : kSyscallsRequiredForUnsafeTraps) {
- CHECK(policy_->EvaluateSyscall(sysnum)->IsAllow())
- << "Policies that use UnsafeTrap() must unconditionally allow all "
- "required system calls";
- }
-
- CHECK(registry_->EnableUnsafeTraps())
- << "We'd rather die than enable unsafe traps";
+ if (!policy_->EvaluateSyscall(sysnum)->IsAllow()) {
+ SANDBOX_DIE(
+ "Policies that use UnsafeTrap() must unconditionally allow all "
+ "required system calls");
+ }
+ }
+
+ if (!registry_->EnableUnsafeTraps()) {
+ // We should never be able to get here, as UnsafeTrap() should never
+ // actually return a valid ErrorCode object unless the user set the
+ // CHROME_SANDBOX_DEBUGGING environment variable; and therefore,
+ // "has_unsafe_traps" would always be false. But better double-check
+ // than enabling dangerous code.
+ SANDBOX_DIE("We'd rather die than enable unsafe traps");
+ }
}
// Assemble the BPF filter program.
@@ -246,9 +261,9 @@
// a binary search over the ranges.
// As a sanity check, we need to have at least one distinct ranges for us
// to be able to build a jump table.
- CHECK(start < stop) << "Invalid iterator range";
- const auto n = stop - start;
- if (n == 1) {
+ if (stop - start <= 0) {
+ SANDBOX_DIE("Invalid set of system call ranges");
+ } else if (stop - start == 1) {
// If we have narrowed things down to a single range object, we can
// return from the BPF filter program.
return start->node;
@@ -258,7 +273,7 @@
// We compare our system call number against the lowest valid system call
// number in this range object. If our number is lower, it is outside of
// this range object. If it is greater or equal, it might be inside.
- Ranges::const_iterator mid = start + n / 2;
+ Ranges::const_iterator mid = start + (stop - start) / 2;
// Sub-divide the list of ranges and continue recursively.
CodeGen::Node jf = AssembleJumpTable(start, mid);
@@ -278,30 +293,31 @@
case ErrorCode::ET_TRAP:
return gen_.MakeInstruction(BPF_RET + BPF_K, err.err());
default:
- LOG(FATAL)
- << "ErrorCode is not suitable for returning from a BPF program";
- return CodeGen::kNullNode;
+ SANDBOX_DIE("ErrorCode is not suitable for returning from a BPF program");
}
}
CodeGen::Node PolicyCompiler::CondExpression(const ErrorCode& cond) {
// Sanity check that |cond| makes sense.
- CHECK(cond.argno_ >= 0 && cond.argno_ < 6) << "Invalid argument number "
- << cond.argno_;
- CHECK(cond.width_ == ErrorCode::TP_32BIT ||
- cond.width_ == ErrorCode::TP_64BIT)
- << "Invalid argument width " << cond.width_;
- CHECK_NE(0U, cond.mask_) << "Zero mask is invalid";
- CHECK_EQ(cond.value_, cond.value_ & cond.mask_)
- << "Value contains masked out bits";
- if (sizeof(void*) == 4) {
- CHECK_EQ(ErrorCode::TP_32BIT, cond.width_)
- << "Invalid width on 32-bit platform";
- }
- if (cond.width_ == ErrorCode::TP_32BIT) {
- CHECK_EQ(0U, cond.mask_ >> 32) << "Mask exceeds argument size";
- CHECK_EQ(0U, cond.value_ >> 32) << "Value exceeds argument size";
- }
+ if (cond.argno_ < 0 || cond.argno_ >= 6) {
+ SANDBOX_DIE("sandbox_bpf: invalid argument number");
+ }
+ if (cond.width_ != ErrorCode::TP_32BIT &&
+ cond.width_ != ErrorCode::TP_64BIT) {
+ SANDBOX_DIE("sandbox_bpf: invalid argument width");
+ }
+ if (cond.mask_ == 0) {
+ SANDBOX_DIE("sandbox_bpf: zero mask is invalid");
+ }
+ if ((cond.value_ & cond.mask_) != cond.value_) {
+ SANDBOX_DIE("sandbox_bpf: value contains masked out bits");
+ }
+ if (cond.width_ == ErrorCode::TP_32BIT &&
+ ((cond.mask_ >> 32) != 0 || (cond.value_ >> 32) != 0)) {
+ SANDBOX_DIE("sandbox_bpf: test exceeds argument size");
+ }
+ // TODO(mdempsky): Reject TP_64BIT on 32-bit platforms. For now we allow it
+ // because some SandboxBPF unit tests exercise it.
CodeGen::Node passed = RetExpression(*cond.passed_);
CodeGen::Node failed = RetExpression(*cond.failed_);
« no previous file with comments | « no previous file | sandbox/linux/bpf_dsl/trap_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698