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

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

Issue 10536048: Instead of outputting one BPF check per possible system call. Coalesce (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Does this result in easier-to-read diffs? Created 8 years, 6 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 | Annotate | Revision Log
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 #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 if (evaluators.size() != 1) { 14 if (evaluators.size() != 1) {
15 *err = "Not implemented"; 15 *err = "Not implemented";
16 return false; 16 return false;
17 } 17 }
18 Sandbox::EvaluateSyscall evaluateSyscall = evaluators.begin()->first; 18 Sandbox::EvaluateSyscall evaluateSyscall = evaluators.begin()->first;
19 for (int nr = MIN_SYSCALL-1; nr <= MAX_SYSCALL+1; ++nr) { 19 for (int nr = MIN_SYSCALL-1; nr <= static_cast<int>(MAX_SYSCALL)+1; ++nr) {
20 // We ideally want to iterate over the full system call range and values 20 // We ideally want to iterate over the full system call range and values
21 // just above and just below this range. This gives us the full result set 21 // just above and just below this range. This gives us the full result set
22 // of the "evaluators". 22 // of the "evaluators".
23 // On Intel systems, this can fail in a surprising way, as a cleared bit 30 23 // On Intel systems, this can fail in a surprising way, as a cleared bit 30
24 // indicates either i386 or x86-64; and a set bit 30 indicates x32. And 24 // indicates either i386 or x86-64; and a set bit 30 indicates x32. And
25 // unless we pay attention to setting this bit correctly, an early check in 25 // unless we pay attention to setting this bit correctly, an early check in
26 // our BPF program will make us fail with a misleading error code. 26 // our BPF program will make us fail with a misleading error code.
27 #if defined(__i386__) || defined(__x86_64__) 27 #if defined(__i386__) || defined(__x86_64__)
28 #if defined(__x86_64__) && defined(__ILP32__) 28 #if defined(__x86_64__) && defined(__ILP32__)
29 int sysnum = nr | 0x40000000; 29 int sysnum = nr | 0x40000000;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 uint32_t Verifier::ret(State *state, const struct sock_filter& insn, 167 uint32_t Verifier::ret(State *state, const struct sock_filter& insn,
168 const char **err) { 168 const char **err) {
169 if (BPF_SRC(insn.code) != BPF_K) { 169 if (BPF_SRC(insn.code) != BPF_K) {
170 *err = "Invalid BPF_RET instruction"; 170 *err = "Invalid BPF_RET instruction";
171 return 0; 171 return 0;
172 } 172 }
173 return insn.k; 173 return insn.k;
174 } 174 }
175 175
176 } // namespace 176 } // namespace
OLDNEW
« sandbox/linux/seccomp-bpf/sandbox_bpf.cc ('K') | « sandbox/linux/seccomp-bpf/sandbox_bpf.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698