Commit 2ed6cc7
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]>1 parent 9a71dd4 commit 2ed6cc7
1 file changed
+33
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15995 | 15995 | | |
15996 | 15996 | | |
15997 | 15997 | | |
| 15998 | + | |
| 15999 | + | |
15998 | 16000 | | |
15999 | 16001 | | |
16000 | 16002 | | |
| |||
16021 | 16023 | | |
16022 | 16024 | | |
16023 | 16025 | | |
| 16026 | + | |
| 16027 | + | |
16024 | 16028 | | |
16025 | 16029 | | |
16026 | 16030 | | |
| |||
16047 | 16051 | | |
16048 | 16052 | | |
16049 | 16053 | | |
| 16054 | + | |
| 16055 | + | |
| 16056 | + | |
| 16057 | + | |
| 16058 | + | |
| 16059 | + | |
16050 | 16060 | | |
16051 | 16061 | | |
16052 | 16062 | | |
| |||
16059 | 16069 | | |
16060 | 16070 | | |
16061 | 16071 | | |
| 16072 | + | |
| 16073 | + | |
16062 | 16074 | | |
16063 | 16075 | | |
16064 | 16076 | | |
16065 | 16077 | | |
16066 | 16078 | | |
16067 | 16079 | | |
| 16080 | + | |
| 16081 | + | |
16068 | 16082 | | |
16069 | 16083 | | |
16070 | 16084 | | |
16071 | 16085 | | |
16072 | 16086 | | |
16073 | 16087 | | |
| 16088 | + | |
| 16089 | + | |
16074 | 16090 | | |
16075 | 16091 | | |
16076 | 16092 | | |
16077 | 16093 | | |
16078 | 16094 | | |
16079 | 16095 | | |
| 16096 | + | |
| 16097 | + | |
16080 | 16098 | | |
16081 | 16099 | | |
16082 | 16100 | | |
16083 | 16101 | | |
16084 | 16102 | | |
16085 | 16103 | | |
| 16104 | + | |
| 16105 | + | |
16086 | 16106 | | |
16087 | 16107 | | |
16088 | 16108 | | |
16089 | 16109 | | |
16090 | 16110 | | |
16091 | 16111 | | |
| 16112 | + | |
| 16113 | + | |
16092 | 16114 | | |
16093 | 16115 | | |
16094 | 16116 | | |
16095 | 16117 | | |
16096 | 16118 | | |
16097 | 16119 | | |
| 16120 | + | |
| 16121 | + | |
16098 | 16122 | | |
16099 | 16123 | | |
16100 | 16124 | | |
16101 | 16125 | | |
16102 | 16126 | | |
16103 | 16127 | | |
| 16128 | + | |
| 16129 | + | |
16104 | 16130 | | |
16105 | 16131 | | |
16106 | 16132 | | |
| |||
16439 | 16465 | | |
16440 | 16466 | | |
16441 | 16467 | | |
| 16468 | + | |
| 16469 | + | |
| 16470 | + | |
| 16471 | + | |
| 16472 | + | |
| 16473 | + | |
| 16474 | + | |
16442 | 16475 | | |
16443 | 16476 | | |
16444 | 16477 | | |
| |||
0 commit comments