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