| 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 #ifndef SANDBOX_LINUX_SECCOMP_BPF_ERRORCODE_H__ | 5 #ifndef SANDBOX_LINUX_BPF_DSL_ERRORCODE_H__ |
| 6 #define SANDBOX_LINUX_SECCOMP_BPF_ERRORCODE_H__ | 6 #define SANDBOX_LINUX_BPF_DSL_ERRORCODE_H__ |
| 7 | 7 |
| 8 #include "sandbox/linux/seccomp-bpf/trap.h" | 8 #include "sandbox/linux/bpf_dsl/trap_registry.h" |
| 9 #include "sandbox/sandbox_export.h" | 9 #include "sandbox/sandbox_export.h" |
| 10 | 10 |
| 11 namespace sandbox { | 11 namespace sandbox { |
| 12 namespace bpf_dsl { | 12 namespace bpf_dsl { |
| 13 class PolicyCompiler; | |
| 14 } | |
| 15 | 13 |
| 16 // This class holds all the possible values that can be returned by a sandbox | 14 // This class holds all the possible values that can be returned by a sandbox |
| 17 // policy. | 15 // policy. |
| 18 // We can either wrap a symbolic ErrorCode (i.e. ERR_XXX enum values), an | 16 // We can either wrap a symbolic ErrorCode (i.e. ERR_XXX enum values), an |
| 19 // errno value (in the range 0..4095), a pointer to a TrapFnc callback | 17 // errno value (in the range 0..4095), a pointer to a TrapFnc callback |
| 20 // handling a SECCOMP_RET_TRAP trap, or a complex constraint. | 18 // handling a SECCOMP_RET_TRAP trap, or a complex constraint. |
| 21 // All of the commonly used values are stored in the "err_" field. So, code | 19 // All of the commonly used values are stored in the "err_" field. So, code |
| 22 // that is using the ErrorCode class typically operates on a single 32bit | 20 // that is using the ErrorCode class typically operates on a single 32bit |
| 23 // field. | 21 // field. |
| 24 // | 22 // |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 const ErrorCode* passed() const { return passed_; } | 146 const ErrorCode* passed() const { return passed_; } |
| 149 const ErrorCode* failed() const { return failed_; } | 147 const ErrorCode* failed() const { return failed_; } |
| 150 | 148 |
| 151 struct LessThan { | 149 struct LessThan { |
| 152 bool operator()(const ErrorCode& a, const ErrorCode& b) const { | 150 bool operator()(const ErrorCode& a, const ErrorCode& b) const { |
| 153 return a.LessThan(b); | 151 return a.LessThan(b); |
| 154 } | 152 } |
| 155 }; | 153 }; |
| 156 | 154 |
| 157 private: | 155 private: |
| 158 friend bpf_dsl::PolicyCompiler; | 156 friend class PolicyCompiler; |
| 159 friend class CodeGen; | |
| 160 friend class SandboxBPF; | |
| 161 friend class Trap; | |
| 162 | 157 |
| 163 // If we are wrapping a callback, we must assign a unique id. This id is | 158 // If we are wrapping a callback, we must assign a unique id. This id is |
| 164 // how the kernel tells us which one of our different SECCOMP_RET_TRAP | 159 // how the kernel tells us which one of our different SECCOMP_RET_TRAP |
| 165 // cases has been triggered. | 160 // cases has been triggered. |
| 166 ErrorCode(uint16_t trap_id, Trap::TrapFnc fnc, const void* aux, bool safe); | 161 ErrorCode(uint16_t trap_id, |
| 162 TrapRegistry::TrapFnc fnc, |
| 163 const void* aux, |
| 164 bool safe); |
| 167 | 165 |
| 168 // Some system calls require inspection of arguments. This constructor | 166 // Some system calls require inspection of arguments. This constructor |
| 169 // allows us to specify additional constraints. | 167 // allows us to specify additional constraints. |
| 170 ErrorCode(int argno, | 168 ErrorCode(int argno, |
| 171 ArgType width, | 169 ArgType width, |
| 172 uint64_t mask, | 170 uint64_t mask, |
| 173 uint64_t value, | 171 uint64_t value, |
| 174 const ErrorCode* passed, | 172 const ErrorCode* passed, |
| 175 const ErrorCode* failed); | 173 const ErrorCode* failed); |
| 176 | 174 |
| 177 ErrorType error_type_; | 175 ErrorType error_type_; |
| 178 | 176 |
| 179 union { | 177 union { |
| 180 // Fields needed for SECCOMP_RET_TRAP callbacks | 178 // Fields needed for SECCOMP_RET_TRAP callbacks |
| 181 struct { | 179 struct { |
| 182 Trap::TrapFnc fnc_; // Callback function and arg, if trap was | 180 TrapRegistry::TrapFnc fnc_; // Callback function and arg, if trap was |
| 183 void* aux_; // triggered by the kernel's BPF filter. | 181 void* aux_; // triggered by the kernel's BPF filter. |
| 184 bool safe_; // Keep sandbox active while calling fnc_() | 182 bool safe_; // Keep sandbox active while calling fnc_() |
| 185 }; | 183 }; |
| 186 | 184 |
| 187 // Fields needed when inspecting additional arguments. | 185 // Fields needed when inspecting additional arguments. |
| 188 struct { | 186 struct { |
| 189 uint64_t mask_; // Mask that we are comparing under. | 187 uint64_t mask_; // Mask that we are comparing under. |
| 190 uint64_t value_; // Value that we are comparing with. | 188 uint64_t value_; // Value that we are comparing with. |
| 191 int argno_; // Syscall arg number that we are inspecting. | 189 int argno_; // Syscall arg number that we are inspecting. |
| 192 ArgType width_; // Whether we are looking at a 32/64bit value. | 190 ArgType width_; // Whether we are looking at a 32/64bit value. |
| 193 const ErrorCode* passed_; // Value to be returned if comparison passed, | 191 const ErrorCode* passed_; // Value to be returned if comparison passed, |
| 194 const ErrorCode* failed_; // or if it failed. | 192 const ErrorCode* failed_; // or if it failed. |
| 195 }; | 193 }; |
| 196 }; | 194 }; |
| 197 | 195 |
| 198 // 32bit field used for all possible types of ErrorCode values. This is | 196 // 32bit field used for all possible types of ErrorCode values. This is |
| 199 // the value that uniquely identifies any ErrorCode and it (typically) can | 197 // the value that uniquely identifies any ErrorCode and it (typically) can |
| 200 // be emitted directly into a BPF filter program. | 198 // be emitted directly into a BPF filter program. |
| 201 uint32_t err_; | 199 uint32_t err_; |
| 202 }; | 200 }; |
| 203 | 201 |
| 202 } // namespace bpf_dsl |
| 204 } // namespace sandbox | 203 } // namespace sandbox |
| 205 | 204 |
| 206 #endif // SANDBOX_LINUX_SECCOMP_BPF_ERRORCODE_H__ | 205 #endif // SANDBOX_LINUX_BPF_DSL_ERRORCODE_H__ |
| OLD | NEW |