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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
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 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
6 6
7 // Some headers on Android are missing cdefs: crbug.com/172337. 7 // Some headers on Android are missing cdefs: crbug.com/172337.
8 // (We can't use OS_ANDROID here since build_config.h is not included). 8 // (We can't use OS_ANDROID here since build_config.h is not included).
9 #if defined(ANDROID) 9 #if defined(ANDROID)
10 #include <sys/cdefs.h> 10 #include <sys/cdefs.h>
11 #endif 11 #endif
12 12
13 #include <errno.h> 13 #include <errno.h>
14 #include <linux/filter.h> 14 #include <linux/filter.h>
15 #include <sys/prctl.h> 15 #include <sys/prctl.h>
16 #include <sys/types.h> 16 #include <sys/types.h>
17 #include <unistd.h> 17 #include <unistd.h>
18 18
19 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
20 #include "base/files/scoped_file.h" 20 #include "base/files/scoped_file.h"
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "base/posix/eintr_wrapper.h" 24 #include "base/posix/eintr_wrapper.h"
25 #include "base/third_party/valgrind/valgrind.h" 25 #include "base/third_party/valgrind/valgrind.h"
26 #include "sandbox/linux/bpf_dsl/codegen.h" 26 #include "sandbox/linux/bpf_dsl/codegen.h"
27 #include "sandbox/linux/bpf_dsl/dump_bpf.h" 27 #include "sandbox/linux/bpf_dsl/dump_bpf.h"
28 #include "sandbox/linux/bpf_dsl/policy.h" 28 #include "sandbox/linux/bpf_dsl/policy.h"
29 #include "sandbox/linux/bpf_dsl/policy_compiler.h" 29 #include "sandbox/linux/bpf_dsl/policy_compiler.h"
30 #include "sandbox/linux/bpf_dsl/seccomp_macros.h"
30 #include "sandbox/linux/bpf_dsl/syscall_set.h" 31 #include "sandbox/linux/bpf_dsl/syscall_set.h"
31 #include "sandbox/linux/seccomp-bpf/die.h" 32 #include "sandbox/linux/seccomp-bpf/die.h"
32 #include "sandbox/linux/seccomp-bpf/errorcode.h" 33 #include "sandbox/linux/seccomp-bpf/errorcode.h"
33 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h"
34 #include "sandbox/linux/seccomp-bpf/syscall.h" 34 #include "sandbox/linux/seccomp-bpf/syscall.h"
35 #include "sandbox/linux/seccomp-bpf/trap.h" 35 #include "sandbox/linux/seccomp-bpf/trap.h"
36 #include "sandbox/linux/seccomp-bpf/verifier.h" 36 #include "sandbox/linux/seccomp-bpf/verifier.h"
37 #include "sandbox/linux/services/linux_syscalls.h" 37 #include "sandbox/linux/services/proc_util.h"
38 #include "sandbox/linux/services/syscall_wrappers.h" 38 #include "sandbox/linux/services/syscall_wrappers.h"
39 #include "sandbox/linux/services/thread_helpers.h" 39 #include "sandbox/linux/services/thread_helpers.h"
40 #include "sandbox/linux/system_headers/linux_seccomp.h"
41 #include "sandbox/linux/system_headers/linux_syscalls.h"
40 42
41 namespace sandbox { 43 namespace sandbox {
42 44
43 namespace { 45 namespace {
44 46
45 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; } 47 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; }
46 48
47 bool IsSingleThreaded(int proc_task_fd) { 49 bool IsSingleThreaded(int proc_task_fd) {
48 return ThreadHelpers::IsSingleThreaded(proc_task_fd); 50 return ThreadHelpers::IsSingleThreaded(proc_task_fd);
49 } 51 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 CHECK(seccomp_level == SeccompLevel::SINGLE_THREADED || 111 CHECK(seccomp_level == SeccompLevel::SINGLE_THREADED ||
110 seccomp_level == SeccompLevel::MULTI_THREADED); 112 seccomp_level == SeccompLevel::MULTI_THREADED);
111 113
112 if (sandbox_has_started_) { 114 if (sandbox_has_started_) {
113 SANDBOX_DIE( 115 SANDBOX_DIE(
114 "Cannot repeatedly start sandbox. Create a separate Sandbox " 116 "Cannot repeatedly start sandbox. Create a separate Sandbox "
115 "object instead."); 117 "object instead.");
116 return false; 118 return false;
117 } 119 }
118 120
121 if (!proc_task_fd_.is_valid()) {
122 SetProcTaskFd(ProcUtil::OpenProcSelfTask());
123 }
124
119 const bool supports_tsync = KernelSupportsSeccompTsync(); 125 const bool supports_tsync = KernelSupportsSeccompTsync();
120 126
121 if (seccomp_level == SeccompLevel::SINGLE_THREADED) { 127 if (seccomp_level == SeccompLevel::SINGLE_THREADED) {
122 if (!IsSingleThreaded(proc_task_fd_.get())) { 128 // Wait for /proc/self/task/ to update if needed and assert the
123 SANDBOX_DIE("Cannot start sandbox; process is already multi-threaded"); 129 // process is single threaded.
124 return false; 130 ThreadHelpers::AssertSingleThreaded(proc_task_fd_.get());
125 }
126 } else if (seccomp_level == SeccompLevel::MULTI_THREADED) { 131 } else if (seccomp_level == SeccompLevel::MULTI_THREADED) {
127 if (IsSingleThreaded(proc_task_fd_.get())) { 132 if (IsSingleThreaded(proc_task_fd_.get())) {
128 SANDBOX_DIE("Cannot start sandbox; " 133 SANDBOX_DIE("Cannot start sandbox; "
129 "process may be single-threaded when reported as not"); 134 "process may be single-threaded when reported as not");
130 return false; 135 return false;
131 } 136 }
132 if (!supports_tsync) { 137 if (!supports_tsync) {
133 SANDBOX_DIE("Cannot start sandbox; kernel does not support synchronizing " 138 SANDBOX_DIE("Cannot start sandbox; kernel does not support synchronizing "
134 "filters for a threadgroup"); 139 "filters for a threadgroup");
135 return false; 140 return false;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } else { 247 } else {
243 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) { 248 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) {
244 SANDBOX_DIE("Kernel refuses to turn on BPF filters"); 249 SANDBOX_DIE("Kernel refuses to turn on BPF filters");
245 } 250 }
246 } 251 }
247 252
248 sandbox_has_started_ = true; 253 sandbox_has_started_ = true;
249 } 254 }
250 255
251 } // namespace sandbox 256 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/linux_seccomp.h ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698