Netdev List
 help / color / mirror / Atom feed
* [PATCH net v6 0/2] xsk, xdp: fix ZC buffer double free on failed redirect
@ 2026-12-04 19:39 Maciej Fijalkowski
  2026-12-04 19:39 ` [PATCH net v6 1/2] xsk: Do not free ZC Rx buffer when the Rx ring is full Maciej Fijalkowski
  2026-12-04 19:39 ` [PATCH net v6 2/2] xdp: Do not free ZC buffer when a frame redirect fails Maciej Fijalkowski
  0 siblings, 2 replies; 5+ messages in thread
From: Maciej Fijalkowski @ 2026-12-04 19:39 UTC (permalink / raw)
  To: netdev, kuba, pabeni, magnus.karlsson, sdf, ast, daniel, hawk,
	john.fastabend, jtollet, willemb, andrii, eddyz87, memxor
  Cc: bpf, bjorn, kerneljasonxing, marcin.knap, joshwash, hramamurthy,
	sgoutham, martin.lau, song, yonghong.song, jolsa, emil,
	ihor.solodrai, toke, hangbin.liu

Changes in v6:
v5: https://lore.kernel.org/all/20261113-xsk-zc-rx-double-free-v5-1-6ead3af4d131@vecima.com/
- Add patch 2 for the devmap, cpumap and ifindex paths (Jakub).
- Patch 1: update the changelog paragraph about the devmap path, which
  patch 2 now fixes. No code changes, rebased on current net.

Hi,

A failed xdp_do_redirect() leaves a zero-copy buffer with the driver,
which then frees it. Two paths in the core free the buffer themselves
before failing:

- xsk_rcv_zc(), when the Rx ring of the target XSK is full;
- xdp_convert_zc_to_xdp_frame(), which copies the buffer for a devmap,
  cpumap or ifindex target and frees it before the redirect of the
  copy can still fail. The copy then leaks as well.

The second free is harmless when the driver frees the buffer right
away, as xp_free() skips a buffer that is already on the pool free
list. It corrupts the pool when the driver frees it later, after the
buffer may have been handed out again, as mlx5e does on Rx WQE refill.

Marcin's patch 1 fixes the first path, and its v1 to v5 were posted on
their own. Jakub asked for all redirect targets to be fixed in one
series [0], and with Marcin away I took it over [1].

Patch 1 is Marcin's v5 without code changes. I only updated the
paragraph about the devmap path in its changelog, as patch 2 fixes it.

Patch 2 makes xdp_do_redirect() copy the buffer without freeing it,
and free it only once the copy has been redirected. If the redirect
fails, the copy is freed and the buffer is left to the driver. With
both patches, a failed xdp_do_redirect() never frees a zero-copy
buffer, whatever the target, so this complements original intent from
patch 1.

I asked LLM to test it with virtio_net in zero-copy mode under QEMU,
20000 packets per case. The XDP program redirects either to lo through a
devmap or an ifindex, which fails as lo has no ndo_xdp_xmit; to another
virtio_net device through a devmap, which succeeds; or to an XSKMAP
whose socket's Rx ring is full. xp_free() calls were counted with a
kprobe and leaked pages derived from nr_free_pages (rounded, as it is
noisy), both per packet:

                         xp_free() calls      pages leaked
                        base   p1   p1+p2   base   p1   p1+p2
  devmap, fails           2     2     1       1     1     0
  ifindex, fails          2     2     1       1     1     0
  XSKMAP, Rx ring full    2     1     1       0     0     0
  devmap, succeeds        1     1     1       0     0     0
  XDP_TX                  1     1     1       0     0     0

[0] https://lore.kernel.org/r/20261111173715.75bccc04@kernel.org
[1] https://lore.kernel.org/r/av3tAd5kTyxfmo1S@boxer


Maciej Fijalkowski (1):
  xdp: Do not free ZC buffer when a frame redirect fails

Marcin Knap (1):
  xsk: Do not free ZC Rx buffer when the Rx ring is full

 drivers/net/ethernet/google/gve/gve_rx_dqo.c  |  4 +++-
 drivers/net/ethernet/intel/i40e/i40e_xsk.c    |  1 +
 drivers/net/ethernet/intel/ice/ice_xsk.c      |  1 +
 .../marvell/octeontx2/nic/otx2_txrx.c         |  3 ++-
 include/net/xdp.h                             |  2 ++
 net/core/filter.c                             | 23 +++++++++++++++++--
 net/core/xdp.c                                | 19 +++++++++++++--
 net/xdp/xsk.c                                 | 15 +++---------
 8 files changed, 50 insertions(+), 18 deletions(-)


base-commit: e9d78fc6741ac06d438cf64e314c28e57014432a
-- 
2.43.0


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

end of thread, other threads:[~2026-12-05 19:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 19:39 [PATCH net v6 0/2] xsk, xdp: fix ZC buffer double free on failed redirect Maciej Fijalkowski
2026-12-04 19:39 ` [PATCH net v6 1/2] xsk: Do not free ZC Rx buffer when the Rx ring is full Maciej Fijalkowski
2026-12-05 19:42   ` netdev-bot+sashiko
2026-12-04 19:39 ` [PATCH net v6 2/2] xdp: Do not free ZC buffer when a frame redirect fails Maciej Fijalkowski
2026-12-05 19:42   ` netdev-bot+sashiko

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