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_BPF_DSL_POLICY_COMPILER_H_ | 5 #ifndef SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ |
6 #define SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ | 6 #define SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 14 matching lines...) Expand all Loading... |
25 // PolicyCompiler implements the bpf_dsl compiler, allowing users to | 25 // PolicyCompiler implements the bpf_dsl compiler, allowing users to |
26 // transform bpf_dsl policies into BPF programs to be executed by the | 26 // transform bpf_dsl policies into BPF programs to be executed by the |
27 // Linux kernel. | 27 // Linux kernel. |
28 class SANDBOX_EXPORT PolicyCompiler { | 28 class SANDBOX_EXPORT PolicyCompiler { |
29 public: | 29 public: |
30 PolicyCompiler(const Policy* policy, TrapRegistry* registry); | 30 PolicyCompiler(const Policy* policy, TrapRegistry* registry); |
31 ~PolicyCompiler(); | 31 ~PolicyCompiler(); |
32 | 32 |
33 // Compile registers any trap handlers needed by the policy and | 33 // Compile registers any trap handlers needed by the policy and |
34 // compiles the policy to a BPF program, which it returns. | 34 // compiles the policy to a BPF program, which it returns. |
35 scoped_ptr<CodeGen::Program> Compile(); | 35 scoped_ptr<CodeGen::Program> Compile(bool verify); |
| 36 |
| 37 // DangerousSetEscapePC sets the "escape PC" that is allowed to issue any |
| 38 // system calls, regardless of policy. |
| 39 void DangerousSetEscapePC(uint64_t escapepc); |
36 | 40 |
37 // Error returns an ErrorCode to indicate the system call should fail with | 41 // Error returns an ErrorCode to indicate the system call should fail with |
38 // the specified error number. | 42 // the specified error number. |
39 ErrorCode Error(int err); | 43 ErrorCode Error(int err); |
40 | 44 |
41 // Trap returns an ErrorCode to indicate the system call should | 45 // Trap returns an ErrorCode to indicate the system call should |
42 // instead invoke a trap handler. | 46 // instead invoke a trap handler. |
43 ErrorCode Trap(TrapRegistry::TrapFnc fnc, const void* aux, bool safe); | 47 ErrorCode Trap(TrapRegistry::TrapFnc fnc, const void* aux, bool safe); |
44 | 48 |
45 // UnsafeTraps require some syscalls to always be allowed. | 49 // UnsafeTraps require some syscalls to always be allowed. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 85 |
82 // Compile the configured policy into a complete instruction sequence. | 86 // Compile the configured policy into a complete instruction sequence. |
83 CodeGen::Node AssemblePolicy(); | 87 CodeGen::Node AssemblePolicy(); |
84 | 88 |
85 // Return an instruction sequence that checks the | 89 // Return an instruction sequence that checks the |
86 // arch_seccomp_data's "arch" field is valid, and then passes | 90 // arch_seccomp_data's "arch" field is valid, and then passes |
87 // control to |passed| if so. | 91 // control to |passed| if so. |
88 CodeGen::Node CheckArch(CodeGen::Node passed); | 92 CodeGen::Node CheckArch(CodeGen::Node passed); |
89 | 93 |
90 // If |has_unsafe_traps_| is true, returns an instruction sequence | 94 // If |has_unsafe_traps_| is true, returns an instruction sequence |
91 // that allows all system calls from Syscall::Call(), and otherwise | 95 // that allows all system calls from |escapepc_|, and otherwise |
92 // passes control to |rest|. Otherwise, simply returns |rest|. | 96 // passes control to |rest|. Otherwise, simply returns |rest|. |
93 CodeGen::Node MaybeAddEscapeHatch(CodeGen::Node rest); | 97 CodeGen::Node MaybeAddEscapeHatch(CodeGen::Node rest); |
94 | 98 |
95 // Return an instruction sequence that loads and checks the system | 99 // Return an instruction sequence that loads and checks the system |
96 // call number, performs a binary search, and then dispatches to an | 100 // call number, performs a binary search, and then dispatches to an |
97 // appropriate instruction sequence compiled from the current | 101 // appropriate instruction sequence compiled from the current |
98 // policy. | 102 // policy. |
99 CodeGen::Node DispatchSyscall(); | 103 CodeGen::Node DispatchSyscall(); |
100 | 104 |
101 // Return an instruction sequence that checks the system call number | 105 // Return an instruction sequence that checks the system call number |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 137 |
134 // Returns a BPF program that evaluates half of a conditional expression; | 138 // Returns a BPF program that evaluates half of a conditional expression; |
135 // it should only ever be called from CondExpression(). | 139 // it should only ever be called from CondExpression(). |
136 CodeGen::Node CondExpressionHalf(const ErrorCode& cond, | 140 CodeGen::Node CondExpressionHalf(const ErrorCode& cond, |
137 ArgHalf half, | 141 ArgHalf half, |
138 CodeGen::Node passed, | 142 CodeGen::Node passed, |
139 CodeGen::Node failed); | 143 CodeGen::Node failed); |
140 | 144 |
141 const Policy* policy_; | 145 const Policy* policy_; |
142 TrapRegistry* registry_; | 146 TrapRegistry* registry_; |
| 147 uint64_t escapepc_; |
143 | 148 |
144 Conds conds_; | 149 Conds conds_; |
145 CodeGen gen_; | 150 CodeGen gen_; |
146 bool has_unsafe_traps_; | 151 bool has_unsafe_traps_; |
147 | 152 |
148 DISALLOW_COPY_AND_ASSIGN(PolicyCompiler); | 153 DISALLOW_COPY_AND_ASSIGN(PolicyCompiler); |
149 }; | 154 }; |
150 | 155 |
151 } // namespace bpf_dsl | 156 } // namespace bpf_dsl |
152 } // namespace sandbox | 157 } // namespace sandbox |
153 | 158 |
154 #endif // SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ | 159 #endif // SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ |
OLD | NEW |