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 #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> |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if (rv == -1 && errno == EFAULT) { | 72 if (rv == -1 && errno == EFAULT) { |
73 return true; | 73 return true; |
74 } else { | 74 } else { |
75 // TODO(jln): turn these into DCHECK after 417888 is considered fixed. | 75 // TODO(jln): turn these into DCHECK after 417888 is considered fixed. |
76 CHECK_EQ(-1, rv); | 76 CHECK_EQ(-1, rv); |
77 CHECK(ENOSYS == errno || EINVAL == errno); | 77 CHECK(ENOSYS == errno || EINVAL == errno); |
78 return false; | 78 return false; |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
| 82 uint64_t EscapePC() { |
| 83 intptr_t rv = Syscall::Call(-1); |
| 84 if (rv == -1 && errno == ENOSYS) { |
| 85 return 0; |
| 86 } |
| 87 return static_cast<uint64_t>(static_cast<uintptr_t>(rv)); |
| 88 } |
| 89 |
82 } // namespace | 90 } // namespace |
83 | 91 |
84 SandboxBPF::SandboxBPF(bpf_dsl::Policy* policy) | 92 SandboxBPF::SandboxBPF(bpf_dsl::Policy* policy) |
85 : proc_task_fd_(), sandbox_has_started_(false), policy_(policy) { | 93 : proc_task_fd_(), sandbox_has_started_(false), policy_(policy) { |
86 } | 94 } |
87 | 95 |
88 SandboxBPF::~SandboxBPF() { | 96 SandboxBPF::~SandboxBPF() { |
89 } | 97 } |
90 | 98 |
91 // static | 99 // static |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 static_cast<intptr_t>(args.args[3]), static_cast<intptr_t>(args.args[4]), | 185 static_cast<intptr_t>(args.args[3]), static_cast<intptr_t>(args.args[4]), |
178 static_cast<intptr_t>(args.args[5])); | 186 static_cast<intptr_t>(args.args[5])); |
179 } | 187 } |
180 | 188 |
181 scoped_ptr<CodeGen::Program> SandboxBPF::AssembleFilter( | 189 scoped_ptr<CodeGen::Program> SandboxBPF::AssembleFilter( |
182 bool force_verification) { | 190 bool force_verification) { |
183 #if !defined(NDEBUG) | 191 #if !defined(NDEBUG) |
184 force_verification = true; | 192 force_verification = true; |
185 #endif | 193 #endif |
186 DCHECK(policy_); | 194 DCHECK(policy_); |
187 bpf_dsl::PolicyCompiler compiler(policy_.get(), Trap::Registry()); | 195 bpf_dsl::PolicyCompiler compiler(policy_.get(), Trap::Registry(), EscapePC()); |
188 scoped_ptr<CodeGen::Program> program = compiler.Compile(); | 196 scoped_ptr<CodeGen::Program> program = compiler.Compile(); |
189 | 197 |
190 // Make sure compilation resulted in a BPF program that executes | 198 // Make sure compilation resulted in a BPF program that executes |
191 // correctly. Otherwise, there is an internal error in our BPF compiler. | 199 // correctly. Otherwise, there is an internal error in our BPF compiler. |
192 // There is really nothing the caller can do until the bug is fixed. | 200 // There is really nothing the caller can do until the bug is fixed. |
193 if (force_verification) { | 201 if (force_verification) { |
194 // Verification is expensive. We only perform this step, if we are | 202 // Verification is expensive. We only perform this step, if we are |
195 // compiled in debug mode, or if the caller explicitly requested | 203 // compiled in debug mode, or if the caller explicitly requested |
196 // verification. | 204 // verification. |
197 | 205 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } else { | 255 } else { |
248 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) { | 256 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) { |
249 SANDBOX_DIE("Kernel refuses to turn on BPF filters"); | 257 SANDBOX_DIE("Kernel refuses to turn on BPF filters"); |
250 } | 258 } |
251 } | 259 } |
252 | 260 |
253 sandbox_has_started_ = true; | 261 sandbox_has_started_ = true; |
254 } | 262 } |
255 | 263 |
256 } // namespace sandbox | 264 } // namespace sandbox |
OLD | NEW |