123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #ifndef _LINUX_BPF_VERIFIER_H
- #define _LINUX_BPF_VERIFIER_H 1
- #include <linux/bpf.h> /* for enum bpf_reg_type */
- #include <linux/filter.h> /* for MAX_BPF_STACK */
-
- #define BPF_REGISTER_MAX_RANGE (1024 * 1024 * 1024)
- #define BPF_REGISTER_MIN_RANGE -1
- struct bpf_reg_state {
- enum bpf_reg_type type;
- union {
-
- s64 imm;
-
- struct {
- u16 off;
- u16 range;
- };
-
- struct bpf_map *map_ptr;
- };
- u32 id;
-
- s64 min_value;
- u64 max_value;
- bool value_from_signed;
- };
- enum bpf_stack_slot_type {
- STACK_INVALID,
- STACK_SPILL,
- STACK_MISC
- };
- #define BPF_REG_SIZE 8
- struct bpf_verifier_state {
- struct bpf_reg_state regs[MAX_BPF_REG];
- u8 stack_slot_type[MAX_BPF_STACK];
- struct bpf_reg_state spilled_regs[MAX_BPF_STACK / BPF_REG_SIZE];
- };
- struct bpf_verifier_state_list {
- struct bpf_verifier_state state;
- struct bpf_verifier_state_list *next;
- };
- struct bpf_insn_aux_data {
- enum bpf_reg_type ptr_type;
- };
- #define MAX_USED_MAPS 64
- struct bpf_verifier_env;
- struct bpf_ext_analyzer_ops {
- int (*insn_hook)(struct bpf_verifier_env *env,
- int insn_idx, int prev_insn_idx);
- };
- struct bpf_verifier_env {
- struct bpf_prog *prog;
- struct bpf_verifier_stack_elem *head;
- int stack_size;
- struct bpf_verifier_state cur_state;
- struct bpf_verifier_state_list **explored_states;
- const struct bpf_ext_analyzer_ops *analyzer_ops;
- void *analyzer_priv;
- struct bpf_map *used_maps[MAX_USED_MAPS];
- u32 used_map_cnt;
- u32 id_gen;
- bool allow_ptr_leaks;
- bool seen_direct_write;
- bool varlen_map_value_access;
- struct bpf_insn_aux_data *insn_aux_data;
- };
- int bpf_analyzer(struct bpf_prog *prog, const struct bpf_ext_analyzer_ops *ops,
- void *priv);
- #endif
|