Skip to content

Commit 407958a

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
bpf: encapsulate precision backtracking bookkeeping
Add struct backtrack_state and straightforward API around it to keep track of register and stack masks used and maintained during precision backtracking process. Having this logic separately allow to keep high-level backtracking algorithm cleaner, but also it sets us up to cleanly keep track of register and stack masks per frame, allowing (with some further logic adjustments) to perform precision backpropagation across multiple frames (i.e., subprog calls). Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20230505043317.3629845-4-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent e0bf462 commit 407958a

2 files changed

Lines changed: 196 additions & 67 deletions

File tree

include/linux/bpf_verifier.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ enum bpf_stack_slot_type {
238238

239239
#define BPF_REG_SIZE 8 /* size of eBPF register in bytes */
240240

241+
#define BPF_REGMASK_ARGS ((1 << BPF_REG_1) | (1 << BPF_REG_2) | \
242+
(1 << BPF_REG_3) | (1 << BPF_REG_4) | \
243+
(1 << BPF_REG_5))
244+
241245
#define BPF_DYNPTR_SIZE sizeof(struct bpf_dynptr_kern)
242246
#define BPF_DYNPTR_NR_SLOTS (BPF_DYNPTR_SIZE / BPF_REG_SIZE)
243247

@@ -541,6 +545,15 @@ struct bpf_subprog_info {
541545
bool is_async_cb;
542546
};
543547

548+
struct bpf_verifier_env;
549+
550+
struct backtrack_state {
551+
struct bpf_verifier_env *env;
552+
u32 frame;
553+
u32 reg_masks[MAX_CALL_FRAMES];
554+
u64 stack_masks[MAX_CALL_FRAMES];
555+
};
556+
544557
/* single container for all structs
545558
* one verifier_env per bpf_check() call
546559
*/
@@ -578,6 +591,7 @@ struct bpf_verifier_env {
578591
int *insn_stack;
579592
int cur_stack;
580593
} cfg;
594+
struct backtrack_state bt;
581595
u32 pass_cnt; /* number of times do_check() was called */
582596
u32 subprog_cnt;
583597
/* number of instructions analyzed by the verifier */

0 commit comments

Comments
 (0)