Article View: linux.kernel.netdev
Article #27102[PATCH net v6 0/2] xsk, xdp: fix ZC buffer double free on failed redirect
From: Maciej Fijalkowski
Date: Fri, 04 Dec 2026 19:39
Date: Fri, 04 Dec 2026 19:39
77 lines
12560 bytes
12560 bytes
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
Technical Details
Message-ID:
<20261204193929.1168874-1-maciej.fijalkowski@intel.com>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377586-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377586-linux-kernel-netdev=dewy.ru From: maciej.fijalkowski@intel.com (Maciej Fijalkowski) Newsgroups: linux.kernel.netdev 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 Organization: Usenet Network Message-ID: <20261204193929.1168874-1-maciej.fijalkowski@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2847054"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:7UDzoyMIszVhHXNKQcRmh6UmKbc= sha256:v8K30qrVwCCPoTisrKelMzDt8MmBLTUXKpUnUfiM5YI= sha1:Exg87SJLhhExzBGsOJP+vHWBFBo= sha256:NHNCxWlHP3VYLA4jvi/re9flaTblfKPVUEL5LqgfNO8= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id B9B9B117CBE; Fri, 4 Dec 2026 22:40:27 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.44 X-Spam-Status: No, score=-3.44 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m9tzyKsu7gmz; Fri, 4 Dec 2026 22:40:24 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-377586-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=intel.com X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 30744117CBB; Fri, 4 Dec 2026 22:40:13 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id A73492C3A0; Fri, 4 Dec 2026 19:40:09 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796413208; b=mjeSSE4M2UF5O9ndfHIiULKWbq9An69VhrowNite2mbCRjWlFX1r1ageItWAFlBxpjjs LWaxRKlwNM9dah4qaG5nK9ZPu6JXzgoFsL0JAgyjT+hEvmGgBBnddMbk08CsRf+TqhGtR VkYK4GyBU/e7rpVdU7EHN3K/zH88Y9IF/oj5VSgzgh/b9+a0oO6fd+X9RGkv/YOLJedKa /2K0iHivbla0vdtgFPMNTFFM1wDm9pgsUnslIPvU8XZ7tL4RnnBKbHE9sjg5e50sSLddB 1xj+V1Vseug6PEyX/wQyiBWfcgC8re+5LCYW/VQ0dygsI0VbPROXEHylA0Hr9nlHhvw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796413208; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature: X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-IronPort-AV:X-IronPort-AV: Received:X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV: Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=PzTBT8JI1yQojYGrUh0T4pN0qbUhDpfUQcDBo4q0dAo=; b=nQpYzY8xuA/m/Ky5aEPZMIjh+C6CNX4v5lcI8YM8OTh43Ir5YwO77Ltk0zYEt9PojptX 84SKLjUIBUdU8TFVkhpdZVDcxp/Wkkyq0LKa2xw5c3P5w1ax5AecfrbhjdVu/tfWS7HxE CwN3xGmgVItUHisr7V7CYLzOn1YlupfbfGJQzPYBDfTlkCtsyetf39jc12r5Cz/d5wnCL +J/aHwwFYvnACnN5FTFYYtaYghD34eOwlz68zdn1LQb670cKd95tkIQnlI9aTOUVZ+PtE vDmGZHSmPXilbvZ4VLQSm3xIJRU9mm/3OUA9ePOMeAEQZz05eYpgJyh74NKwc49pK6Q== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nkacUtkF; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B39C606A6AB; Fri, 4 Dec 2026 19:40:08 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nkacUtkF X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.8 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796413202; b=bW3BDJlHmCaGXja3eapKVHEVOvMBxvfPkfHffyBwSior0/yHDSZQhH03ihXC0bFW++RM yjCDq92gl9kUyV4Y2D0UcCtRVh08nSAW/bCZSeGtSuax7VMFLV9eE7DP9bWrUfui0+7gp 454i+vgJiGuJobofqEtFFNO+lOLDPK6kZYYrDdP4UY8524uM9Nk7FwIljYuuVEYMaBcRb qSAANz88PaD3n1E4c1Ehg92x6yudCzX9rRfjszLPnyoOTQjLscR8D207Api3sLbSaezna o5WzXalYAmxntnWxyKPR95oXzxvVuSY+RYOzGdQ1j8+pzOO9jmbutN3tYAX2laskNYA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796413202; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=PzTBT8JI1yQojYGrUh0T4pN0qbUhDpfUQcDBo4q0dAo=; b=Pck5K/FepaOZb8Ldw8vt2f5fp/WiUIMZX5XvQwnGIJORfITHf2sFBosYtz1Qpqaugtk0 OjoUZCLx9mjYWWJpTiPo8HqZYIoM9wFtIcYALyeKi+py97ebU1lzzAo/5n9dpfP39G7b9 rkXyWGx5GgWAGmlock/mVpq49hNb3ut3jRPtkOVyYnhJCfzHaNNdUYdBvDwhwKCNGUM4W 5WtVzDJSpB/UpsL6LbsynmXhBDNWq5wigx1muWcngjOphDztvvy6Uk1l9ruf4u6dRcyBP 046GvYkclim7zJuWRPDhPS9QwcOhCIsv7uHPKIjqy0AoOPHxrQFxmy0sxXBiXE4twEg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nkacUtkF; arc=none smtp.remote-ip=192.198.163.8 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8282A606A33E; Fri, 4 Dec 2026 19:39:56 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8282A606A33E X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796413196; x=1827949196; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=PzTBT8JI1yQojYGrUh0T4pN0qbUhDpfUQcDBo4q0dAo=; b=nkacUtkF6KXNBV1W/iXEeHVlqaKbEC6s+t470UJ6hUxPyZsZT1gHys09 gbFMLchau2xEl0gCstHO4Ba9Tg6Gv0xE4MRaAOQaAYIAGc7EnWuTgoyaU t9/ArzfCfM682bwDMDE6NvWOz4MC+v4NWorJZKxW3y0f0iym8TwhOP8Tf DGyBP4B7/TT9RjADaxT5Fn83Rbat4cDwur7oAzlRwc9X376jvOpF4glil a6yxLUZZRv7eNzkm0xNHCDA0N8pSAy5g/0/03g3esE+tQ8w2kbUlXEJyS xiTjDX0yVM6hEgLSzLcCWJ850oa6OS9fllQsApZV4hJ7Ayfdo72J8Wwzn Q==; X-CSE-ConnectionGUID: dUSiCtndRMKDbzCxobKUUQ== X-CSE-MsgGUID: YBI2pJUxSKCuJTLiS7OaOQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5290951" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5290951" X-Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 11:39:55 -0800 X-CSE-ConnectionGUID: 8UiMirkwQSO55dQjKHbFKA== X-CSE-MsgGUID: 0ak93O1oRzCt01Tq754NOA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14021399" X-Received: from boxer.igk.intel.com ([10.102.20.173]) by orviesa003.jf.intel.com with ESMTP; 04 Dec 2026 11:39:50 -0800 X-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 X-Mailer: git-send-email 2.38.1 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list