Commit e4ea6e3
selftests/bpf: Add verifier bounds checks for sign extension
This patch adds a new test cases to validate the improved register bounds
tracking logic.
We perform the sequence:
call bpf_get_prandom_u32;
r1 &= 0x100;
r1 = (s8)r1;
After the bitwise AND, `r1` is either 0 or 256 (0x100).
If 0: The lower 8 bits are 0.
If 256: The bit at index 8 is set, but the lower 8 bits are 0.
Since the cast to s8 only considers bits 0-7, the set bit at index 8 is
truncated. In both cases, the sign bit (bit 7) is 0, so the
result is exactly 0.
With the coercion logic before this series:
1: (bf) r1 = r0
; R0=scalar(id=1) R1=scalar(id=1)
2: (57) r1 &= 256
; R1=scalar(...,var_off=(0x0; 0x100))
3: (bf) r1 = (s8)r1
; R1=scalar(smin=smin32=-128,smax=smax32=127)
With our changes:
1: (bf) r1 = r0
; R0=scalar(id=1) R1=scalar(id=1)
2: (57) r1 &= 256
; R1=scalar(...,var_off=(0x0; 0x100))
3: (bf) r1 = (s8)r1
; R1=0
Signed-off-by: Dimitar Kanaliev <[email protected]>1 parent 92e98c7 commit e4ea6e3
1 file changed
+19
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
342 | 361 | | |
343 | 362 | | |
344 | 363 | | |
| |||
0 commit comments