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