Commit 12c5caf
xdp: introduce xdp_convert_skb_to_buff()
Currently, generic XDP hook uses xdp_rxq_info from netstack Rx queues
which do not have its XDP memory model registered. There is a case when
XDP program calls bpf_xdp_adjust_tail() BPF helper, which in turn
releases underlying memory. This happens when it consumes enough amount
of bytes and when XDP buffer has fragments. For this action the memory
model knowledge passed to XDP program is crucial so that core can call
suitable function for freeing/recycling the page.
For netstack queues it defaults to MEM_TYPE_PAGE_SHARED (0) due to lack
of mem model registration. The problem we're fixing here is when kernel
copied the skb to new buffer backed by system's page_pool and XDP buffer
is built around it. Then when bpf_xdp_adjust_tail() calls
__xdp_return(), it acts incorrectly due to mem type not being set to
MEM_TYPE_PAGE_POOL and causes a page leak.
Pull out the existing code from bpf_prog_run_generic_xdp() that
init/prepares xdp_buff onto new helper xdp_convert_skb_to_buff() and
embed there rxq's mem_type initialization that is assigned to xdp_buff.
Make it agnostic to current skb->data position.
This problem was triggered by syzbot as well as AF_XDP test suite which
is about to be integrated to BPF CI.
Reported-by: [email protected]
Closes: https://lore.kernel.org/netdev/[email protected]/
Fixes: e6d5dbd ("xdp: add multi-buff support for xdp running in generic mode")
Tested-by: Ihor Solodrai <[email protected]>
Co-developed-by: Octavian Purdila <[email protected]>
Signed-off-by: Octavian Purdila <[email protected]> # whole analysis, testing, initiating a fix
Signed-off-by: Maciej Fijalkowski <[email protected]> # commit msg and proposed more robust fix
Reviewed-by: Toke Høiland-Jørgensen <[email protected]>1 parent 87c66e9 commit 12c5caf
2 files changed
+29
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
387 | 412 | | |
388 | 413 | | |
389 | 414 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5320 | 5320 | | |
5321 | 5321 | | |
5322 | 5322 | | |
5323 | | - | |
| 5323 | + | |
5324 | 5324 | | |
5325 | 5325 | | |
5326 | | - | |
| 5326 | + | |
5327 | 5327 | | |
5328 | 5328 | | |
5329 | | - | |
5330 | 5329 | | |
5331 | 5330 | | |
5332 | | - | |
5333 | | - | |
5334 | | - | |
| 5331 | + | |
5335 | 5332 | | |
5336 | | - | |
5337 | | - | |
5338 | | - | |
5339 | | - | |
5340 | | - | |
5341 | 5333 | | |
5342 | | - | |
5343 | | - | |
5344 | | - | |
5345 | | - | |
5346 | | - | |
5347 | | - | |
5348 | | - | |
5349 | | - | |
5350 | | - | |
5351 | | - | |
| 5334 | + | |
5352 | 5335 | | |
5353 | 5336 | | |
5354 | 5337 | | |
| |||
0 commit comments