From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
magnus.karlsson@intel.com, sdf@fomichev.me, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
jtollet@cisco.com, willemb@google.com, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com
Cc: bpf@vger.kernel.org, bjorn@kernel.org, kerneljasonxing@gmail.com,
marcin.knap@vecima.com, joshwash@google.com,
hramamurthy@google.com, sgoutham@marvell.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
toke@redhat.com, hangbin.liu@linux.dev
Subject: [PATCH net v6 0/2] xsk, xdp: fix ZC buffer double free on failed redirect
Date: Fri, 4 Dec 2026 20:39:27 +0100 [thread overview]
Message-ID: <20261204193929.1168874-1-maciej.fijalkowski@intel.com> (raw)
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
next reply other threads:[~2026-12-04 19:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 19:39 Maciej Fijalkowski [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204193929.1168874-1-maciej.fijalkowski@intel.com \
--to=maciej.fijalkowski@intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hangbin.liu@linux.dev \
--cc=hawk@kernel.org \
--cc=hramamurthy@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=joshwash@google.com \
--cc=jtollet@cisco.com \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=magnus.karlsson@intel.com \
--cc=marcin.knap@vecima.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=sgoutham@marvell.com \
--cc=song@kernel.org \
--cc=toke@redhat.com \
--cc=willemb@google.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox