[PATCH stable 6.6.y v2 3/3] selftests/bpf: add helper retval linked scalar pruning test

From: Zhenzhong Wu

Date: Sun Jun 07 2026 - 13:14:10 EST


Add a verifier test case covering a pruning bug where a helper return
value and another scalar become linked by scalar id on one path. A later
branch can then let the verifier explore an impossible continuation and
prune the real success path.

The test uses bpf_skb_load_bytes() to create a helper return value in R0
and a scalar derived from the tc test packet length. It then links the two
scalars on one path and checks that the later branch keeps the reachable
success path.

Signed-off-by: Zhenzhong Wu <jt26wzz@xxxxxxxxx>
---
.../selftests/bpf/progs/verifier_reg_equal.c | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/verifier_reg_equal.c b/tools/testing/selftests/bpf/progs/verifier_reg_equal.c
index dc1d8c30f..269b2af50 100644
--- a/tools/testing/selftests/bpf/progs/verifier_reg_equal.c
+++ b/tools/testing/selftests/bpf/progs/verifier_reg_equal.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/bpf.h>
+#include <stddef.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

@@ -55,4 +56,38 @@ l1_%=: exit; \
: __clobber_all);
}

+SEC("tc")
+__description("helper retval linked scalar pruning")
+__success __retval(0)
+__naked void helper_retval_linked_scalar_pruning(void)
+{
+ asm volatile (" \
+ r7 = *(u32 *)(r1 + %[__sk_buff_data_end]); \
+ r5 = *(u32 *)(r1 + %[__sk_buff_data]); \
+ r7 -= r5; \
+ r2 = 0; \
+ r3 = r10; \
+ r3 += -8; \
+ r4 = 1; \
+ call %[bpf_skb_load_bytes]; \
+ r6 = 1; \
+ if r0 == 0 goto l0_%=; \
+ r7 = r0; \
+l0_%=: if r0 != 0 goto l1_%=; \
+ r7 <<= 32; \
+ r7 >>= 32; \
+ r6 = 1; \
+ if r7 != %[test_data_len] goto l1_%=; \
+ r0 = 0; \
+ exit; \
+l1_%=: r0 = r6; \
+ exit; \
+" :
+ : __imm(bpf_skb_load_bytes),
+ __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
+ __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end)),
+ __imm_const(test_data_len, TEST_DATA_LEN)
+ : __clobber_all);
+}
+
char _license[] SEC("license") = "GPL";
--
2.43.0