Commit 261c4a5
bpf: Skip bounds adjustment for conditional jumps on same scalar register
When conditional jumps are performed on the same scalar register
(e.g., r0 <= r0, r0 > r0, r0 < r0), the BPF verifier incorrectly
attempts to adjust the register's min/max bounds. This leads to
invalid range bounds and triggers a BUG warning.
The problematic BPF program:
0: call bpf_get_prandom_u32
1: w8 = 0x80000000
2: r0 &= r8
3: if r0 > r0 goto <exit>
The instruction 3 triggers kernel warning:
3: if r0 > r0 goto <exit>
true_reg1: range bounds violation u64=[0x1, 0x0] s64=[0x1, 0x0] u32=[0x1, 0x0] s32=[0x1, 0x0] var_off=(0x0, 0x0)
true_reg2: const tnum out of sync with range bounds u64=[0x0, 0xffffffffffffffff] s64=[0x8000000000000000, 0x7fffffffffffffff] var_off=(0x0, 0x0)
Comparing a register with itself should not change its bounds and
for most comparison operations, comparing a register with itself has
a known result (e.g., r0 == r0 is always true, r0 < r0 is always false).
Fix this by:
1. Enhance is_scalar_branch_taken() to properly handle branch direction
computation for same register comparisons across all BPF jump operations
2. Adds early return in reg_set_min_max() to avoid bounds adjustment
for unknown branch directions (e.g., BPF_JSET) on the same register
The fix ensures that unnecessary bounds adjustments are skipped, preventing
the verifier bug while maintaining correct branch direction analysis.
Reported-by: Kaiyan Mei <[email protected]>
Reported-by: Yinhao Hu <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: KaFai Wan <[email protected]>
Acked-by: Eduard Zingerman <[email protected]>1 parent 9a71dd4 commit 261c4a5
1 file changed
+31
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15993 | 15993 | | |
15994 | 15994 | | |
15995 | 15995 | | |
| 15996 | + | |
| 15997 | + | |
| 15998 | + | |
| 15999 | + | |
| 16000 | + | |
| 16001 | + | |
| 16002 | + | |
| 16003 | + | |
| 16004 | + | |
| 16005 | + | |
| 16006 | + | |
| 16007 | + | |
| 16008 | + | |
| 16009 | + | |
| 16010 | + | |
| 16011 | + | |
| 16012 | + | |
| 16013 | + | |
| 16014 | + | |
| 16015 | + | |
| 16016 | + | |
| 16017 | + | |
| 16018 | + | |
| 16019 | + | |
15996 | 16020 | | |
15997 | 16021 | | |
15998 | 16022 | | |
| |||
16439 | 16463 | | |
16440 | 16464 | | |
16441 | 16465 | | |
| 16466 | + | |
| 16467 | + | |
| 16468 | + | |
| 16469 | + | |
| 16470 | + | |
| 16471 | + | |
| 16472 | + | |
16442 | 16473 | | |
16443 | 16474 | | |
16444 | 16475 | | |
| |||
0 commit comments