regsafe() currently requires an exact match for PTR_TO_STACK registers. This prevents an explored state from pruning a current state whose variable-offset range is a subset of the explored range. This change allows a checkpoint containing a widened stack pointer to cover narrower offsets reached on subsequent loop iterations, for example [-56, -8] within [-64, -8]. Signed-off-by: Eduard Zingerman --- kernel/bpf/states.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c index 18bf7b660c2f..29d18520d27c 100644 --- a/kernel/bpf/states.c +++ b/kernel/bpf/states.c @@ -644,7 +644,12 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold, return range_within(rold, rcur) && tnum_in(rold->var_off, rcur->var_off); case PTR_TO_STACK: - return regs_exact(rold, rcur, idmap); + return memcmp(rold, rcur, offsetof(struct bpf_reg_state, var_off)) == 0 && + range_within(rold, rcur) && + tnum_in(rold->var_off, rcur->var_off) && + check_ids(rold->id, rcur->id, idmap) && + check_ids(rold->parent_id, rcur->parent_id, idmap) && + rold->frameno == rcur->frameno; case PTR_TO_ARENA: return true; case PTR_TO_INSN: -- 2.55.0