| 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_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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // directory is not accessible when "startSandbox()" gets called, the caller | 84 // directory is not accessible when "startSandbox()" gets called, the caller |
| 85 // can provide an already opened file descriptor by calling "set_proc_fd()". | 85 // can provide an already opened file descriptor by calling "set_proc_fd()". |
| 86 // The sandbox becomes the new owner of this file descriptor and will | 86 // The sandbox becomes the new owner of this file descriptor and will |
| 87 // eventually close it when "StartSandbox()" executes. | 87 // eventually close it when "StartSandbox()" executes. |
| 88 void set_proc_fd(int proc_fd); | 88 void set_proc_fd(int proc_fd); |
| 89 | 89 |
| 90 // Set the BPF policy as |policy|. Ownership of |policy| is transfered here | 90 // Set the BPF policy as |policy|. Ownership of |policy| is transfered here |
| 91 // to the sandbox object. | 91 // to the sandbox object. |
| 92 void SetSandboxPolicy(SandboxBPFPolicy* policy); | 92 void SetSandboxPolicy(SandboxBPFPolicy* policy); |
| 93 | 93 |
| 94 // Error returns an ErrorCode to indicate the system call should fail with |
| 95 // the specified error number. |
| 96 ErrorCode Error(int err); |
| 97 |
| 94 // We can use ErrorCode to request calling of a trap handler. This method | 98 // We can use ErrorCode to request calling of a trap handler. This method |
| 95 // performs the required wrapping of the callback function into an | 99 // performs the required wrapping of the callback function into an |
| 96 // ErrorCode object. | 100 // ErrorCode object. |
| 97 // The "aux" field can carry a pointer to arbitrary data. See EvaluateSyscall | 101 // The "aux" field can carry a pointer to arbitrary data. See EvaluateSyscall |
| 98 // for a description of how to pass data from SetSandboxPolicy() to a Trap() | 102 // for a description of how to pass data from SetSandboxPolicy() to a Trap() |
| 99 // handler. | 103 // handler. |
| 100 static ErrorCode Trap(Trap::TrapFnc fnc, const void* aux); | 104 static ErrorCode Trap(Trap::TrapFnc fnc, const void* aux); |
| 101 | 105 |
| 102 // Calls a user-space trap handler and disables all sandboxing for system | 106 // Calls a user-space trap handler and disables all sandboxing for system |
| 103 // calls made from this trap handler. | 107 // calls made from this trap handler. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 bool KernelSupportSeccompBPF(); | 225 bool KernelSupportSeccompBPF(); |
| 222 | 226 |
| 223 // Verify that the current policy passes some basic sanity checks. | 227 // Verify that the current policy passes some basic sanity checks. |
| 224 void PolicySanityChecks(SandboxBPFPolicy* policy); | 228 void PolicySanityChecks(SandboxBPFPolicy* policy); |
| 225 | 229 |
| 226 // Assembles and installs a filter based on the policy that has previously | 230 // Assembles and installs a filter based on the policy that has previously |
| 227 // been configured with SetSandboxPolicy(). | 231 // been configured with SetSandboxPolicy(). |
| 228 void InstallFilter(bool must_sync_threads); | 232 void InstallFilter(bool must_sync_threads); |
| 229 | 233 |
| 230 // Compile the configured policy into a complete instruction sequence. | 234 // Compile the configured policy into a complete instruction sequence. |
| 231 // (See MaybeAddEscapeHatch for |has_unsafe_traps|.) | 235 Instruction* CompilePolicy(CodeGen* gen); |
| 232 Instruction* CompilePolicy(CodeGen* gen, bool* has_unsafe_traps); | |
| 233 | 236 |
| 234 // Return an instruction sequence that checks the | 237 // Return an instruction sequence that checks the |
| 235 // arch_seccomp_data's "arch" field is valid, and then passes | 238 // arch_seccomp_data's "arch" field is valid, and then passes |
| 236 // control to |passed| if so. | 239 // control to |passed| if so. |
| 237 Instruction* CheckArch(CodeGen* gen, Instruction* passed); | 240 Instruction* CheckArch(CodeGen* gen, Instruction* passed); |
| 238 | 241 |
| 239 // If the |rest| instruction sequence contains any unsafe traps, | 242 // If |has_unsafe_traps_| is true, returns an instruction sequence |
| 240 // then sets |*has_unsafe_traps| to true and returns an instruction | 243 // that allows all system calls from Syscall::Call(), and otherwise |
| 241 // sequence that allows all system calls from Syscall::Call(), and | 244 // passes control to |rest|. Otherwise, simply returns |rest|. |
| 242 // otherwise passes control to |rest|. | |
| 243 // | |
| 244 // If |rest| contains no unsafe traps, then |rest| is returned | |
| 245 // directly and |*has_unsafe_traps| is set to false. | |
| 246 Instruction* MaybeAddEscapeHatch(CodeGen* gen, | 245 Instruction* MaybeAddEscapeHatch(CodeGen* gen, |
| 247 bool* has_unsafe_traps, | |
| 248 Instruction* rest); | 246 Instruction* rest); |
| 249 | 247 |
| 250 // Return an instruction sequence that loads and checks the system | 248 // Return an instruction sequence that loads and checks the system |
| 251 // call number, performs a binary search, and then dispatches to an | 249 // call number, performs a binary search, and then dispatches to an |
| 252 // appropriate instruction sequence compiled from the current | 250 // appropriate instruction sequence compiled from the current |
| 253 // policy. | 251 // policy. |
| 254 Instruction* DispatchSyscall(CodeGen* gen); | 252 Instruction* DispatchSyscall(CodeGen* gen); |
| 255 | 253 |
| 256 // Return an instruction sequence that checks the system call number | 254 // Return an instruction sequence that checks the system call number |
| 257 // (expected to be loaded in register A) and if valid, passes | 255 // (expected to be loaded in register A) and if valid, passes |
| 258 // control to |passed| (with register A still valid). | 256 // control to |passed| (with register A still valid). |
| 259 Instruction* CheckSyscallNumber(CodeGen* gen, Instruction* passed); | 257 Instruction* CheckSyscallNumber(CodeGen* gen, Instruction* passed); |
| 260 | 258 |
| 261 // Verify the correctness of a compiled program by comparing it against the | 259 // Verify the correctness of a compiled program by comparing it against the |
| 262 // current policy. This function should only ever be called by unit tests and | 260 // current policy. This function should only ever be called by unit tests and |
| 263 // by the sandbox internals. It should not be used by production code. | 261 // by the sandbox internals. It should not be used by production code. |
| 264 void VerifyProgram(const Program& program, bool has_unsafe_traps); | 262 void VerifyProgram(const Program& program); |
| 265 | 263 |
| 266 // Finds all the ranges of system calls that need to be handled. Ranges are | 264 // Finds all the ranges of system calls that need to be handled. Ranges are |
| 267 // sorted in ascending order of system call numbers. There are no gaps in the | 265 // sorted in ascending order of system call numbers. There are no gaps in the |
| 268 // ranges. System calls with identical ErrorCodes are coalesced into a single | 266 // ranges. System calls with identical ErrorCodes are coalesced into a single |
| 269 // range. | 267 // range. |
| 270 void FindRanges(Ranges* ranges); | 268 void FindRanges(Ranges* ranges); |
| 271 | 269 |
| 272 // Returns a BPF program snippet that implements a jump table for the | 270 // Returns a BPF program snippet that implements a jump table for the |
| 273 // given range of system call numbers. This function runs recursively. | 271 // given range of system call numbers. This function runs recursively. |
| 274 Instruction* AssembleJumpTable(CodeGen* gen, | 272 Instruction* AssembleJumpTable(CodeGen* gen, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 296 Instruction* passed, | 294 Instruction* passed, |
| 297 Instruction* failed); | 295 Instruction* failed); |
| 298 | 296 |
| 299 static SandboxStatus status_; | 297 static SandboxStatus status_; |
| 300 | 298 |
| 301 bool quiet_; | 299 bool quiet_; |
| 302 int proc_fd_; | 300 int proc_fd_; |
| 303 scoped_ptr<const SandboxBPFPolicy> policy_; | 301 scoped_ptr<const SandboxBPFPolicy> policy_; |
| 304 Conds* conds_; | 302 Conds* conds_; |
| 305 bool sandbox_has_started_; | 303 bool sandbox_has_started_; |
| 304 bool has_unsafe_traps_; |
| 306 | 305 |
| 307 DISALLOW_COPY_AND_ASSIGN(SandboxBPF); | 306 DISALLOW_COPY_AND_ASSIGN(SandboxBPF); |
| 308 }; | 307 }; |
| 309 | 308 |
| 310 } // namespace sandbox | 309 } // namespace sandbox |
| 311 | 310 |
| 312 #endif // SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__ | 311 #endif // SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__ |
| OLD | NEW |