Chromium Code Reviews| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 explicit RedirectToUserSpacePolicyWrapper( | 192 explicit RedirectToUserSpacePolicyWrapper( |
| 193 const SandboxBPFPolicy* wrapped_policy) | 193 const SandboxBPFPolicy* wrapped_policy) |
| 194 : wrapped_policy_(wrapped_policy) { | 194 : wrapped_policy_(wrapped_policy) { |
| 195 DCHECK(wrapped_policy_); | 195 DCHECK(wrapped_policy_); |
| 196 } | 196 } |
| 197 | 197 |
| 198 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, | 198 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, |
| 199 int system_call_number) const OVERRIDE { | 199 int system_call_number) const OVERRIDE { |
| 200 ErrorCode err = | 200 ErrorCode err = |
| 201 wrapped_policy_->EvaluateSyscall(sandbox_compiler, system_call_number); | 201 wrapped_policy_->EvaluateSyscall(sandbox_compiler, system_call_number); |
| 202 if ((err.err() & SECCOMP_RET_ACTION) == SECCOMP_RET_ERRNO) { | 202 if ((err.err() & SECCOMP_RET_ACTION) == SECCOMP_RET_ERRNO) { |
|
jln (very slow on Chromium)
2014/08/29 20:40:05
Shouldn't use your new ChangeErrnoToTraps() method
leecam
2014/08/29 22:56:30
Done.
| |
| 203 return ReturnErrnoViaTrap(sandbox_compiler, err.err() & SECCOMP_RET_DATA); | 203 return ReturnErrnoViaTrap(sandbox_compiler, err.err() & SECCOMP_RET_DATA); |
| 204 } else if (err.error_type() == ErrorCode::ET_COND) { | |
| 205 // Need to change all ERRNO ErrorCode in this Conditional to Traps | |
| 206 ChangeErrnoToTraps(&err, sandbox_compiler); | |
| 204 } | 207 } |
| 205 return err; | 208 return err; |
| 206 } | 209 } |
| 207 | 210 |
| 208 virtual ErrorCode InvalidSyscall( | 211 virtual ErrorCode InvalidSyscall( |
| 209 SandboxBPF* sandbox_compiler) const OVERRIDE { | 212 SandboxBPF* sandbox_compiler) const OVERRIDE { |
| 210 return ReturnErrnoViaTrap(sandbox_compiler, ENOSYS); | 213 return ReturnErrnoViaTrap(sandbox_compiler, ENOSYS); |
| 211 } | 214 } |
| 212 | 215 |
| 213 private: | 216 private: |
| 214 ErrorCode ReturnErrnoViaTrap(SandboxBPF* sandbox_compiler, int err) const { | 217 ErrorCode ReturnErrnoViaTrap(SandboxBPF* sandbox_compiler, int err) const { |
| 215 return sandbox_compiler->Trap(ReturnErrno, reinterpret_cast<void*>(err)); | 218 return sandbox_compiler->Trap(ReturnErrno, reinterpret_cast<void*>(err)); |
| 216 } | 219 } |
| 217 | 220 |
| 221 void ChangeErrnoToTraps(ErrorCode* err, SandboxBPF* sandbox_compiler) const { | |
|
jln (very slow on Chromium)
2014/08/29 20:40:05
Because of the recursion you need to handle all ca
leecam
2014/08/29 22:56:31
Done.
| |
| 222 if (err->error_type() == ErrorCode::ET_SIMPLE && | |
| 223 (err->err() & SECCOMP_RET_ACTION) == SECCOMP_RET_ERRNO) { | |
| 224 // Have an errno, need to change this to a trap | |
| 225 *err = | |
| 226 ReturnErrnoViaTrap(sandbox_compiler, err->err() & SECCOMP_RET_DATA); | |
| 227 } else if (err->error_type() == ErrorCode::ET_COND) { | |
| 228 // Need to explore both paths | |
| 229 ChangeErrnoToTraps((ErrorCode*)err->passed(), sandbox_compiler); | |
| 230 ChangeErrnoToTraps((ErrorCode*)err->failed(), sandbox_compiler); | |
| 231 } | |
| 232 // Have a Trap or Allow, leave as they are. | |
|
jln (very slow on Chromium)
2014/08/29 20:40:05
To make this code more robust, check if it is a Tr
leecam
2014/08/29 22:56:30
Done.
| |
| 233 } | |
| 234 | |
| 218 const SandboxBPFPolicy* wrapped_policy_; | 235 const SandboxBPFPolicy* wrapped_policy_; |
| 219 DISALLOW_COPY_AND_ASSIGN(RedirectToUserSpacePolicyWrapper); | 236 DISALLOW_COPY_AND_ASSIGN(RedirectToUserSpacePolicyWrapper); |
| 220 }; | 237 }; |
| 221 | 238 |
| 222 intptr_t BPFFailure(const struct arch_seccomp_data&, void* aux) { | 239 intptr_t BPFFailure(const struct arch_seccomp_data&, void* aux) { |
| 223 SANDBOX_DIE(static_cast<char*>(aux)); | 240 SANDBOX_DIE(static_cast<char*>(aux)); |
| 224 } | 241 } |
| 225 | 242 |
| 226 } // namespace | 243 } // namespace |
| 227 | 244 |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 &*conds_->insert(failed).first); | 1076 &*conds_->insert(failed).first); |
| 1060 } | 1077 } |
| 1061 | 1078 |
| 1062 ErrorCode SandboxBPF::Kill(const char* msg) { | 1079 ErrorCode SandboxBPF::Kill(const char* msg) { |
| 1063 return Trap(BPFFailure, const_cast<char*>(msg)); | 1080 return Trap(BPFFailure, const_cast<char*>(msg)); |
| 1064 } | 1081 } |
| 1065 | 1082 |
| 1066 SandboxBPF::SandboxStatus SandboxBPF::status_ = STATUS_UNKNOWN; | 1083 SandboxBPF::SandboxStatus SandboxBPF::status_ = STATUS_UNKNOWN; |
| 1067 | 1084 |
| 1068 } // namespace sandbox | 1085 } // namespace sandbox |
| OLD | NEW |