Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | |
| 6 | |
| 7 | |
| 8 namespace playground2 { | |
| 9 | |
| 10 ErrorCode::ErrorCode(int err) { | |
| 11 switch (err) { | |
| 12 case ERR_INVALID: | |
| 13 // We allow the default constructor, as it makes the ErrorCode class | |
| 14 // much easier to use. But if we ever encounter an invalid ErrorCode | |
| 15 // when compiling a BPF filter, we deliberately generate an invalid | |
| 16 // program that will get flagged both by our Verifier class and by | |
| 17 // the Linux kernel. | |
| 18 err_ = SECCOMP_RET_INVALID; | |
| 19 errorType_ = ET_INVALID; | |
| 20 break; | |
| 21 case ERR_ALLOWED: | |
| 22 err_ = SECCOMP_RET_ALLOW; | |
| 23 errorType_ = ET_SIMPLE; | |
| 24 break; | |
| 25 case ERR_MIN_ERRNO ... ERR_MAX_ERRNO: | |
| 26 err_ = SECCOMP_RET_ERRNO + err; | |
| 27 errorType_ = ET_SIMPLE; | |
| 28 break; | |
| 29 default: | |
| 30 die("Invalid use of ErrorCode object"); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 ErrorCode::ErrorCode(ErrorCode::TrapFnc fnc, const void *aux, uint16_t id) : | |
| 35 errorType_(ET_TRAP), | |
|
jln (very slow on Chromium)
2012/07/27 19:46:30
Initializer lists should be indented 4 spaces, the
| |
| 36 fnc_(fnc), | |
| 37 aux_(const_cast<void *>(aux)), | |
| 38 err_(SECCOMP_RET_TRAP + id) { | |
| 39 } | |
| 40 | |
| 41 ErrorCode::ErrorCode(int argno, ArgType width, Operation op, uint64_t value, | |
| 42 const ErrorCode *passed, const ErrorCode *failed) : | |
| 43 errorType_(ET_COND), | |
|
jln (very slow on Chromium)
2012/07/27 19:46:30
Same here.
| |
| 44 value_(value), | |
| 45 argno_(argno), | |
| 46 width_(width), | |
| 47 op_(op), | |
| 48 passed_(passed), | |
| 49 failed_(failed), | |
| 50 err_(SECCOMP_RET_INVALID) { | |
| 51 if (op < 0 || op >= OP_NUM_OPS) { | |
| 52 die("Invalid opcode in BPF sandbox rules"); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 bool ErrorCode::isEqual(const ErrorCode &err) const { | |
| 57 if (errorType_ == ET_INVALID || err.errorType_ == ET_INVALID) { | |
| 58 die("Dereferencing invalid ErrorCode"); | |
| 59 } | |
| 60 if (errorType_ != err.errorType_) { | |
| 61 return false; | |
| 62 } | |
| 63 if (errorType_ == ET_SIMPLE || errorType_ == ET_TRAP) { | |
| 64 return err_ == err.err_; | |
| 65 } else if (errorType_ == ET_COND) { | |
| 66 return value_ == err.value_ && | |
| 67 argno_ == err.argno_ && | |
| 68 width_ == err.width_ && | |
| 69 op_ == err.op_ && | |
| 70 passed_->isEqual(*err.passed_) && | |
| 71 failed_->isEqual(*err.failed_); | |
| 72 } else { | |
| 73 die("Corrupted ErrorCode"); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 bool ErrorCode::lessThan(const ErrorCode& err) const { | |
|
jln (very slow on Chromium)
2012/07/27 19:46:30
This is quit "artificial". Do you mind adding a co
| |
| 78 if (errorType_ == ET_INVALID || err.errorType_ == ET_INVALID) { | |
| 79 die("Dereferencing invalid ErrorCode"); | |
| 80 } | |
| 81 if (errorType_ != err.errorType_) { | |
| 82 return errorType_ < err.errorType_; | |
| 83 } else { | |
| 84 if (errorType_ == ET_SIMPLE || errorType_ == ET_TRAP) { | |
| 85 return err_ < err.err_; | |
| 86 } else if (errorType_ == ET_COND) { | |
| 87 if (value_ != err.value_) { | |
| 88 return value_ < err.value_; | |
| 89 } else if (argno_ != err.argno_) { | |
| 90 return argno_ < err.argno_; | |
| 91 } else if (width_ != err.width_) { | |
| 92 return width_ < err.width_; | |
| 93 } else if (op_ != err.op_) { | |
| 94 return op_ < err.op_; | |
| 95 } else if (!passed_->isEqual(*err.passed_)) { | |
| 96 return passed_->lessThan(*err.passed_); | |
|
jln (very slow on Chromium)
2012/07/27 19:46:30
Do you want to add a CHECK here, to check that &er
| |
| 97 } else if (!failed_->isEqual(*err.failed_)) { | |
| 98 return failed_->lessThan(*err.failed_); | |
| 99 } else { | |
| 100 return false; | |
| 101 } | |
| 102 } else { | |
| 103 die("Corrupted ErrorCode"); | |
| 104 } | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 void ErrorCode::die(const char *msg) { | |
| 109 Sandbox::die(msg); | |
| 110 } | |
| 111 | |
| 112 } // namespace | |
| OLD | NEW |