Commit fd4cfa8
bpf: Reject negative const offsets for buffer pointers
The verifier rejects variable offsets for PTR_TO_TP_BUFFER and PTR_TO_BUF
accesses, but it currently accepts a constant negative offset produced by
pointer arithmetic.
Commit 022ac07 ("bpf: use reg->var_off instead of reg->off for
pointers") moved constant pointer offsets from reg->off to reg->var_off.
However, __check_buffer_access() continued to check only the instruction
offset. An access with reg->var_off equal to -8 and an instruction offset
of zero therefore passes verification.
For writable raw tracepoints, the access end is also calculated from the
unsigned reg->var_off.value. An eight-byte access starting at -8 wraps
the calculated end to zero, allowing the program to load and attach
without increasing max_tp_access.
After ensuring that reg->var_off is constant, calculate the effective
access start using signed arithmetic and reject it when it is negative.
Use the validated start to calculate the access end for both
PTR_TO_TP_BUFFER and PTR_TO_BUF.
Fixes: 022ac07 ("bpf: use reg->var_off instead of reg->off for pointers")
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Cc: stable@vger.kernel.org # 5.2.0
Link: https://patch.msgid.link/20260714093846.18159-2-sun.jian.kdev@gmail.com
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>1 parent 2d8af4e commit fd4cfa8
1 file changed
Lines changed: 19 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5326 | 5326 | | |
5327 | 5327 | | |
5328 | 5328 | | |
5329 | | - | |
| 5329 | + | |
| 5330 | + | |
5330 | 5331 | | |
5331 | | - | |
5332 | | - | |
5333 | | - | |
5334 | | - | |
5335 | | - | |
5336 | | - | |
| 5332 | + | |
| 5333 | + | |
5337 | 5334 | | |
5338 | 5335 | | |
5339 | 5336 | | |
| |||
5344 | 5341 | | |
5345 | 5342 | | |
5346 | 5343 | | |
| 5344 | + | |
| 5345 | + | |
| 5346 | + | |
| 5347 | + | |
| 5348 | + | |
| 5349 | + | |
| 5350 | + | |
| 5351 | + | |
| 5352 | + | |
5347 | 5353 | | |
5348 | 5354 | | |
5349 | 5355 | | |
5350 | 5356 | | |
5351 | 5357 | | |
5352 | 5358 | | |
5353 | 5359 | | |
| 5360 | + | |
5354 | 5361 | | |
5355 | 5362 | | |
5356 | | - | |
| 5363 | + | |
5357 | 5364 | | |
5358 | 5365 | | |
5359 | 5366 | | |
5360 | | - | |
5361 | | - | |
| 5367 | + | |
5362 | 5368 | | |
5363 | 5369 | | |
5364 | 5370 | | |
| |||
5370 | 5376 | | |
5371 | 5377 | | |
5372 | 5378 | | |
| 5379 | + | |
5373 | 5380 | | |
5374 | 5381 | | |
5375 | | - | |
| 5382 | + | |
5376 | 5383 | | |
5377 | 5384 | | |
5378 | 5385 | | |
5379 | | - | |
| 5386 | + | |
5380 | 5387 | | |
5381 | 5388 | | |
5382 | 5389 | | |
| |||
0 commit comments