Article View: linux.kernel.netdev
Article #26261[PATCH net v3 2/4] xdp: Size zero-copy skbs from the data, not the frame size
From: Björn Töpel
Date: Thu, 03 Dec 2026 09:56
Date: Thu, 03 Dec 2026 09:56
121 lines
12715 bytes
12715 bytes
xdp_build_skb_from_zc() gives the skb head the frame size of the XSk
buffer, and the skb shared info takes the end of it. A device may fill
a single-buffer XSk frame to its end, so a long packet overwrites the
shared info of the new skb with packet data. With 2K chunks, no UMEM
headroom and the default MTU, a 1514 byte frame that XDP passes on
ice, idpf or gve needs 256 + 1514 + 320 = 2090 bytes and gets 2048.
The sender controls up to 48 bytes of the shared info, its frag list
among them. The last patch of this series lets multi-buffer pools and
bpf_xdp_adjust_tail() reach the end of the frame as well.
The copies of the head and of the fragments also round the length up
to 16 bytes, and read and write past the end of the data.
Size the head from the data, and copy the exact length. Heads larger
than a page come from kmalloc, not the page pool.
Found again by an AI code review agent, and the 2K case by reading the
code. Reproduced out of tree, with a test module and the AF_XDP
page-pool RFC on fbnic in QEMU.
Reported-by: Clément Lecigne <clecigne@google.com>
Link: https://lore.kernel.org/bpf/20260629072300.1664622-1-clecigne@google.com/
Fixes: 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion")
Acked-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
net/core/xdp.c | 40 ++++++++++++++++++++++++++++------------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 1d679e8fd649..33a6740b411f 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -709,7 +709,7 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
}
memcpy(page_address(page) + offset, skb_frag_address(frag),
- LARGEST_ALIGN(len));
+ len);
__skb_fill_page_desc_noacc(sinfo, i, page, offset, len);
tsize += truesize;
@@ -723,6 +723,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
return true;
}
+static struct sk_buff *xdp_zc_alloc_head(struct page_pool *pp,
+ struct net_device *dev, u32 size)
+{
+ u32 truesize = SKB_HEAD_ALIGN(size);
+ struct sk_buff *skb;
+ void *data;
+
+ if (truesize > PAGE_SIZE)
+ return __netdev_alloc_skb(dev, size, GFP_ATOMIC | __GFP_NOWARN);
+
+ data = page_pool_dev_alloc_va(pp, &truesize);
+ if (unlikely(!data))
+ return NULL;
+
+ skb = napi_build_skb(data, truesize);
+ if (unlikely(!skb))
+ page_pool_free_va(pp, data, true);
+
+ return skb;
+}
+
/**
* xdp_build_skb_from_zc - create an skb from XSk &xdp_buff
* @xdp: source XSk buff
@@ -730,7 +751,8 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
* Similar to xdp_build_skb_from_buff(), but for XSk frames. Allocate an skb
* head, new buffer for the head, copy the data and initialize the skb fields.
* If there are frags, allocate new buffers for them and copy.
- * Buffers are allocated from the system percpu pools to try recycling them.
+ * Buffers are allocated from the system percpu pools to try recycling them,
+ * except a head that does not fit into a page.
* If new skb was built successfully, @xdp is returned to XSk pool's freelist.
* On error, it remains untouched and the caller must take care of this.
*
@@ -738,33 +760,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb,
*/
struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp)
{
+ u32 size = xdp->data_end - xdp->data_hard_start;
const struct xdp_rxq_info *rxq = xdp->rxq;
u32 len = xdp->data_end - xdp->data_meta;
- u32 truesize = xdp->frame_sz;
struct sk_buff *skb = NULL;
struct page_pool *pp;
int metalen;
- void *data;
if (!IS_ENABLED(CONFIG_PAGE_POOL))
return NULL;
local_lock_nested_bh(&system_page_pool.bh_lock);
pp = this_cpu_read(system_page_pool.pool);
- data = page_pool_dev_alloc_va(pp, &truesize);
- if (unlikely(!data))
- goto out;
- skb = napi_build_skb(data, truesize);
- if (unlikely(!skb)) {
- page_pool_free_va(pp, data, true);
+ skb = xdp_zc_alloc_head(pp, rxq->dev, size);
+ if (unlikely(!skb))
goto out;
- }
skb_mark_for_recycle(skb);
skb_reserve(skb, xdp->data_meta - xdp->data_hard_start);
- memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len));
+ memcpy(__skb_put(skb, len), xdp->data_meta, len);
metalen = xdp->data - xdp->data_meta;
if (metalen > 0) {
--
2.53.1-Meta
Technical Details
Message-ID:
<20261203095647.3448925-3-bjorn@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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-376463-linux-kernel-netdev=dewy.ruReferences:
<20261203095647.3448925-1-bjorn@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.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-376463-linux-kernel-netdev=dewy.ru From: bjorn@kernel.org (Björn Töpel) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3 2/4] xdp: Size zero-copy skbs from the data, not the frame size Date: Thu, 3 Dec 2026 10:56:43 +0100 Organization: Usenet Network Message-ID: <20261203095647.3448925-3-bjorn@kernel.org> References: <20261203095647.3448925-1-bjorn@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2453671"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:1Ng7SrPCUlGLKS1xEEGwzWmO9Z8= sha256:dt1/KBO6U3nvied+7xRb4v7KGgHEUlQOJA47aJnhtPs= sha1:ropUzwfdqC3crAXe6KRg5Duk88o= sha256:1KcvZKggtCDM0h9wLa3u4KheBXyW4PTBkXwz7EYp3Ho= 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 AE36B1178BB; Thu, 3 Dec 2026 12:57:32 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org 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 XjG-WH1qs0bL; Thu, 3 Dec 2026 12:57:29 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376463-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 1AE621178B0; Thu, 3 Dec 2026 12:57:20 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 99F4926642; Thu, 3 Dec 2026 09:57:17 +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=1796291837; b=S1lq5NUvkHQwbclTrFntWtzCuEnbdm+l3J7Pgv2eDk42kX9f7hZB5U3NQP9TalrLNbJt GwIbSg7/rx/4bkJj4brZFbmjkqnXNww1tsycShhtmEuYeUKIrxqkV4RcS5/f5Q15GIR4Z fNtcOLpiHhN87dZcMfNTCWAHTrHHwnYXX6kYIs8Y1rZ+H8EbYg01VNef60PBOSFj/By3n 9cNH1r/7OqCsMhIo1v6UHT4YgYIkpHg9fbFJ4bGcWj94dVwJ4w/dffFaAsHq54ZEeb6L8 8tVAPV5IslRdJ8USmeaKwY7XyEau3GqvOX8LAv3hPlvAfz6FE4+J7Kvu6jALC0AH80w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796291837; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=+u0eQGc8GCuxQbKeZrVqIHnCdu4OnmEEY7xNA9QC94E=; b=0h7RDEHkECl00bMYlRWprHHl0dwsseFGt2LUTqZ42QohFolco0NkVf38jWUu+6rlOaFj oyM1H1e6R5B0HIK1+fEymwnRBO9LWs3i1krASyzvceKASn6vbhof71626fi3Xsm4tGAii GlTyRC5pNL3UbUqfdCMg6W61gepsoS7wrmKvJCvfBf8hOuOAmw2NdUPnCeKMZqJAcLdOu C7B6YoHfyo9N2ZAHM42eHnXMUcyR2bB4N5RLmyz2KuAq5NyRm6K1G2apUhNVmq0Vai2Vb auSn9TzDBPJ6OM+tpQj0WBno3ko5XKvj1Zb5Hk+M4/85IlWQz9HKgSba3XfIZ0u3lSA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=grQLOsA5; 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 71F13606A322; Thu, 3 Dec 2026 09:57:17 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=grQLOsA5 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796291836; b=IVabBsPMihiA4rUD02uSIxv7Y21PnBFmjr8p/K+7r/HLjqSLKenRaiJXHn8BsE8yURfw IPzt4JWCKC39w5FinYT4FwK+/PsPZGzKSN+P37fjgWrzF70BV/IieD5spOEXhzPfTdlV9 Ii8e3kLqhV8XaiiJvH4LqhbWrbtNooKoGgmGc3gFEG8wybTDGDGBSQQL7wzIgQupMwyLv bHD1kDXecSuIqd0EOXUY6xHbuRX/cMc1Vr0Qir9sKfv+/I5gKCKrUfRCu2WJ1x3HfXAdz phUQbb6dw/42wqBCRnc0xrt+EedZdB4hZibUvLS9KPO50nmhXGxEuxm7rkjYV0l5WPw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796291836; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=+u0eQGc8GCuxQbKeZrVqIHnCdu4OnmEEY7xNA9QC94E=; b=Q2CrITPIJ2dhXg+ifpKzeoiBupcuRl6iF0TPiUqjAcYFjONHky+AblgkDl1PGK9fEFS5 qEyFVvFeBNkMP+YVHeB3xt7XCGXxvnAM+6lyD7pQqVCihFuOifL457Kk52cz/ovAt44AC relFeSaaRutcAmVDpru7oaeOV3ol/uiMAeIJA8Rk6UzMJV+lnc4mmpDF7DLh43xiDxdCS Y2Q1dMmUG4AIYHmijbogrbRSYZqxed8dBxHNXpwR8lfzUw8E5+M8VUWhdyQuX6N62vo1N JIbu7rCeLe2dTezAJH89Vxj+37nAVHp5uWlLtUmaVTiQSTiFGBENv1yGinskhGYPeag== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=grQLOsA5; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FA24606A333; Thu, 3 Dec 2026 09:57:16 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 190D41F00896; Thu, 3 Dec 2026 09:57:09 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796291836; bh=+u0eQGc8GCuxQbKeZrVqIHnCdu4OnmEEY7xNA9QC94E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=grQLOsA5cfPJPyd26w/7c1LV74MvPkR9BHi2j8rOvxqAmK38/5O2p9X05gkADrPa/ yNCkPjNK24wF+KjdPbaj2Pc4QixQTqFYkPELoAgT0cOItlKJ85kkzjCGkOISZqz0iT /luKC9UlWgEUYr0AGD93GV3mr2Ia7xBzIjPUoKqP0WI5CUt6xbktE/K0NaVJMiLFIC uOCnXPE6ESGipBtmkSGoE3oKhZtem9gu/81t5HAwAGkOuTT03yPlJ16DDb5cVxtis8 KpiWXStUyucxMR+iFoCeBAGX3Cz281lpon76xNQfu+UeX3hCuLrw8hObLmijG4RQ4k XuaFkM3pfu/ow== X-Cc: Björn Töpel <bjorn@kernel.org>, Simon Horman <horms@kernel.org>, Stanislav Fomichev <sdf@fomichev.me>, Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, Yonghong Song <yonghong.song@linux.dev>, Jiri Olsa <jolsa@kernel.org>, Emil Tsalapatis <emil@etsalapatis.com>, Ihor Solodrai <ihor.solodrai@linux.dev>, intel-wired-lan@lists.osuosl.org, Clément Lecigne <clecigne@google.com>, Michal Swiatkowski <michal.swiatkowski@linux.intel.com>, Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>, Kurt Kanzenbach <kurt@linutronix.de> X-Mailer: git-send-email 2.56.1 X-In-Reply-To: <20261203095647.3448925-1-bjorn@kernel.org> 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