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

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

Issue 10546041: Added a new Verifier class to the BPF compiler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored error handling and rebased on head of the trunk 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef VERIFIER_H__
6 #define VERIFIER_H__
7
8 #include <linux/filter.h>
9
10 #include <utility>
11 #include <vector>
12
13 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
14
15
16 namespace playground2 {
17
18 class Verifier {
19 public:
20 // Evaluate the BPF program for all possible inputs and verify that it
21 // computes the correct result. We use the "evaluators" to determine
22 // the full set of possible inputs that we have to iterate over.
23 // Returns success, if the BPF filter accurately reflects the rules
24 // set by the "evaluators".
25 static bool verifyBPF(const std::vector<struct sock_filter>& program,
26 const Sandbox::Evaluators& evaluators,
27 const char **err);
28
29 // Evaluate a given BPF program for a particular set of system call
30 // parameters. If evaluation failed for any reason, "err" will be set to
31 // a non-NULL error string. Otherwise, the BPF program's result will be
32 // returned by the function.
33 // We do not actually implement the full BPF state machine, but only the
34 // parts that can actually be generated by our BPF compiler. If this code
35 // is used for purposes other than verifying the output of the sandbox's
36 // BPF compiler, we might have to extend this BPF interpreter.
37 static uint32_t evaluateBPF(const std::vector<struct sock_filter>& program,
38 const struct arch_seccomp_data& data,
39 const char **err);
40
41 private:
42 struct State {
43 State(const std::vector<struct sock_filter>& p,
44 const struct arch_seccomp_data& d) :
45 program(p),
46 data(d),
47 ip(0),
48 accumulator(0),
49 accIsValid(false) {
50 }
51 const std::vector<struct sock_filter>& program;
52 const struct arch_seccomp_data& data;
53 unsigned int ip;
54 uint32_t accumulator;
55 bool accIsValid;
56 };
57
58 static void ld (State *state, const struct sock_filter& insn,
59 const char **err);
60 static void jmp(State *state, const struct sock_filter& insn,
61 const char **err);
62 static uint32_t ret(State *state, const struct sock_filter& insn,
63 const char **err);
64
65 DISALLOW_IMPLICIT_CONSTRUCTORS(Verifier);
66 };
67
68 } // namespace
69
70 #endif // VERIFIER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698