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

Side by Side Diff: sandbox/linux/seccomp-bpf/sandbox_bpf.h

Issue 290223002: Remove SandboxBPF's dependency on CompatibilityPolicy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Two more missing default constructors Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « sandbox/linux/seccomp-bpf/demo.cc ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.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_SECCOMP_BPF_SANDBOX_BPF_H__ 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__
6 #define SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__ 6 #define SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/wait.h> 10 #include <sys/wait.h>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // StartSandbox(), the program should indicate whether or not the sandbox 58 // StartSandbox(), the program should indicate whether or not the sandbox
59 // should try and engage with multi-thread support. 59 // should try and engage with multi-thread support.
60 enum SandboxThreadState { 60 enum SandboxThreadState {
61 PROCESS_INVALID, 61 PROCESS_INVALID,
62 PROCESS_SINGLE_THREADED, // The program is currently single-threaded. 62 PROCESS_SINGLE_THREADED, // The program is currently single-threaded.
63 // Note: PROCESS_MULTI_THREADED requires experimental kernel support that 63 // Note: PROCESS_MULTI_THREADED requires experimental kernel support that
64 // has not been contributed to upstream Linux. 64 // has not been contributed to upstream Linux.
65 PROCESS_MULTI_THREADED, // The program may be multi-threaded. 65 PROCESS_MULTI_THREADED, // The program may be multi-threaded.
66 }; 66 };
67 67
68 // When calling setSandboxPolicy(), the caller can provide an arbitrary
69 // pointer in |aux|. This pointer will then be forwarded to the sandbox
70 // policy each time a call is made through an EvaluateSyscall function
71 // pointer. One common use case would be to pass the "aux" pointer as an
72 // argument to Trap() functions.
73 typedef ErrorCode (*EvaluateSyscall)(SandboxBPF* sandbox_compiler,
74 int system_call_number,
75 void* aux);
76 // A vector of BPF instructions that need to be installed as a filter 68 // A vector of BPF instructions that need to be installed as a filter
77 // program in the kernel. 69 // program in the kernel.
78 typedef std::vector<struct sock_filter> Program; 70 typedef std::vector<struct sock_filter> Program;
79 71
80 // Constructors and destructors. 72 // Constructors and destructors.
81 // NOTE: Setting a policy and starting the sandbox is a one-way operation. 73 // NOTE: Setting a policy and starting the sandbox is a one-way operation.
82 // The kernel does not provide any option for unloading a loaded 74 // The kernel does not provide any option for unloading a loaded
83 // sandbox. Strictly speaking, that means we should disallow calling 75 // sandbox. Strictly speaking, that means we should disallow calling
84 // the destructor, if StartSandbox() has ever been called. In practice, 76 // the destructor, if StartSandbox() has ever been called. In practice,
85 // this makes it needlessly complicated to operate on "Sandbox" 77 // this makes it needlessly complicated to operate on "Sandbox"
(...skipping 16 matching lines...) Expand all
102 // provided by the caller. 94 // provided by the caller.
103 static SandboxStatus SupportsSeccompSandbox(int proc_fd); 95 static SandboxStatus SupportsSeccompSandbox(int proc_fd);
104 96
105 // The sandbox needs to be able to access files in "/proc/self". If this 97 // The sandbox needs to be able to access files in "/proc/self". If this
106 // directory is not accessible when "startSandbox()" gets called, the caller 98 // directory is not accessible when "startSandbox()" gets called, the caller
107 // can provide an already opened file descriptor by calling "set_proc_fd()". 99 // can provide an already opened file descriptor by calling "set_proc_fd()".
108 // The sandbox becomes the new owner of this file descriptor and will 100 // The sandbox becomes the new owner of this file descriptor and will
109 // eventually close it when "StartSandbox()" executes. 101 // eventually close it when "StartSandbox()" executes.
110 void set_proc_fd(int proc_fd); 102 void set_proc_fd(int proc_fd);
111 103
112 // The system call evaluator function is called with the system
113 // call number. It can decide to allow the system call unconditionally
114 // by returning ERR_ALLOWED; it can deny the system call unconditionally by
115 // returning an appropriate "errno" value; or it can request inspection
116 // of system call argument(s) by returning a suitable ErrorCode.
117 // The "aux" parameter can be used to pass optional data to the system call
118 // evaluator. There are different possible uses for this data, but one of the
119 // use cases would be for the policy to then forward this pointer to a Trap()
120 // handler. In this case, of course, the data that is pointed to must remain
121 // valid for the entire time that Trap() handlers can be called; typically,
122 // this would be the lifetime of the program.
123 // DEPRECATED: use the policy interface below.
124 void SetSandboxPolicyDeprecated(EvaluateSyscall syscallEvaluator, void* aux);
125
126 // Set the BPF policy as |policy|. Ownership of |policy| is transfered here 104 // Set the BPF policy as |policy|. Ownership of |policy| is transfered here
127 // to the sandbox object. 105 // to the sandbox object.
128 void SetSandboxPolicy(SandboxBPFPolicy* policy); 106 void SetSandboxPolicy(SandboxBPFPolicy* policy);
129 107
130 // We can use ErrorCode to request calling of a trap handler. This method 108 // We can use ErrorCode to request calling of a trap handler. This method
131 // performs the required wrapping of the callback function into an 109 // performs the required wrapping of the callback function into an
132 // ErrorCode object. 110 // ErrorCode object.
133 // The "aux" field can carry a pointer to arbitrary data. See EvaluateSyscall 111 // The "aux" field can carry a pointer to arbitrary data. See EvaluateSyscall
134 // for a description of how to pass data from SetSandboxPolicy() to a Trap() 112 // for a description of how to pass data from SetSandboxPolicy() to a Trap()
135 // handler. 113 // handler.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 typedef std::map<uint32_t, ErrorCode> ErrMap; 200 typedef std::map<uint32_t, ErrorCode> ErrMap;
223 typedef std::set<ErrorCode, struct ErrorCode::LessThan> Conds; 201 typedef std::set<ErrorCode, struct ErrorCode::LessThan> Conds;
224 202
225 // Get a file descriptor pointing to "/proc", if currently available. 203 // Get a file descriptor pointing to "/proc", if currently available.
226 int proc_fd() { return proc_fd_; } 204 int proc_fd() { return proc_fd_; }
227 205
228 // Creates a subprocess and runs "code_in_sandbox" inside of the specified 206 // Creates a subprocess and runs "code_in_sandbox" inside of the specified
229 // policy. The caller has to make sure that "this" has not yet been 207 // policy. The caller has to make sure that "this" has not yet been
230 // initialized with any other policies. 208 // initialized with any other policies.
231 bool RunFunctionInPolicy(void (*code_in_sandbox)(), 209 bool RunFunctionInPolicy(void (*code_in_sandbox)(),
232 EvaluateSyscall syscall_evaluator, 210 scoped_ptr<SandboxBPFPolicy> policy);
233 void* aux);
234 211
235 // Performs a couple of sanity checks to verify that the kernel supports the 212 // Performs a couple of sanity checks to verify that the kernel supports the
236 // features that we need for successful sandboxing. 213 // features that we need for successful sandboxing.
237 // The caller has to make sure that "this" has not yet been initialized with 214 // The caller has to make sure that "this" has not yet been initialized with
238 // any other policies. 215 // any other policies.
239 bool KernelSupportSeccompBPF(); 216 bool KernelSupportSeccompBPF();
240 217
241 // Verify that the current policy passes some basic sanity checks. 218 // Verify that the current policy passes some basic sanity checks.
242 void PolicySanityChecks(SandboxBPFPolicy* policy); 219 void PolicySanityChecks(SandboxBPFPolicy* policy);
243 220
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 scoped_ptr<const SandboxBPFPolicy> policy_; 259 scoped_ptr<const SandboxBPFPolicy> policy_;
283 Conds* conds_; 260 Conds* conds_;
284 bool sandbox_has_started_; 261 bool sandbox_has_started_;
285 262
286 DISALLOW_COPY_AND_ASSIGN(SandboxBPF); 263 DISALLOW_COPY_AND_ASSIGN(SandboxBPF);
287 }; 264 };
288 265
289 } // namespace sandbox 266 } // namespace sandbox
290 267
291 #endif // SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__ 268 #endif // SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/demo.cc ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698