kernel/bpf/verifier.c
Source file repositories/reference/linux-study-clean/kernel/bpf/verifier.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/verifier.c- Extension
.c- Size
- 593718 bytes
- Lines
- 20001
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
uapi/linux/btf.hlinux/bpf-cgroup.hlinux/kernel.hlinux/types.hlinux/slab.hlinux/bpf.hlinux/btf.hlinux/bpf_verifier.hlinux/filter.hnet/netlink.hlinux/file.hlinux/vmalloc.hlinux/stringify.hlinux/bsearch.hlinux/sort.hlinux/perf_event.hlinux/ctype.hlinux/error-injection.hlinux/bpf_lsm.hlinux/btf_ids.hlinux/poison.hlinux/module.hlinux/cpumask.hlinux/cnum.hlinux/bpf_mem_alloc.hnet/xdp.hlinux/trace_events.hlinux/kallsyms.hdisasm.hlinux/bpf_types.h
Detected Declarations
struct bpf_verifier_stack_elemstruct bpf_call_arg_metastruct bpf_kfunc_metastruct bpf_kfunc_btfstruct bpf_kfunc_btf_tabstruct linked_regstruct linked_regsstruct bpf_subprog_call_depth_infostruct bpf_reg_typesstruct bpf_sanitize_infoenum bpf_featuresenum bpf_access_srcenum kfunc_ptr_arg_typeenum special_kfunc_typefunction bpf_map_ptr_storefunction bpf_map_key_storefunction update_ref_objfunction validate_ref_objfunction argno_from_regfunction argno_from_argfunction reg_from_argnofunction arg_from_argnofunction arg_idx_from_argnofunction verbose_invalid_scalarfunction reg_not_nullfunction bpf_subprog_is_globalfunction subprog_returns_voidfunction bpf_mark_subprog_exc_cbfunction subprog_is_exc_cbfunction reg_may_point_to_spin_lockfunction type_is_rdonly_memfunction is_acquire_functionfunction is_ptr_cast_functionfunction is_sync_callback_calling_functionfunction is_async_callback_calling_functionfunction is_callback_calling_functionfunction bpf_is_sync_callback_calling_insnfunction bpf_is_async_callback_calling_insnfunction is_async_cb_sleepablefunction bpf_is_may_goto_insnfunction is_spi_bounds_validfunction stack_slot_obj_get_spifunction dynptr_get_spifunction iter_get_spifunction irq_flag_get_spifunction arg_to_dynptr_typefunction get_dynptr_type_flagfunction dynptr_type_referenced
Annotated Snippet
struct bpf_verifier_stack_elem {
/* verifier state is 'st'
* before processing instruction 'insn_idx'
* and after processing instruction 'prev_insn_idx'
*/
struct bpf_verifier_state st;
int insn_idx;
int prev_insn_idx;
struct bpf_verifier_stack_elem *next;
/* length of verifier log at the time this state was pushed on stack */
u32 log_pos;
};
#define BPF_COMPLEXITY_LIMIT_JMP_SEQ 8192
#define BPF_COMPLEXITY_LIMIT_STATES 64
#define BPF_GLOBAL_PERCPU_MA_MAX_SIZE 512
#define BPF_PRIV_STACK_MIN_SIZE 64
static int acquire_reference(struct bpf_verifier_env *env, int insn_idx, int parent_id);
static int release_reference_nomark(struct bpf_verifier_state *state, int id);
static int release_reference(struct bpf_verifier_env *env, int id);
static void invalidate_non_owning_refs(struct bpf_verifier_env *env);
static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env);
static bool is_tracing_prog_type(enum bpf_prog_type type);
static int ref_set_non_owning(struct bpf_verifier_env *env,
struct bpf_reg_state *reg);
static bool is_trusted_reg(struct bpf_verifier_env *env, const struct bpf_reg_state *reg);
static inline bool in_sleepable_context(struct bpf_verifier_env *env);
static const char *non_sleepable_context_description(struct bpf_verifier_env *env);
static void scalar32_min_max_add(struct bpf_reg_state *dst_reg, struct bpf_reg_state *src_reg);
static void scalar_min_max_add(struct bpf_reg_state *dst_reg, struct bpf_reg_state *src_reg);
static void bpf_map_ptr_store(struct bpf_insn_aux_data *aux,
struct bpf_map *map,
bool unpriv, bool poison)
{
unpriv |= bpf_map_ptr_unpriv(aux);
aux->map_ptr_state.unpriv = unpriv;
aux->map_ptr_state.poison = poison;
aux->map_ptr_state.map_ptr = map;
}
static void bpf_map_key_store(struct bpf_insn_aux_data *aux, u64 state)
{
bool poisoned = bpf_map_key_poisoned(aux);
aux->map_key_state = state | BPF_MAP_KEY_SEEN |
(poisoned ? BPF_MAP_KEY_POISON : 0ULL);
}
static void update_ref_obj(struct ref_obj_desc *ref_obj, struct bpf_reg_state *reg)
{
ref_obj->id = reg->id;
ref_obj->parent_id = reg->parent_id;
ref_obj->cnt++;
}
static int validate_ref_obj(struct bpf_verifier_env *env, struct ref_obj_desc *ref_obj)
{
if (ref_obj->cnt > 1) {
verifier_bug(env, "function expects only one referenced object but got %d\n",
ref_obj->cnt);
return -EFAULT;
}
return 0;
}
struct bpf_call_arg_meta {
struct bpf_map_desc map;
struct bpf_dynptr_desc dynptr;
struct ref_obj_desc ref_obj;
bool raw_mode;
bool pkt_access;
u8 release_regno;
int regno;
int access_size;
int mem_size;
u64 msize_max_value;
int func_id;
struct btf *btf;
u32 btf_id;
struct btf *ret_btf;
u32 ret_btf_id;
u32 subprogno;
struct btf_field *kptr_field;
s64 const_map_key;
};
Annotation
- Immediate include surface: `uapi/linux/btf.h`, `linux/bpf-cgroup.h`, `linux/kernel.h`, `linux/types.h`, `linux/slab.h`, `linux/bpf.h`, `linux/btf.h`, `linux/bpf_verifier.h`.
- Detected declarations: `struct bpf_verifier_stack_elem`, `struct bpf_call_arg_meta`, `struct bpf_kfunc_meta`, `struct bpf_kfunc_btf`, `struct bpf_kfunc_btf_tab`, `struct linked_reg`, `struct linked_regs`, `struct bpf_subprog_call_depth_info`, `struct bpf_reg_types`, `struct bpf_sanitize_info`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.