-
Notifications
You must be signed in to change notification settings - Fork 5
bpf: Skip bounds adjustment for conditional jumps on same scalar register #6274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpf: Skip bounds adjustment for conditional jumps on same scalar register #6274
Conversation
|
Upstream branch: ab01bfa |
|
Upstream branch: ab01bfa |
bbb1d28 to
144c891
Compare
|
Upstream branch: ab01bfa |
144c891 to
702b9f1
Compare
9a71dd4 to
e4f505a
Compare
|
Upstream branch: e6e10c5 |
702b9f1 to
7956482
Compare
e4f505a to
5119f01
Compare
…ster 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]>
Add test cases to verify the correctness of the BPF verifier's branch analysis when conditional jumps are performed on the same scalar register. And make sure that JGT does not trigger verifier BUG. Signed-off-by: KaFai Wan <[email protected]> Acked-by: Eduard Zingerman <[email protected]>
|
Upstream branch: 5dae745 |
7956482 to
c4353a9
Compare
|
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1018758 irrelevant now. Closing PR. |
Pull request for series with
subject: bpf: Skip bounds adjustment for conditional jumps on same scalar register
version: 4
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1018758