Commit 9f88b29
bpf: Support negative offsets, BPF_SUB, and alu32 for linked register tracking
[ Upstream commit 7a433e5 ]
Previously, the verifier only tracked positive constant deltas between
linked registers using BPF_ADD. This limitation meant patterns like:
r1 = r0;
r1 += -4;
if r1 s>= 0 goto l0_%=; // r1 >= 0 implies r0 >= 4
// verifier couldn't propagate bounds back to r0
if r0 != 0 goto l0_%=;
r0 /= 0; // Verifier thinks this is reachable
l0_%=:
Similar limitation exists for 32-bit registers.
With this change, the verifier can now track negative deltas in reg->off
enabling bound propagation for the above pattern.
For alu32, we make sure the destination register has the upper 32 bits
as 0s before creating the link. BPF_ADD_CONST is split into
BPF_ADD_CONST64 and BPF_ADD_CONST32, the latter is used in case of alu32
and sync_linked_regs uses this to zext the result if known_reg has this
flag.
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20260204151741.2678118-2-puranjay@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Stable-dep-of: d7f1417 ("bpf: Fix linked reg delta tracking when src_reg == dst_reg")
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 2546335 commit 9f88b29
3 files changed
Lines changed: 45 additions & 13 deletions
File tree
- include/linux
- kernel/bpf
- tools/testing/selftests/bpf/progs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
150 | 152 | | |
151 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
152 | 156 | | |
153 | 157 | | |
154 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15787 | 15787 | | |
15788 | 15788 | | |
15789 | 15789 | | |
| 15790 | + | |
| 15791 | + | |
| 15792 | + | |
| 15793 | + | |
| 15794 | + | |
| 15795 | + | |
| 15796 | + | |
15790 | 15797 | | |
15791 | 15798 | | |
15792 | 15799 | | |
| |||
15796 | 15803 | | |
15797 | 15804 | | |
15798 | 15805 | | |
15799 | | - | |
15800 | | - | |
| 15806 | + | |
| 15807 | + | |
15801 | 15808 | | |
15802 | 15809 | | |
15803 | | - | |
15804 | | - | |
15805 | | - | |
| 15810 | + | |
| 15811 | + | |
| 15812 | + | |
| 15813 | + | |
| 15814 | + | |
| 15815 | + | |
| 15816 | + | |
| 15817 | + | |
| 15818 | + | |
| 15819 | + | |
15806 | 15820 | | |
15807 | | - | |
15808 | | - | |
15809 | | - | |
| 15821 | + | |
| 15822 | + | |
| 15823 | + | |
| 15824 | + | |
| 15825 | + | |
| 15826 | + | |
| 15827 | + | |
| 15828 | + | |
| 15829 | + | |
| 15830 | + | |
15810 | 15831 | | |
15811 | 15832 | | |
15812 | 15833 | | |
15813 | 15834 | | |
| 15835 | + | |
15814 | 15836 | | |
15815 | 15837 | | |
15816 | 15838 | | |
15817 | | - | |
15818 | | - | |
| 15839 | + | |
| 15840 | + | |
| 15841 | + | |
| 15842 | + | |
| 15843 | + | |
15819 | 15844 | | |
15820 | 15845 | | |
15821 | 15846 | | |
| |||
16888 | 16913 | | |
16889 | 16914 | | |
16890 | 16915 | | |
16891 | | - | |
| 16916 | + | |
16892 | 16917 | | |
16893 | 16918 | | |
16894 | 16919 | | |
| |||
16903 | 16928 | | |
16904 | 16929 | | |
16905 | 16930 | | |
| 16931 | + | |
| 16932 | + | |
| 16933 | + | |
16906 | 16934 | | |
16907 | 16935 | | |
16908 | 16936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1477 | 1477 | | |
1478 | 1478 | | |
1479 | 1479 | | |
1480 | | - | |
| 1480 | + | |
1481 | 1481 | | |
1482 | 1482 | | |
1483 | 1483 | | |
| |||
0 commit comments