selftests/bpf: Add tests with stack ptr register in conditional jmp
PATCH 1/1 selftests/bpf: Add tests with stack ptr register in conditional jmp
From: Yonghong Song <[email protected]>
Commit 5ffb537e416ee22dbfb3d552102e50da33fec7f6 upstream.
Add two tests:
- one test has 'rX <op> r10' where rX is not r10, and
- another test has 'rX <op> rY' where rX and rY are not r10 but there is an early insn 'rX = r10'.
Without previous verifier change, both tests will fail.
[ shung-hsi.yu: contains additional hunks for kernel/bpf/verifier.c that
should be part of the previous patch in the series, commit e2d2115e56c4 "bpf: Do not include stack ptr register in precision backtracking bookkeeping", which already incorporated. ]
---
Verified that newly added test passes in 6.15.y[1] as well as 6.12.y[2]
1: https://github.com/shunghsiyu/libbpf/actions/runs/16561115937/job/46830912531
2: https://github.com/shunghsiyu/libbpf/actions/runs/16561115937/job/46830912533
--- kernel/bpf/verifier.c | 7 ++- .../selftests/bpf/progs/verifier_precision.c | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +5 -2
@@ -15480,6 +15480,8 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,if (src_reg->type ==PTR_TO_STACK ) insn_flags |=INSN_F_SRC_REG_STACK ; +if (dst_reg->type ==PTR_TO_STACK ) + insn_flags |=INSN_F_DST_REG_STACK ; }else {if (insn->src_reg !=BPF_REG_0 ) {verbose (env,"BPF_JMP/JMP32 uses reserved fields\n" );
@@ -15489,10 +15491,11 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,memset (src_reg,0 ,sizeof (*src_reg)); src_reg->type =SCALAR_VALUE ;__mark_reg_known (src_reg, insn->imm); + +if (dst_reg->type ==PTR_TO_STACK ) + insn_flags |=INSN_F_DST_REG_STACK ; } -if (dst_reg->type ==PTR_TO_STACK ) - insn_flags |=INSN_F_DST_REG_STACK ;if (insn_flags) { err =push_insn_history (env, this_branch, insn_flags,0 );if (err)
tools/testing/selftests/bpf/progs/verifier_precision.c +53 -0
57 lines not on this page · raw message
Signature · 1 line
2.50.1
Sasha Levin
maintainer[ Sasha's backport helper bot ]
Hi,
✅ All tests passed successfully. No issues detected. No action required from the submitter.
The upstream commit SHA1 provided is correct: 5ffb537e416ee22dbfb3d552102e50da33fec7f6
WARNING: Author mismatch between patch and upstream commit:
Backport author: Shung-Hsi Yu <[email protected]> Commit author: Yonghong Song <[email protected]>
Note: The patch differs from the upstream commit:
---
1: 5ffb537e416e ! 1: 0812c73da513 selftests/bpf: Add tests with stack ptr register in conditional jmp
@@ Metadata
## Commit message ##
selftests/bpf: Add tests with stack ptr register in conditional jmp
+ Commit 5ffb537e416ee22dbfb3d552102e50da33fec7f6 upstream.
+
Add two tests:
- one test has 'rX <op> r10' where rX is not r10, and
- another test has 'rX <op> rY' where rX and rY are not r10
@@ Commit message
+ [ shung-hsi.yu: contains additional hunks for kernel/bpf/verifier.c that
+ should be part of the previous patch in the series, commit
+ e2d2115e56c4 "bpf: Do not include stack ptr register in precision
+ backtracking bookkeeping", which already incorporated. ]
+ Link: https://lore.kernel.org/all/[email protected]/
+ Signed-off-by: Shung-Hsi Yu <[email protected]>
## kernel/bpf/verifier.c ##
@@ kernel/bpf/verifier.c: static int check_cond_jmp_op(struct bpf_verifier_env *env,
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | 6.15 | Success | Success | | 6.12 | Success | Success |