Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: sandbox/linux/bpf_dsl/policy_compiler.h

Issue 1302043002: sandbox/linux: refactor bpf_dsl dependency on die.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change default panic behavior to simply Kill Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/linux/bpf_dsl/bpf_dsl_unittest.cc ('k') | sandbox/linux/bpf_dsl/policy_compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bpf_dsl/trap_registry.h"
18 #include "sandbox/linux/seccomp-bpf/errorcode.h" 19 #include "sandbox/linux/seccomp-bpf/errorcode.h"
19 #include "sandbox/sandbox_export.h" 20 #include "sandbox/sandbox_export.h"
20 21
21 namespace sandbox { 22 namespace sandbox {
22 namespace bpf_dsl { 23 namespace bpf_dsl {
23 class Policy; 24 class Policy;
24 25
25 // PolicyCompiler implements the bpf_dsl compiler, allowing users to 26 // PolicyCompiler implements the bpf_dsl compiler, allowing users to
26 // transform bpf_dsl policies into BPF programs to be executed by the 27 // transform bpf_dsl policies into BPF programs to be executed by the
27 // Linux kernel. 28 // Linux kernel.
28 class SANDBOX_EXPORT PolicyCompiler { 29 class SANDBOX_EXPORT PolicyCompiler {
29 public: 30 public:
31 using PanicFunc = bpf_dsl::ResultExpr (*)(const char* error);
32
30 PolicyCompiler(const Policy* policy, TrapRegistry* registry); 33 PolicyCompiler(const Policy* policy, TrapRegistry* registry);
31 ~PolicyCompiler(); 34 ~PolicyCompiler();
32 35
33 // Compile registers any trap handlers needed by the policy and 36 // Compile registers any trap handlers needed by the policy and
34 // compiles the policy to a BPF program, which it returns. 37 // compiles the policy to a BPF program, which it returns.
35 scoped_ptr<CodeGen::Program> Compile(bool verify); 38 scoped_ptr<CodeGen::Program> Compile(bool verify);
36 39
37 // DangerousSetEscapePC sets the "escape PC" that is allowed to issue any 40 // DangerousSetEscapePC sets the "escape PC" that is allowed to issue any
38 // system calls, regardless of policy. 41 // system calls, regardless of policy.
39 void DangerousSetEscapePC(uint64_t escapepc); 42 void DangerousSetEscapePC(uint64_t escapepc);
40 43
44 // SetPanicFunc sets the callback function used for handling faulty
45 // system call conditions. The default behavior is to immediately kill
46 // the process.
47 // TODO(mdempsky): Move this into Policy?
48 void SetPanicFunc(PanicFunc panic_func);
49
41 // Error returns an ErrorCode to indicate the system call should fail with 50 // Error returns an ErrorCode to indicate the system call should fail with
42 // the specified error number. 51 // the specified error number.
43 ErrorCode Error(int err); 52 ErrorCode Error(int err);
44 53
45 // Trap returns an ErrorCode to indicate the system call should 54 // Trap returns an ErrorCode to indicate the system call should
46 // instead invoke a trap handler. 55 // instead invoke a trap handler.
47 ErrorCode Trap(TrapRegistry::TrapFnc fnc, const void* aux, bool safe); 56 ErrorCode Trap(TrapRegistry::TrapFnc fnc, const void* aux, bool safe);
48 57
49 // UnsafeTraps require some syscalls to always be allowed. 58 // UnsafeTraps require some syscalls to always be allowed.
50 // This helper function returns true for these calls. 59 // This helper function returns true for these calls.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // Returns a BPF program that evaluates half of a conditional expression; 147 // Returns a BPF program that evaluates half of a conditional expression;
139 // it should only ever be called from CondExpression(). 148 // it should only ever be called from CondExpression().
140 CodeGen::Node CondExpressionHalf(const ErrorCode& cond, 149 CodeGen::Node CondExpressionHalf(const ErrorCode& cond,
141 ArgHalf half, 150 ArgHalf half,
142 CodeGen::Node passed, 151 CodeGen::Node passed,
143 CodeGen::Node failed); 152 CodeGen::Node failed);
144 153
145 const Policy* policy_; 154 const Policy* policy_;
146 TrapRegistry* registry_; 155 TrapRegistry* registry_;
147 uint64_t escapepc_; 156 uint64_t escapepc_;
157 PanicFunc panic_func_;
148 158
149 Conds conds_; 159 Conds conds_;
150 CodeGen gen_; 160 CodeGen gen_;
151 bool has_unsafe_traps_; 161 bool has_unsafe_traps_;
152 162
153 DISALLOW_COPY_AND_ASSIGN(PolicyCompiler); 163 DISALLOW_COPY_AND_ASSIGN(PolicyCompiler);
154 }; 164 };
155 165
156 } // namespace bpf_dsl 166 } // namespace bpf_dsl
157 } // namespace sandbox 167 } // namespace sandbox
158 168
159 #endif // SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_ 169 #endif // SANDBOX_LINUX_BPF_DSL_POLICY_COMPILER_H_
OLDNEW
« no previous file with comments | « sandbox/linux/bpf_dsl/bpf_dsl_unittest.cc ('k') | sandbox/linux/bpf_dsl/policy_compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698