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 #ifndef SANDBOX_LINUX_SECCOMP_BPF_VERIFIER_H__ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_VERIFIER_H__ |
6 #define SANDBOX_LINUX_SECCOMP_BPF_VERIFIER_H__ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_VERIFIER_H__ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 | 13 |
14 struct sock_filter; | 14 struct sock_filter; |
15 | 15 |
16 namespace sandbox { | 16 namespace sandbox { |
17 struct arch_seccomp_data; | 17 struct arch_seccomp_data; |
18 namespace bpf_dsl { | 18 namespace bpf_dsl { |
19 class SandboxBPFDSLPolicy; | 19 class Policy; |
20 class PolicyCompiler; | 20 class PolicyCompiler; |
21 } | 21 } |
22 | 22 |
23 class Verifier { | 23 class Verifier { |
24 public: | 24 public: |
25 // Evaluate the BPF program for all possible inputs and verify that it | 25 // Evaluate the BPF program for all possible inputs and verify that it |
26 // computes the correct result. We use the "evaluators" to determine | 26 // computes the correct result. We use the "evaluators" to determine |
27 // the full set of possible inputs that we have to iterate over. | 27 // the full set of possible inputs that we have to iterate over. |
28 // Returns success, if the BPF filter accurately reflects the rules | 28 // Returns success, if the BPF filter accurately reflects the rules |
29 // set by the "evaluators". | 29 // set by the "evaluators". |
30 // Upon success, "err" is set to NULL. Upon failure, it contains a static | 30 // Upon success, "err" is set to NULL. Upon failure, it contains a static |
31 // error message that does not need to be free()'d. | 31 // error message that does not need to be free()'d. |
32 static bool VerifyBPF(bpf_dsl::PolicyCompiler* compiler, | 32 static bool VerifyBPF(bpf_dsl::PolicyCompiler* compiler, |
33 const std::vector<struct sock_filter>& program, | 33 const std::vector<struct sock_filter>& program, |
34 const bpf_dsl::SandboxBPFDSLPolicy& policy, | 34 const bpf_dsl::Policy& policy, |
35 const char** err); | 35 const char** err); |
36 | 36 |
37 // Evaluate a given BPF program for a particular set of system call | 37 // Evaluate a given BPF program for a particular set of system call |
38 // parameters. If evaluation failed for any reason, "err" will be set to | 38 // parameters. If evaluation failed for any reason, "err" will be set to |
39 // a non-NULL error string. Otherwise, the BPF program's result will be | 39 // a non-NULL error string. Otherwise, the BPF program's result will be |
40 // returned by the function and "err" is NULL. | 40 // returned by the function and "err" is NULL. |
41 // We do not actually implement the full BPF state machine, but only the | 41 // We do not actually implement the full BPF state machine, but only the |
42 // parts that can actually be generated by our BPF compiler. If this code | 42 // parts that can actually be generated by our BPF compiler. If this code |
43 // is used for purposes other than verifying the output of the sandbox's | 43 // is used for purposes other than verifying the output of the sandbox's |
44 // BPF compiler, we might have to extend this BPF interpreter. | 44 // BPF compiler, we might have to extend this BPF interpreter. |
45 static uint32_t EvaluateBPF(const std::vector<struct sock_filter>& program, | 45 static uint32_t EvaluateBPF(const std::vector<struct sock_filter>& program, |
46 const struct arch_seccomp_data& data, | 46 const struct arch_seccomp_data& data, |
47 const char** err); | 47 const char** err); |
48 | 48 |
49 private: | 49 private: |
50 DISALLOW_IMPLICIT_CONSTRUCTORS(Verifier); | 50 DISALLOW_IMPLICIT_CONSTRUCTORS(Verifier); |
51 }; | 51 }; |
52 | 52 |
53 } // namespace sandbox | 53 } // namespace sandbox |
54 | 54 |
55 #endif // SANDBOX_LINUX_SECCOMP_BPF_VERIFIER_H__ | 55 #endif // SANDBOX_LINUX_SECCOMP_BPF_VERIFIER_H__ |
OLD | NEW |