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/bpf_dsl/policy_compiler.h" | 5 #include "sandbox/linux/bpf_dsl/policy_compiler.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <linux/filter.h> | 8 #include <linux/filter.h> |
9 #include <sys/syscall.h> | 9 #include <sys/syscall.h> |
10 | 10 |
11 #include <limits> | 11 #include <limits> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" | 15 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
16 #include "sandbox/linux/bpf_dsl/bpf_dsl_impl.h" | 16 #include "sandbox/linux/bpf_dsl/bpf_dsl_impl.h" |
| 17 #include "sandbox/linux/bpf_dsl/policy.h" |
17 #include "sandbox/linux/seccomp-bpf/codegen.h" | 18 #include "sandbox/linux/seccomp-bpf/codegen.h" |
18 #include "sandbox/linux/seccomp-bpf/die.h" | 19 #include "sandbox/linux/seccomp-bpf/die.h" |
19 #include "sandbox/linux/seccomp-bpf/errorcode.h" | 20 #include "sandbox/linux/seccomp-bpf/errorcode.h" |
20 #include "sandbox/linux/seccomp-bpf/instruction.h" | 21 #include "sandbox/linux/seccomp-bpf/instruction.h" |
21 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" | 22 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" |
22 #include "sandbox/linux/seccomp-bpf/syscall.h" | 23 #include "sandbox/linux/seccomp-bpf/syscall.h" |
23 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" | 24 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" |
24 | 25 |
25 namespace sandbox { | 26 namespace sandbox { |
26 namespace bpf_dsl { | 27 namespace bpf_dsl { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // set errno themselves. The glibc wrapper that triggered the SIGSYS will | 69 // set errno themselves. The glibc wrapper that triggered the SIGSYS will |
69 // ultimately do so for us. | 70 // ultimately do so for us. |
70 int err = reinterpret_cast<intptr_t>(aux) & SECCOMP_RET_DATA; | 71 int err = reinterpret_cast<intptr_t>(aux) & SECCOMP_RET_DATA; |
71 return -err; | 72 return -err; |
72 } | 73 } |
73 | 74 |
74 intptr_t BPFFailure(const struct arch_seccomp_data&, void* aux) { | 75 intptr_t BPFFailure(const struct arch_seccomp_data&, void* aux) { |
75 SANDBOX_DIE(static_cast<char*>(aux)); | 76 SANDBOX_DIE(static_cast<char*>(aux)); |
76 } | 77 } |
77 | 78 |
78 bool HasUnsafeTraps(const SandboxBPFDSLPolicy* policy) { | 79 bool HasUnsafeTraps(const Policy* policy) { |
79 for (uint32_t sysnum : SyscallSet::All()) { | 80 for (uint32_t sysnum : SyscallSet::All()) { |
80 if (SyscallSet::IsValid(sysnum) && | 81 if (SyscallSet::IsValid(sysnum) && |
81 policy->EvaluateSyscall(sysnum)->HasUnsafeTraps()) { | 82 policy->EvaluateSyscall(sysnum)->HasUnsafeTraps()) { |
82 return true; | 83 return true; |
83 } | 84 } |
84 } | 85 } |
85 return policy->InvalidSyscall()->HasUnsafeTraps(); | 86 return policy->InvalidSyscall()->HasUnsafeTraps(); |
86 } | 87 } |
87 | 88 |
88 } // namespace | 89 } // namespace |
89 | 90 |
90 struct PolicyCompiler::Range { | 91 struct PolicyCompiler::Range { |
91 Range(uint32_t f, const ErrorCode& e) : from(f), err(e) {} | 92 Range(uint32_t f, const ErrorCode& e) : from(f), err(e) {} |
92 uint32_t from; | 93 uint32_t from; |
93 ErrorCode err; | 94 ErrorCode err; |
94 }; | 95 }; |
95 | 96 |
96 PolicyCompiler::PolicyCompiler(const SandboxBPFDSLPolicy* policy, | 97 PolicyCompiler::PolicyCompiler(const Policy* policy, TrapRegistry* registry) |
97 TrapRegistry* registry) | |
98 : policy_(policy), | 98 : policy_(policy), |
99 registry_(registry), | 99 registry_(registry), |
100 conds_(), | 100 conds_(), |
101 gen_(), | 101 gen_(), |
102 has_unsafe_traps_(HasUnsafeTraps(policy_)) { | 102 has_unsafe_traps_(HasUnsafeTraps(policy_)) { |
103 } | 103 } |
104 | 104 |
105 PolicyCompiler::~PolicyCompiler() { | 105 PolicyCompiler::~PolicyCompiler() { |
106 } | 106 } |
107 | 107 |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 &*conds_.insert(passed).first, | 514 &*conds_.insert(passed).first, |
515 &*conds_.insert(failed).first); | 515 &*conds_.insert(failed).first); |
516 } | 516 } |
517 | 517 |
518 ErrorCode PolicyCompiler::Kill(const char* msg) { | 518 ErrorCode PolicyCompiler::Kill(const char* msg) { |
519 return Trap(BPFFailure, const_cast<char*>(msg)); | 519 return Trap(BPFFailure, const_cast<char*>(msg)); |
520 } | 520 } |
521 | 521 |
522 } // namespace bpf_dsl | 522 } // namespace bpf_dsl |
523 } // namespace sandbox | 523 } // namespace sandbox |
OLD | NEW |