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/errorcode.h" | 5 #include "sandbox/linux/bpf_dsl/errorcode.h" |
6 | 6 |
7 #include "sandbox/linux/seccomp-bpf/die.h" | 7 #include "base/logging.h" |
8 #include "sandbox/linux/system_headers/linux_seccomp.h" | 8 #include "sandbox/linux/system_headers/linux_seccomp.h" |
9 | 9 |
10 namespace sandbox { | 10 namespace sandbox { |
| 11 namespace bpf_dsl { |
11 | 12 |
12 ErrorCode::ErrorCode() : error_type_(ET_INVALID), err_(SECCOMP_RET_INVALID) { | 13 ErrorCode::ErrorCode() : error_type_(ET_INVALID), err_(SECCOMP_RET_INVALID) {} |
13 } | |
14 | 14 |
15 ErrorCode::ErrorCode(int err) { | 15 ErrorCode::ErrorCode(int err) { |
16 switch (err) { | 16 switch (err) { |
17 case ERR_ALLOWED: | 17 case ERR_ALLOWED: |
18 err_ = SECCOMP_RET_ALLOW; | 18 err_ = SECCOMP_RET_ALLOW; |
19 error_type_ = ET_SIMPLE; | 19 error_type_ = ET_SIMPLE; |
20 break; | 20 break; |
| 21 case ERR_KILL: |
| 22 err_ = SECCOMP_RET_KILL; |
| 23 error_type_ = ET_SIMPLE; |
| 24 break; |
21 case ERR_MIN_ERRNO... ERR_MAX_ERRNO: | 25 case ERR_MIN_ERRNO... ERR_MAX_ERRNO: |
22 err_ = SECCOMP_RET_ERRNO + err; | 26 err_ = SECCOMP_RET_ERRNO + err; |
23 error_type_ = ET_SIMPLE; | 27 error_type_ = ET_SIMPLE; |
24 break; | 28 break; |
25 default: | 29 default: |
26 if ((err & ~SECCOMP_RET_DATA) == ERR_TRACE) { | 30 if ((err & ~SECCOMP_RET_DATA) == ERR_TRACE) { |
27 err_ = SECCOMP_RET_TRACE + (err & SECCOMP_RET_DATA); | 31 err_ = SECCOMP_RET_TRACE + (err & SECCOMP_RET_DATA); |
28 error_type_ = ET_SIMPLE; | 32 error_type_ = ET_SIMPLE; |
29 break; | 33 break; |
30 } | 34 } |
31 SANDBOX_DIE("Invalid use of ErrorCode object"); | 35 LOG(FATAL) << "Invalid use of ErrorCode object"; |
32 } | 36 } |
33 } | 37 } |
34 | 38 |
35 ErrorCode::ErrorCode(uint16_t trap_id, | 39 ErrorCode::ErrorCode(uint16_t trap_id, |
36 Trap::TrapFnc fnc, | 40 TrapRegistry::TrapFnc fnc, |
37 const void* aux, | 41 const void* aux, |
38 bool safe) | 42 bool safe) |
39 : error_type_(ET_TRAP), | 43 : error_type_(ET_TRAP), |
40 fnc_(fnc), | 44 fnc_(fnc), |
41 aux_(const_cast<void*>(aux)), | 45 aux_(const_cast<void*>(aux)), |
42 safe_(safe), | 46 safe_(safe), |
43 err_(SECCOMP_RET_TRAP + trap_id) { | 47 err_(SECCOMP_RET_TRAP + trap_id) {} |
44 } | |
45 | 48 |
46 ErrorCode::ErrorCode(int argno, | 49 ErrorCode::ErrorCode(int argno, |
47 ArgType width, | 50 ArgType width, |
48 uint64_t mask, | 51 uint64_t mask, |
49 uint64_t value, | 52 uint64_t value, |
50 const ErrorCode* passed, | 53 const ErrorCode* passed, |
51 const ErrorCode* failed) | 54 const ErrorCode* failed) |
52 : error_type_(ET_COND), | 55 : error_type_(ET_COND), |
53 mask_(mask), | 56 mask_(mask), |
54 value_(value), | 57 value_(value), |
55 argno_(argno), | 58 argno_(argno), |
56 width_(width), | 59 width_(width), |
57 passed_(passed), | 60 passed_(passed), |
58 failed_(failed), | 61 failed_(failed), |
59 err_(SECCOMP_RET_INVALID) { | 62 err_(SECCOMP_RET_INVALID) {} |
60 } | |
61 | 63 |
62 bool ErrorCode::Equals(const ErrorCode& err) const { | 64 bool ErrorCode::Equals(const ErrorCode& err) const { |
63 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { | 65 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { |
64 SANDBOX_DIE("Dereferencing invalid ErrorCode"); | 66 LOG(FATAL) << "Dereferencing invalid ErrorCode"; |
65 } | 67 } |
66 if (error_type_ != err.error_type_) { | 68 if (error_type_ != err.error_type_) { |
67 return false; | 69 return false; |
68 } | 70 } |
69 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { | 71 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { |
70 return err_ == err.err_; | 72 return err_ == err.err_; |
71 } else if (error_type_ == ET_COND) { | 73 } else if (error_type_ == ET_COND) { |
72 return mask_ == err.mask_ && value_ == err.value_ && argno_ == err.argno_ && | 74 return mask_ == err.mask_ && value_ == err.value_ && argno_ == err.argno_ && |
73 width_ == err.width_ && passed_->Equals(*err.passed_) && | 75 width_ == err.width_ && passed_->Equals(*err.passed_) && |
74 failed_->Equals(*err.failed_); | 76 failed_->Equals(*err.failed_); |
75 } else { | 77 } else { |
76 SANDBOX_DIE("Corrupted ErrorCode"); | 78 LOG(FATAL) << "Corrupted ErrorCode"; |
| 79 return false; |
77 } | 80 } |
78 } | 81 } |
79 | 82 |
80 bool ErrorCode::LessThan(const ErrorCode& err) const { | 83 bool ErrorCode::LessThan(const ErrorCode& err) const { |
81 // Implementing a "LessThan()" operator allows us to use ErrorCode objects | 84 // Implementing a "LessThan()" operator allows us to use ErrorCode objects |
82 // as keys in STL containers; most notably, it also allows us to put them | 85 // as keys in STL containers; most notably, it also allows us to put them |
83 // into std::set<>. Actual ordering is not important as long as it is | 86 // into std::set<>. Actual ordering is not important as long as it is |
84 // deterministic. | 87 // deterministic. |
85 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { | 88 if (error_type_ == ET_INVALID || err.error_type_ == ET_INVALID) { |
86 SANDBOX_DIE("Dereferencing invalid ErrorCode"); | 89 LOG(FATAL) << "Dereferencing invalid ErrorCode"; |
87 } | 90 } |
88 if (error_type_ != err.error_type_) { | 91 if (error_type_ != err.error_type_) { |
89 return error_type_ < err.error_type_; | 92 return error_type_ < err.error_type_; |
90 } else { | 93 } else { |
91 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { | 94 if (error_type_ == ET_SIMPLE || error_type_ == ET_TRAP) { |
92 return err_ < err.err_; | 95 return err_ < err.err_; |
93 } else if (error_type_ == ET_COND) { | 96 } else if (error_type_ == ET_COND) { |
94 if (mask_ != err.mask_) { | 97 if (mask_ != err.mask_) { |
95 return mask_ < err.mask_; | 98 return mask_ < err.mask_; |
96 } else if (value_ != err.value_) { | 99 } else if (value_ != err.value_) { |
97 return value_ < err.value_; | 100 return value_ < err.value_; |
98 } else if (argno_ != err.argno_) { | 101 } else if (argno_ != err.argno_) { |
99 return argno_ < err.argno_; | 102 return argno_ < err.argno_; |
100 } else if (width_ != err.width_) { | 103 } else if (width_ != err.width_) { |
101 return width_ < err.width_; | 104 return width_ < err.width_; |
102 } else if (!passed_->Equals(*err.passed_)) { | 105 } else if (!passed_->Equals(*err.passed_)) { |
103 return passed_->LessThan(*err.passed_); | 106 return passed_->LessThan(*err.passed_); |
104 } else if (!failed_->Equals(*err.failed_)) { | 107 } else if (!failed_->Equals(*err.failed_)) { |
105 return failed_->LessThan(*err.failed_); | 108 return failed_->LessThan(*err.failed_); |
106 } else { | 109 } else { |
107 return false; | 110 return false; |
108 } | 111 } |
109 } else { | 112 } else { |
110 SANDBOX_DIE("Corrupted ErrorCode"); | 113 LOG(FATAL) << "Corrupted ErrorCode"; |
| 114 return false; |
111 } | 115 } |
112 } | 116 } |
113 } | 117 } |
114 | 118 |
| 119 } // namespace bpf_dsl |
115 } // namespace sandbox | 120 } // namespace sandbox |
OLD | NEW |