| 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 #include "sandbox/linux/seccomp-bpf/verifier.h" | 6 #include "sandbox/linux/seccomp-bpf/verifier.h" |
| 7 | 7 |
| 8 | 8 |
| 9 namespace playground2 { | 9 namespace playground2 { |
| 10 | 10 |
| 11 bool Verifier::verifyBPF(const std::vector<struct sock_filter>& program, | 11 bool Verifier::verifyBPF(const std::vector<struct sock_filter>& program, |
| 12 const Sandbox::Evaluators& evaluators, | 12 const Sandbox::Evaluators& evaluators, |
| 13 const char **err) { | 13 const char **err) { |
| 14 *err = NULL; | 14 *err = NULL; |
| 15 if (evaluators.size() != 1) { | 15 if (evaluators.size() != 1) { |
| 16 *err = "Not implemented"; | 16 *err = "Not implemented"; |
| 17 return false; | 17 return false; |
| 18 } | 18 } |
| 19 Sandbox::EvaluateSyscall evaluateSyscall = evaluators.begin()->first; | 19 Sandbox::EvaluateSyscall evaluateSyscall = evaluators.begin()->first; |
| 20 for (int nr = MIN_SYSCALL-1; nr <= MAX_SYSCALL+1; ++nr) { | 20 for (int nr = MIN_SYSCALL-1; nr <= static_cast<int>(MAX_SYSCALL)+1; ++nr) { |
| 21 // We ideally want to iterate over the full system call range and values | 21 // We ideally want to iterate over the full system call range and values |
| 22 // just above and just below this range. This gives us the full result set | 22 // just above and just below this range. This gives us the full result set |
| 23 // of the "evaluators". | 23 // of the "evaluators". |
| 24 // On Intel systems, this can fail in a surprising way, as a cleared bit 30 | 24 // On Intel systems, this can fail in a surprising way, as a cleared bit 30 |
| 25 // indicates either i386 or x86-64; and a set bit 30 indicates x32. And | 25 // indicates either i386 or x86-64; and a set bit 30 indicates x32. And |
| 26 // unless we pay attention to setting this bit correctly, an early check in | 26 // unless we pay attention to setting this bit correctly, an early check in |
| 27 // our BPF program will make us fail with a misleading error code. | 27 // our BPF program will make us fail with a misleading error code. |
| 28 #if defined(__i386__) || defined(__x86_64__) | 28 #if defined(__i386__) || defined(__x86_64__) |
| 29 #if defined(__x86_64__) && defined(__ILP32__) | 29 #if defined(__x86_64__) && defined(__ILP32__) |
| 30 int sysnum = nr | 0x40000000; | 30 int sysnum = nr | 0x40000000; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 uint32_t Verifier::ret(State *state, const struct sock_filter& insn, | 166 uint32_t Verifier::ret(State *state, const struct sock_filter& insn, |
| 167 const char **err) { | 167 const char **err) { |
| 168 if (BPF_SRC(insn.code) != BPF_K) { | 168 if (BPF_SRC(insn.code) != BPF_K) { |
| 169 *err = "Invalid BPF_RET instruction"; | 169 *err = "Invalid BPF_RET instruction"; |
| 170 return 0; | 170 return 0; |
| 171 } | 171 } |
| 172 return insn.k; | 172 return insn.k; |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace | 175 } // namespace |
| OLD | NEW |