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