Netdev List
 help / color / mirror / Atom feed
* [PATCH net v9 0/6] xdp: fix page_pool leaks
@ 2026-11-27 10:01 Slawomir Stepien
  2026-11-27 10:01 ` [PATCH net v9 1/6] xdp: run generic XDP on frags with a copy of the rxq info Slawomir Stepien
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Slawomir Stepien @ 2026-11-27 10:01 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Stanislav Fomichev
  Cc: bpf, netdev, Jiayuan Chen, Dudu Lu, Maciej Fijalkowski,
	Tianyi Gao, Octavian Purdila, Toke Høiland-Jørgensen,
	Alexander Lobakin, Lorenzo Bianconi, Lorenzo Bianconi,
	Ihor Solodrai, Andrew Lunn, Willem de Bruijn, Simon Horman,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, Jiri Olsa, Kumar Kartikeya Dwivedi,
	Emil Tsalapatis, Shuah Khan, linux-kselftest, Slawomir Stepien

Hi,

when an XDP program shrinks a frag away with bpf_xdp_adjust_tail(),
bpf_xdp_shrink_data() frees it according to xdp->rxq->mem.type. Generic
XDP and veth copy skbs into page_pool memory with skb_pp_cow_data(), but
run the program with an rxq info that says MEM_TYPE_PAGE_SHARED, so a
page_pool page is freed with page_frag_free(). syzbot reports it as
"BUG: Bad page state ... page_pool leak", and it can end in a
use-after-free.

As Alexei suggested on v8, the program now runs with a copy of the rxq
info on the stack that has the right mem type, and nothing writes into
the shared rxq info any more. The diff is split per path, as the bugs
came with different commits:

- patch 1: generic XDP, non-linear skbs
- patch 2: test_run sets its frag_size on a copy instead of in lo's rxq
  info, which generic XDP on lo uses too
- patch 3: veth, xdp_frames: the frame's mem type, set before the
  program runs
- patch 4: veth, skbs: MEM_TYPE_PAGE_POOL
- patch 5: Jiayuan's selftest from [1], used with their permission,
  with two comments reworded for the on-stack rxq info; it frees
  page_pool frags on tun (generic XDP) and veth
- patch 6: selftests for patch 2

An skb that veth turns into a frame on XDP_TX or XDP_REDIRECT still
leaves as MEM_TYPE_PAGE_SHARED, as today, so its page_pool pages are
released instead of recycled. That is not a leak; recycling them comes
as a net-next follow-up (Maciej).

Thanks to Octavian and Maciej, who started this series, and to Jiayuan
[1] and Dudu [2], who posted fixes for the same bug.

Testing (x86_64, QEMU via virtme-ng, KASAN + DEBUG_VM + DEBUG_NET):
- without the fixes, xdp_shrink_frags reports "page_pool leak" for tun
  and veth, both subtests of patch 6 fail, and a reproducer that trims
  all frags of 8000-byte pings with generic XDP on a veth pair hits
  "page_pool leak", VM_BUG_ON_PAGE() in page_frag_free() and a panic
- with the series: ./test_progs -t ns_xsk,xdp passes (35 tests, 210
  subtests), no splats; the reproducers for generic XDP, native veth
  XDP, XDP_TX and frames trimmed by the peer show no splats
- full ./test_progs (same patches on bpf/master): the same failures as
  without the series
- not tested: page_pool frames from hardware drivers redirected into
  veth

v8->v9:
- target net (Alexei)
- replace patches 1-5 with Alexei's on-stack rxq info, split per path
  (Alexei)
- replace patch 6, which never freed a page_pool frag, with Jiayuan's
  selftest (Alexei)
- patch 6 (was 7): load the program of the ingress_ifindex subtest with
  a skeleton, and check that the program saw a packet with frags before
  checking the result of the grow
- the code is new, so Maciej's and Octavian's patches and Tianyi's
  Reviewed-by are gone

v8: https://lore.kernel.org/bpf/20261124104016.532341-1-sst@poczta.fm/
(links to v1-v7 are in its cover letter)

[1] https://lore.kernel.org/bpf/20260911135711.109338-1-jiayuan.chen@linux.dev/
[2] https://lore.kernel.org/bpf/20261021155645.69120-1-phx0fer@gmail.com/

This series was prepared with an AI coding assistant (Claude): the code
of patches 1-4 is Alexei's diff, which the assistant split and wrote
the commit messages for; it also wrote patch 6 and ran the tests.

Jiayuan Chen (1):
  selftests/bpf: add xdp_shrink_frags

Slawomir Stepien (5):
  xdp: run generic XDP on frags with a copy of the rxq info
  bpf: test_run: Set frag_size on a copy of the rxq info
  veth: use the frame mem type when running XDP on an xdp_frame
  veth: use the page_pool mem type when running XDP on an skb
  selftests/bpf: Grow test_run and generic XDP frags after a test run

 drivers/net/veth.c                            |  33 +-
 net/bpf/test_run.c                            |   9 +-
 net/core/dev.c                                |   9 +
 .../bpf/prog_tests/xdp_adjust_tail.c          | 137 +++++++++
 .../bpf/prog_tests/xdp_shrink_frags.c         | 288 ++++++++++++++++++
 .../test_xdp_adjust_frags_tail_grow_lo.c      |  25 ++
 .../selftests/bpf/progs/xdp_shrink_frags.c    |  34 +++
 7 files changed, 519 insertions(+), 16 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_shrink_frags.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_adjust_frags_tail_grow_lo.c
 create mode 100644 tools/testing/selftests/bpf/progs/xdp_shrink_frags.c


base-commit: e9e45fcb6d39bee9325e6a7dca72bd14e82760f3
-- 
2.56.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-28 10:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 10:01 [PATCH net v9 0/6] xdp: fix page_pool leaks Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 1/6] xdp: run generic XDP on frags with a copy of the rxq info Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 2/6] bpf: test_run: Set frag_size on " Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 3/6] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
2026-11-27 10:01 ` [PATCH net v9 4/6] veth: use the page_pool mem type when running XDP on an skb Slawomir Stepien
2026-11-28 10:03   ` netdev-bot+sashiko
2026-11-27 10:01 ` [PATCH net v9 5/6] selftests/bpf: add xdp_shrink_frags Slawomir Stepien
2026-11-28 10:04   ` netdev-bot+sashiko
2026-11-27 10:01 ` [PATCH net v9 6/6] selftests/bpf: Grow test_run and generic XDP frags after a test run Slawomir Stepien

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox