~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/bpf_verifier.h

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.72 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of version 2 of the GNU General Public
  5  * License as published by the Free Software Foundation.
  6  */
  7 #ifndef _LINUX_BPF_VERIFIER_H
  8 #define _LINUX_BPF_VERIFIER_H 1
  9 
 10 #include <linux/bpf.h> /* for enum bpf_reg_type */
 11 #include <linux/filter.h> /* for MAX_BPF_STACK */
 12 
 13  /* Just some arbitrary values so we can safely do math without overflowing and
 14   * are obviously wrong for any sort of memory access.
 15   */
 16 #define BPF_REGISTER_MAX_RANGE (1024 * 1024 * 1024)
 17 #define BPF_REGISTER_MIN_RANGE -1
 18 
 19 struct bpf_reg_state {
 20         enum bpf_reg_type type;
 21         union {
 22                 /* valid when type == CONST_IMM | PTR_TO_STACK | UNKNOWN_VALUE */
 23                 s64 imm;
 24 
 25                 /* valid when type == PTR_TO_PACKET* */
 26                 struct {
 27                         u16 off;
 28                         u16 range;
 29                 };
 30 
 31                 /* valid when type == CONST_PTR_TO_MAP | PTR_TO_MAP_VALUE |
 32                  *   PTR_TO_MAP_VALUE_OR_NULL
 33                  */
 34                 struct bpf_map *map_ptr;
 35         };
 36         u32 id;
 37         /* Used to determine if any memory access using this register will
 38          * result in a bad access. These two fields must be last.
 39          * See states_equal()
 40          */
 41         s64 min_value;
 42         u64 max_value;
 43         u32 min_align;
 44         u32 aux_off;
 45         u32 aux_off_align;
 46         bool value_from_signed;
 47 };
 48 
 49 enum bpf_stack_slot_type {
 50         STACK_INVALID,    /* nothing was stored in this stack slot */
 51         STACK_SPILL,      /* register spilled into stack */
 52         STACK_MISC        /* BPF program wrote some data into this slot */
 53 };
 54 
 55 #define BPF_REG_SIZE 8  /* size of eBPF register in bytes */
 56 
 57 /* state of the program:
 58  * type of all registers and stack info
 59  */
 60 struct bpf_verifier_state {
 61         struct bpf_reg_state regs[MAX_BPF_REG];
 62         u8 stack_slot_type[MAX_BPF_STACK];
 63         struct bpf_reg_state spilled_regs[MAX_BPF_STACK / BPF_REG_SIZE];
 64 };
 65 
 66 /* linked list of verifier states used to prune search */
 67 struct bpf_verifier_state_list {
 68         struct bpf_verifier_state state;
 69         struct bpf_verifier_state_list *next;
 70 };
 71 
 72 struct bpf_insn_aux_data {
 73         union {
 74                 enum bpf_reg_type ptr_type;     /* pointer type for load/store insns */
 75                 struct bpf_map *map_ptr;        /* pointer for call insn into lookup_elem */
 76         };
 77 };
 78 
 79 #define MAX_USED_MAPS 64 /* max number of maps accessed by one eBPF program */
 80 
 81 struct bpf_verifier_env;
 82 struct bpf_ext_analyzer_ops {
 83         int (*insn_hook)(struct bpf_verifier_env *env,
 84                          int insn_idx, int prev_insn_idx);
 85 };
 86 
 87 /* single container for all structs
 88  * one verifier_env per bpf_check() call
 89  */
 90 struct bpf_verifier_env {
 91         struct bpf_prog *prog;          /* eBPF program being verified */
 92         struct bpf_verifier_stack_elem *head; /* stack of verifier states to be processed */
 93         int stack_size;                 /* number of states to be processed */
 94         bool strict_alignment;          /* perform strict pointer alignment checks */
 95         struct bpf_verifier_state cur_state; /* current verifier state */
 96         struct bpf_verifier_state_list **explored_states; /* search pruning optimization */
 97         const struct bpf_ext_analyzer_ops *analyzer_ops; /* external analyzer ops */
 98         void *analyzer_priv; /* pointer to external analyzer's private data */
 99         struct bpf_map *used_maps[MAX_USED_MAPS]; /* array of map's used by eBPF program */
100         u32 used_map_cnt;               /* number of used maps */
101         u32 id_gen;                     /* used to generate unique reg IDs */
102         bool allow_ptr_leaks;
103         bool seen_direct_write;
104         bool varlen_map_value_access;
105         struct bpf_insn_aux_data *insn_aux_data; /* array of per-insn state */
106 };
107 
108 int bpf_analyzer(struct bpf_prog *prog, const struct bpf_ext_analyzer_ops *ops,
109                  void *priv);
110 
111 #endif /* _LINUX_BPF_VERIFIER_H */
112 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp