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> |
11 #include <set> | 11 #include <set> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "sandbox/linux/bpf_dsl/bpf_dsl_forward.h" | 16 #include "sandbox/linux/bpf_dsl/bpf_dsl_forward.h" |
17 #include "sandbox/linux/bpf_dsl/codegen.h" | 17 #include "sandbox/linux/bpf_dsl/codegen.h" |
18 #include "sandbox/linux/seccomp-bpf/errorcode.h" | 18 #include "sandbox/linux/seccomp-bpf/errorcode.h" |
19 #include "sandbox/sandbox_export.h" | 19 #include "sandbox/sandbox_export.h" |
20 | 20 |
21 namespace sandbox { | 21 namespace sandbox { |
22 namespace bpf_dsl { | 22 namespace bpf_dsl { |
23 class Policy; | 23 class Policy; |
24 | 24 |
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, |
31 TrapRegistry* registry, | |
32 uint64_t escapepc = 0); | |
jln (very slow on Chromium)
2015/02/19 19:49:14
I'm worried about making it too easy to inject a b
mdempsky
2015/02/20 03:20:32
FWIW, this just lets the "user" control what PC is
| |
31 ~PolicyCompiler(); | 33 ~PolicyCompiler(); |
32 | 34 |
33 // Compile registers any trap handlers needed by the policy and | 35 // Compile registers any trap handlers needed by the policy and |
34 // compiles the policy to a BPF program, which it returns. | 36 // compiles the policy to a BPF program, which it returns. |
35 scoped_ptr<CodeGen::Program> Compile(); | 37 scoped_ptr<CodeGen::Program> Compile(); |
36 | 38 |
37 // Error returns an ErrorCode to indicate the system call should fail with | 39 // Error returns an ErrorCode to indicate the system call should fail with |
38 // the specified error number. | 40 // the specified error number. |
39 ErrorCode Error(int err); | 41 ErrorCode Error(int err); |
40 | 42 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 | 83 |
82 // Compile the configured policy into a complete instruction sequence. | 84 // Compile the configured policy into a complete instruction sequence. |
83 CodeGen::Node AssemblePolicy(); | 85 CodeGen::Node AssemblePolicy(); |
84 | 86 |
85 // Return an instruction sequence that checks the | 87 // Return an instruction sequence that checks the |
86 // arch_seccomp_data's "arch" field is valid, and then passes | 88 // arch_seccomp_data's "arch" field is valid, and then passes |
87 // control to |passed| if so. | 89 // control to |passed| if so. |
88 CodeGen::Node CheckArch(CodeGen::Node passed); | 90 CodeGen::Node CheckArch(CodeGen::Node passed); |
89 | 91 |
90 // If |has_unsafe_traps_| is true, returns an instruction sequence | 92 // If |has_unsafe_traps_| is true, returns an instruction sequence |
91 // that allows all system calls from Syscall::Call(), and otherwise | 93 // that allows all system calls from |escapepc_|, and otherwise |
92 // passes control to |rest|. Otherwise, simply returns |rest|. | 94 // passes control to |rest|. Otherwise, simply returns |rest|. |
93 CodeGen::Node MaybeAddEscapeHatch(CodeGen::Node rest); | 95 CodeGen::Node MaybeAddEscapeHatch(CodeGen::Node rest); |
94 | 96 |
95 // Return an instruction sequence that loads and checks the system | 97 // Return an instruction sequence that loads and checks the system |
96 // call number, performs a binary search, and then dispatches to an | 98 // call number, performs a binary search, and then dispatches to an |
97 // appropriate instruction sequence compiled from the current | 99 // appropriate instruction sequence compiled from the current |
98 // policy. | 100 // policy. |
99 CodeGen::Node DispatchSyscall(); | 101 CodeGen::Node DispatchSyscall(); |
100 | 102 |
101 // Return an instruction sequence that checks the system call number | 103 // Return an instruction sequence that checks the system call number |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 | 135 |
134 // Returns a BPF program that evaluates half of a conditional expression; | 136 // Returns a BPF program that evaluates half of a conditional expression; |
135 // it should only ever be called from CondExpression(). | 137 // it should only ever be called from CondExpression(). |
136 CodeGen::Node CondExpressionHalf(const ErrorCode& cond, | 138 CodeGen::Node CondExpressionHalf(const ErrorCode& cond, |
137 ArgHalf half, | 139 ArgHalf half, |
138 CodeGen::Node passed, | 140 CodeGen::Node passed, |
139 CodeGen::Node failed); | 141 CodeGen::Node failed); |
140 | 142 |
141 const Policy* policy_; | 143 const Policy* policy_; |
142 TrapRegistry* registry_; | 144 TrapRegistry* registry_; |
145 uint64_t escapepc_; | |
143 | 146 |
144 Conds conds_; | 147 Conds conds_; |
145 CodeGen gen_; | 148 CodeGen gen_; |
146 bool has_unsafe_traps_; | 149 bool has_unsafe_traps_; |
147 | 150 |
148 DISALLOW_COPY_AND_ASSIGN(PolicyCompiler); | 151 DISALLOW_COPY_AND_ASSIGN(PolicyCompiler); |
149 }; | 152 }; |
150 | 153 |
151 } // namespace bpf_dsl | 154 } // namespace bpf_dsl |
152 } // namespace sandbox | 155 } // namespace sandbox |
153 | 156 |
154 #endif // SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ | 157 #endif // SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ |
OLD | NEW |