Commit e092992
bpf: Reject narrower access to pointer ctx fields
The following BPF program, simplified from a syzkaller repro, causes a
kernel warning:
r0 = *(u8 *)(r1 + 169);
exit;
With pointer field sk being at offset 168 in __sk_buff. This access is
detected as a narrower read in bpf_skb_is_valid_access because it
doesn't match offsetof(struct __sk_buff, sk). It is therefore allowed
and later proceeds to bpf_convert_ctx_access. Note that for the
"is_narrower_load" case in the convert_ctx_accesses(), the insn->off
is aligned, so the cnt may not be 0 because it matches the
offsetof(struct __sk_buff, sk) in the bpf_convert_ctx_access. However,
the target_size stays 0 and the verifier errors with a kernel warning:
verifier bug: error during ctx access conversion(1)
This patch fixes that to return a proper "invalid bpf_context access
off=X size=Y" error on the load instruction.
The same issue affects multiple other fields in context structures that
allow narrow access. Some other non-affected fields (for sk_msg,
sk_lookup, and sockopt) were also changed to use bpf_ctx_range_ptr for
consistency.
Note this syzkaller crash was reported in the "Closes" link below, which
used to be about a different bug, fixed in
commit fce7bd8 ("bpf/verifier: Handle BPF_LOAD_ACQ instructions
in insn_def_regno()"). Because syzbot somehow confused the two bugs,
the new crash and repro didn't get reported to the mailing list.
Fixes: f96da09 ("bpf: simplify narrower ctx access")
Fixes: 0df1a55 ("bpf: Warn on internal verifier errors")
Reported-by: syzbot+0ef84a7bdf5301d4cbec@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=0ef84a7bdf5301d4cbec
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://patch.msgid.link/3b8dcee67ff4296903351a974ddd9c4dca768b64.1753194596.git.paul.chaignon@gmail.com1 parent 17ce3e5 commit e092992
2 files changed
+14
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2440 | 2440 | | |
2441 | 2441 | | |
2442 | 2442 | | |
2443 | | - | |
| 2443 | + | |
2444 | 2444 | | |
2445 | 2445 | | |
2446 | 2446 | | |
2447 | 2447 | | |
2448 | | - | |
| 2448 | + | |
2449 | 2449 | | |
2450 | 2450 | | |
2451 | 2451 | | |
2452 | 2452 | | |
2453 | | - | |
| 2453 | + | |
2454 | 2454 | | |
2455 | 2455 | | |
2456 | 2456 | | |
2457 | 2457 | | |
2458 | | - | |
| 2458 | + | |
2459 | 2459 | | |
2460 | 2460 | | |
2461 | 2461 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8699 | 8699 | | |
8700 | 8700 | | |
8701 | 8701 | | |
8702 | | - | |
| 8702 | + | |
8703 | 8703 | | |
8704 | 8704 | | |
8705 | 8705 | | |
| |||
9277 | 9277 | | |
9278 | 9278 | | |
9279 | 9279 | | |
9280 | | - | |
| 9280 | + | |
9281 | 9281 | | |
9282 | 9282 | | |
9283 | 9283 | | |
| |||
9327 | 9327 | | |
9328 | 9328 | | |
9329 | 9329 | | |
9330 | | - | |
| 9330 | + | |
9331 | 9331 | | |
9332 | 9332 | | |
9333 | 9333 | | |
9334 | 9334 | | |
9335 | | - | |
| 9335 | + | |
9336 | 9336 | | |
9337 | 9337 | | |
9338 | 9338 | | |
9339 | 9339 | | |
9340 | | - | |
| 9340 | + | |
9341 | 9341 | | |
9342 | 9342 | | |
9343 | 9343 | | |
| |||
9346 | 9346 | | |
9347 | 9347 | | |
9348 | 9348 | | |
9349 | | - | |
| 9349 | + | |
9350 | 9350 | | |
9351 | 9351 | | |
9352 | 9352 | | |
| |||
9416 | 9416 | | |
9417 | 9417 | | |
9418 | 9418 | | |
9419 | | - | |
| 9419 | + | |
9420 | 9420 | | |
9421 | 9421 | | |
9422 | 9422 | | |
9423 | 9423 | | |
9424 | | - | |
| 9424 | + | |
9425 | 9425 | | |
9426 | 9426 | | |
9427 | 9427 | | |
9428 | 9428 | | |
9429 | | - | |
| 9429 | + | |
9430 | 9430 | | |
9431 | 9431 | | |
9432 | 9432 | | |
| |||
11632 | 11632 | | |
11633 | 11633 | | |
11634 | 11634 | | |
11635 | | - | |
| 11635 | + | |
11636 | 11636 | | |
11637 | 11637 | | |
11638 | 11638 | | |
| |||
0 commit comments