| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/die.h" | 5 #include "sandbox/linux/seccomp-bpf/die.h" |
| 6 #include "sandbox/linux/seccomp-bpf/errorcode.h" | 6 #include "sandbox/linux/seccomp-bpf/errorcode.h" |
| 7 | 7 |
| 8 namespace sandbox { | 8 namespace sandbox { |
| 9 | 9 |
| 10 ErrorCode::ErrorCode(int err) { | 10 ErrorCode::ErrorCode(int err) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 ErrorCode::ErrorCode(Trap::TrapFnc fnc, const void* aux, bool safe, uint16_t id) | 30 ErrorCode::ErrorCode(Trap::TrapFnc fnc, const void* aux, bool safe, uint16_t id) |
| 31 : error_type_(ET_TRAP), | 31 : error_type_(ET_TRAP), |
| 32 fnc_(fnc), | 32 fnc_(fnc), |
| 33 aux_(const_cast<void*>(aux)), | 33 aux_(const_cast<void*>(aux)), |
| 34 safe_(safe), | 34 safe_(safe), |
| 35 err_(SECCOMP_RET_TRAP + id) {} | 35 err_(SECCOMP_RET_TRAP + id) {} |
| 36 | 36 |
| 37 ErrorCode::ErrorCode(int argno, | 37 ErrorCode::ErrorCode(int argno, |
| 38 ArgType width, | 38 ArgType width, |
| 39 Operation op, | 39 uint64_t mask, |
| 40 uint64_t value, | 40 uint64_t value, |
| 41 const ErrorCode* passed, | 41 const ErrorCode* passed, |
| 42 const ErrorCode* failed) | 42 const ErrorCode* failed) |
| 43 : error_type_(ET_COND), | 43 : error_type_(ET_COND), |
| 44 mask_(mask), |
| 44 value_(value), | 45 value_(value), |
| 45 argno_(argno), | 46 argno_(argno), |
| 46 width_(width), | 47 width_(width), |
| 47 op_(op), | |
| 48 passed_(passed), | 48 passed_(passed), |
| 49 failed_(failed), | 49 failed_(failed), |
| 50 err_(SECCOMP_RET_INVALID) { | 50 err_(SECCOMP_RET_INVALID) { |
| 51 if (op < 0 || op >= OP_NUM_OPS) { | |
| 52 SANDBOX_DIE("Invalid opcode in BPF sandbox rules"); | |
| 53 } | |
| 54 } | 51 } |
| 55 | 52 |
| 56 bool ErrorCode::Equals(const ErrorCode& err) const { | 53 bool ErrorCode::Equals(const ErrorCode& err) const { |
| 57 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { | 54 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { |
| 58 SANDBOX_DIE("Dereferencing invalid ErrorCode"); | 55 SANDBOX_DIE("Dereferencing invalid ErrorCode"); |
| 59 } | 56 } |
| 60 if (error_type_ != err.error_type_) { | 57 if (error_type_ != err.error_type_) { |
| 61 return false; | 58 return false; |
| 62 } | 59 } |
| 63 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { | 60 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { |
| 64 return err_ == err.err_; | 61 return err_ == err.err_; |
| 65 } else if (error_type_ == ET_COND) { | 62 } else if (error_type_ == ET_COND) { |
| 66 return value_ == err.value_ && argno_ == err.argno_ && | 63 return mask_ == err.mask_ && value_ == err.value_ && argno_ == err.argno_ && |
| 67 width_ == err.width_ && op_ == err.op_ && | 64 width_ == err.width_ && passed_->Equals(*err.passed_) && |
| 68 passed_->Equals(*err.passed_) && failed_->Equals(*err.failed_); | 65 failed_->Equals(*err.failed_); |
| 69 } else { | 66 } else { |
| 70 SANDBOX_DIE("Corrupted ErrorCode"); | 67 SANDBOX_DIE("Corrupted ErrorCode"); |
| 71 } | 68 } |
| 72 } | 69 } |
| 73 | 70 |
| 74 bool ErrorCode::LessThan(const ErrorCode& err) const { | 71 bool ErrorCode::LessThan(const ErrorCode& err) const { |
| 75 // Implementing a "LessThan()" operator allows us to use ErrorCode objects | 72 // Implementing a "LessThan()" operator allows us to use ErrorCode objects |
| 76 // as keys in STL containers; most notably, it also allows us to put them | 73 // as keys in STL containers; most notably, it also allows us to put them |
| 77 // into std::set<>. Actual ordering is not important as long as it is | 74 // into std::set<>. Actual ordering is not important as long as it is |
| 78 // deterministic. | 75 // deterministic. |
| 79 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { | 76 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { |
| 80 SANDBOX_DIE("Dereferencing invalid ErrorCode"); | 77 SANDBOX_DIE("Dereferencing invalid ErrorCode"); |
| 81 } | 78 } |
| 82 if (error_type_ != err.error_type_) { | 79 if (error_type_ != err.error_type_) { |
| 83 return error_type_ < err.error_type_; | 80 return error_type_ < err.error_type_; |
| 84 } else { | 81 } else { |
| 85 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { | 82 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { |
| 86 return err_ < err.err_; | 83 return err_ < err.err_; |
| 87 } else if (error_type_ == ET_COND) { | 84 } else if (error_type_ == ET_COND) { |
| 88 if (value_ != err.value_) { | 85 if (mask_ != err.mask_) { |
| 86 return mask_ < err.mask_; |
| 87 } else if (value_ != err.value_) { |
| 89 return value_ < err.value_; | 88 return value_ < err.value_; |
| 90 } else if (argno_ != err.argno_) { | 89 } else if (argno_ != err.argno_) { |
| 91 return argno_ < err.argno_; | 90 return argno_ < err.argno_; |
| 92 } else if (width_ != err.width_) { | 91 } else if (width_ != err.width_) { |
| 93 return width_ < err.width_; | 92 return width_ < err.width_; |
| 94 } else if (op_ != err.op_) { | |
| 95 return op_ < err.op_; | |
| 96 } else if (!passed_->Equals(*err.passed_)) { | 93 } else if (!passed_->Equals(*err.passed_)) { |
| 97 return passed_->LessThan(*err.passed_); | 94 return passed_->LessThan(*err.passed_); |
| 98 } else if (!failed_->Equals(*err.failed_)) { | 95 } else if (!failed_->Equals(*err.failed_)) { |
| 99 return failed_->LessThan(*err.failed_); | 96 return failed_->LessThan(*err.failed_); |
| 100 } else { | 97 } else { |
| 101 return false; | 98 return false; |
| 102 } | 99 } |
| 103 } else { | 100 } else { |
| 104 SANDBOX_DIE("Corrupted ErrorCode"); | 101 SANDBOX_DIE("Corrupted ErrorCode"); |
| 105 } | 102 } |
| 106 } | 103 } |
| 107 } | 104 } |
| 108 | 105 |
| 109 } // namespace sandbox | 106 } // namespace sandbox |
| OLD | NEW |