| 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 <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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // system calls. | 88 // system calls. |
| 89 static bool IsValidSyscallNumber(int sysnum); | 89 static bool IsValidSyscallNumber(int sysnum); |
| 90 | 90 |
| 91 // There are a lot of reasons why the Seccomp sandbox might not be available. | 91 // There are a lot of reasons why the Seccomp sandbox might not be available. |
| 92 // This could be because the kernel does not support Seccomp mode, or it | 92 // This could be because the kernel does not support Seccomp mode, or it |
| 93 // could be because another sandbox is already active. | 93 // could be because another sandbox is already active. |
| 94 // "proc_fd" should be a file descriptor for "/proc", or -1 if not | 94 // "proc_fd" should be a file descriptor for "/proc", or -1 if not |
| 95 // provided by the caller. | 95 // provided by the caller. |
| 96 static SandboxStatus SupportsSeccompSandbox(int proc_fd); | 96 static SandboxStatus SupportsSeccompSandbox(int proc_fd); |
| 97 | 97 |
| 98 // Determines if the kernel has support for the seccomp() system call to |
| 99 // synchronize BPF filters across a thread group. |
| 100 static SandboxStatus SupportsSeccompThreadFilterSynchronization(); |
| 101 |
| 98 // The sandbox needs to be able to access files in "/proc/self". If this | 102 // The sandbox needs to be able to access files in "/proc/self". If this |
| 99 // directory is not accessible when "startSandbox()" gets called, the caller | 103 // directory is not accessible when "startSandbox()" gets called, the caller |
| 100 // can provide an already opened file descriptor by calling "set_proc_fd()". | 104 // can provide an already opened file descriptor by calling "set_proc_fd()". |
| 101 // The sandbox becomes the new owner of this file descriptor and will | 105 // The sandbox becomes the new owner of this file descriptor and will |
| 102 // eventually close it when "StartSandbox()" executes. | 106 // eventually close it when "StartSandbox()" executes. |
| 103 void set_proc_fd(int proc_fd); | 107 void set_proc_fd(int proc_fd); |
| 104 | 108 |
| 105 // Set the BPF policy as |policy|. Ownership of |policy| is transfered here | 109 // Set the BPF policy as |policy|. Ownership of |policy| is transfered here |
| 106 // to the sandbox object. | 110 // to the sandbox object. |
| 107 void SetSandboxPolicy(SandboxBPFPolicy* policy); | 111 void SetSandboxPolicy(SandboxBPFPolicy* policy); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // features that we need for successful sandboxing. | 218 // features that we need for successful sandboxing. |
| 215 // The caller has to make sure that "this" has not yet been initialized with | 219 // The caller has to make sure that "this" has not yet been initialized with |
| 216 // any other policies. | 220 // any other policies. |
| 217 bool KernelSupportSeccompBPF(); | 221 bool KernelSupportSeccompBPF(); |
| 218 | 222 |
| 219 // Verify that the current policy passes some basic sanity checks. | 223 // Verify that the current policy passes some basic sanity checks. |
| 220 void PolicySanityChecks(SandboxBPFPolicy* policy); | 224 void PolicySanityChecks(SandboxBPFPolicy* policy); |
| 221 | 225 |
| 222 // Assembles and installs a filter based on the policy that has previously | 226 // Assembles and installs a filter based on the policy that has previously |
| 223 // been configured with SetSandboxPolicy(). | 227 // been configured with SetSandboxPolicy(). |
| 224 void InstallFilter(SandboxThreadState thread_state); | 228 void InstallFilter(bool must_sync_threads); |
| 225 | 229 |
| 226 // Verify the correctness of a compiled program by comparing it against the | 230 // Verify the correctness of a compiled program by comparing it against the |
| 227 // current policy. This function should only ever be called by unit tests and | 231 // current policy. This function should only ever be called by unit tests and |
| 228 // by the sandbox internals. It should not be used by production code. | 232 // by the sandbox internals. It should not be used by production code. |
| 229 void VerifyProgram(const Program& program, bool has_unsafe_traps); | 233 void VerifyProgram(const Program& program, bool has_unsafe_traps); |
| 230 | 234 |
| 231 // Finds all the ranges of system calls that need to be handled. Ranges are | 235 // Finds all the ranges of system calls that need to be handled. Ranges are |
| 232 // sorted in ascending order of system call numbers. There are no gaps in the | 236 // sorted in ascending order of system call numbers. There are no gaps in the |
| 233 // ranges. System calls with identical ErrorCodes are coalesced into a single | 237 // ranges. System calls with identical ErrorCodes are coalesced into a single |
| 234 // range. | 238 // range. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 260 scoped_ptr<const SandboxBPFPolicy> policy_; | 264 scoped_ptr<const SandboxBPFPolicy> policy_; |
| 261 Conds* conds_; | 265 Conds* conds_; |
| 262 bool sandbox_has_started_; | 266 bool sandbox_has_started_; |
| 263 | 267 |
| 264 DISALLOW_COPY_AND_ASSIGN(SandboxBPF); | 268 DISALLOW_COPY_AND_ASSIGN(SandboxBPF); |
| 265 }; | 269 }; |
| 266 | 270 |
| 267 } // namespace sandbox | 271 } // namespace sandbox |
| 268 | 272 |
| 269 #endif // SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__ | 273 #endif // SANDBOX_LINUX_SECCOMP_BPF_SANDBOX_BPF_H__ |
| OLD | NEW |