Commit d028f87
bpf: make the verifier tracks the "not equal" for regs
We can derive some new information for BPF_JNE in regs_refine_cond_op().
Take following code for example:
/* The type of "a" is u32 */
if (a > 0 && a < 100) {
/* the range of the register for a is [0, 99], not [1, 99],
* and will cause the following error:
*
* invalid zero-sized read
*
* as a can be 0.
*/
bpf_skb_store_bytes(skb, xx, xx, a, 0);
}
In the code above, "a > 0" will be compiled to "jmp xxx if a == 0". In the
TRUE branch, the dst_reg will be marked as known to 0. However, in the
fallthrough(FALSE) branch, the dst_reg will not be handled, which makes
the [min, max] for a is [0, 99], not [1, 99].
For BPF_JNE, we can reduce the range of the dst reg if the src reg is a
const and is exactly the edge of the dst reg.
Signed-off-by: Menglong Dong <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>
Acked-by: Shung-Hsi Yu <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>1 parent 1728df7 commit d028f87
1 file changed
+37
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14336 | 14336 | | |
14337 | 14337 | | |
14338 | 14338 | | |
14339 | | - | |
| 14339 | + | |
| 14340 | + | |
| 14341 | + | |
| 14342 | + | |
| 14343 | + | |
| 14344 | + | |
| 14345 | + | |
| 14346 | + | |
| 14347 | + | |
| 14348 | + | |
| 14349 | + | |
| 14350 | + | |
| 14351 | + | |
| 14352 | + | |
| 14353 | + | |
| 14354 | + | |
| 14355 | + | |
| 14356 | + | |
| 14357 | + | |
| 14358 | + | |
| 14359 | + | |
| 14360 | + | |
| 14361 | + | |
| 14362 | + | |
| 14363 | + | |
| 14364 | + | |
| 14365 | + | |
| 14366 | + | |
| 14367 | + | |
| 14368 | + | |
| 14369 | + | |
| 14370 | + | |
| 14371 | + | |
| 14372 | + | |
| 14373 | + | |
| 14374 | + | |
| 14375 | + | |
14340 | 14376 | | |
14341 | 14377 | | |
14342 | 14378 | | |
| |||
0 commit comments