Commit 7a433e5
bpf: Support negative offsets, BPF_SUB, and alu32 for linked register tracking
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>1 parent b282131 commit 7a433e5
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 | |
|---|---|---|---|
| |||
16209 | 16209 | | |
16210 | 16210 | | |
16211 | 16211 | | |
| 16212 | + | |
| 16213 | + | |
| 16214 | + | |
| 16215 | + | |
| 16216 | + | |
| 16217 | + | |
| 16218 | + | |
16212 | 16219 | | |
16213 | 16220 | | |
16214 | 16221 | | |
| |||
16218 | 16225 | | |
16219 | 16226 | | |
16220 | 16227 | | |
16221 | | - | |
16222 | | - | |
| 16228 | + | |
| 16229 | + | |
16223 | 16230 | | |
16224 | 16231 | | |
16225 | | - | |
16226 | | - | |
16227 | | - | |
| 16232 | + | |
| 16233 | + | |
| 16234 | + | |
| 16235 | + | |
| 16236 | + | |
| 16237 | + | |
| 16238 | + | |
| 16239 | + | |
| 16240 | + | |
| 16241 | + | |
16228 | 16242 | | |
16229 | | - | |
16230 | | - | |
16231 | | - | |
| 16243 | + | |
| 16244 | + | |
| 16245 | + | |
| 16246 | + | |
| 16247 | + | |
| 16248 | + | |
| 16249 | + | |
| 16250 | + | |
| 16251 | + | |
| 16252 | + | |
16232 | 16253 | | |
16233 | 16254 | | |
16234 | 16255 | | |
16235 | 16256 | | |
| 16257 | + | |
16236 | 16258 | | |
16237 | 16259 | | |
16238 | 16260 | | |
16239 | | - | |
16240 | | - | |
| 16261 | + | |
| 16262 | + | |
| 16263 | + | |
| 16264 | + | |
| 16265 | + | |
16241 | 16266 | | |
16242 | 16267 | | |
16243 | 16268 | | |
| |||
17334 | 17359 | | |
17335 | 17360 | | |
17336 | 17361 | | |
17337 | | - | |
| 17362 | + | |
17338 | 17363 | | |
17339 | 17364 | | |
17340 | 17365 | | |
| |||
17349 | 17374 | | |
17350 | 17375 | | |
17351 | 17376 | | |
| 17377 | + | |
| 17378 | + | |
| 17379 | + | |
17352 | 17380 | | |
17353 | 17381 | | |
17354 | 17382 | | |
| |||
| 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