Article View: linux.kernel.netdev
Article #17364Re: [PATCH net-next v10 2/4] net: xdp: add xdp_buff_shrink_tail() helper
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 17:20
Date: Mon, 16 Nov 2026 17:20
149 lines
14032 bytes
14032 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 2 · High: 0 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Critical] The patch removes the lower-bound check `data_end <
xdp->data + ETH_HLEN` from the linear path of bpf_xdp_adjust_tail()…
- [Critical] The new exported xdp_buff_shrink_tail() (net/core/xdp.c)
checks a linear shrink only against the lower bound: `data_end =…
--
net: xdp: add xdp_buff_shrink_tail() helper
This moves the XDP tail-shrink logic out of bpf_xdp_adjust_tail() and into
net/core/xdp.c. The frag shrink helpers move with it, and a new exported
xdp_buff_shrink_tail() handles both the linear and frags cases.
bpf_xdp_adjust_tail() now sends every negative offset to the new helper
so stmmac can share it for FCS stripping.
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 9b8d5191c4ba2..5ea45dfce7a22 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4438,96 +4438,21 @@ static int bpf_xdp_frags_increase_tail(struct xdp_buff *xdp, int offset)
[ ... ]
> BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)
> {
> void *data_hard_end = xdp_data_hard_end(xdp); /* use xdp->frame_sz */
> void *data_end = xdp->data_end + offset;
>
> - if (unlikely(xdp_buff_has_frags(xdp))) { /* non-linear xdp buff */
> - if (offset < 0)
> - return bpf_xdp_frags_shrink_tail(xdp, -offset);
> + if (offset < 0)
> + return xdp_buff_shrink_tail(xdp, -offset);
>
> + if (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */
> return bpf_xdp_frags_increase_tail(xdp, offset);
> - }
>
> /* Notice that xdp_data_hard_end have reserved some tailroom */
> if (unlikely(data_end > data_hard_end))
> return -EINVAL;
>
> - if (unlikely(data_end < xdp->data + ETH_HLEN))
> - return -EINVAL;
> -
> /* Clear memory area on grow, can contain uninit kernel memory */
> if (offset > 0)
> memset(xdp->data_end, 0, offset);
[Severity: Critical]
With the ETH_HLEN check gone from this path, what stops a grow on a
linear xdp_buff from wrapping the pointer?
The offset argument is ARG_ANYTHING, so a program can pass any positive
int. data_end is computed as xdp->data_end + offset. For the linear grow
case, the only check left is data_end > data_hard_end.
On a 32-bit kernel with the default 3G/1G split, packet buffers sit at
or above 0xC0000000. Take xdp->data_end = 0xC5000100 and
offset = 0x3B000000: data_end wraps to 0x100. That passes the
data_hard_end check, and then this runs:
memset(xdp->data_end, 0, offset);
It would zero about 1 GiB of kernel memory past the packet buffer. After
that, xdp->data_end is set below xdp->data.
Before this patch, a wrapped value was always below xdp->data + ETH_HLEN,
so the removed check returned -EINVAL for it. That check now exists only
in xdp_buff_shrink_tail(), which runs only when offset < 0.
The return value also changes for short frames. A linear frame already
shorter than ETH_HLEN used to get -EINVAL from
bpf_xdp_adjust_tail(ctx, 0), or from a small grow that left it under 14
bytes. It now gets 0. That seems to contradict this sentence in the
commit message:
Behavior for valid offsets is unchanged.
Should the lower-bound check stay in bpf_xdp_adjust_tail() for the
offset >= 0 linear path? The later patch "net: stmmac: rework stmmac_rx
to support XDP rx multi-buff" doesn't touch bpf_xdp_adjust_tail(), so
this still looks present at the end of the series.
[ ... ]
> diff --git a/net/core/xdp.c b/net/core/xdp.c
> index 470bf90d93ef2..7c98dbc2a770c 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -672,6 +672,97 @@ struct sk_buff *__xdp_build_skb_from_buff(const struct xdp_buff *xdp)
[ ... ]
> +int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset)
> +{
> + void *data_end = xdp->data_end - offset;
> +
> + if (unlikely(offset < 0))
> + return -EINVAL;
> +
> + if (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */
> + return xdp_frags_shrink_tail(xdp, offset);
> +
> + if (unlikely(data_end < xdp->data + ETH_HLEN))
> + return -EINVAL;
> +
> + xdp->data_end = data_end;
[Severity: Critical]
Can xdp->data_end - offset wrap here and still pass the lower-bound
check?
bpf_xdp_adjust_tail() passes -offset, so a program can ask for a shrink
of up to INT_MAX bytes. The old inline code also checked
data_end > data_hard_end for shrink requests, and that rejected a
wrapped result. This path no longer has that upper-bound check.
Some 32-bit configurations put lowmem below 0x80000000. Examples are
ARM with VMSPLIT_1G (PAGE_OFFSET is 0x40000000), nommu ARM (PAGE_OFFSET
is PHYS_OFFSET), x86-32 with VMSPLIT_1G or VMSPLIT_2G_OPT, and m68k.
On those, a shrink larger than (u32)xdp->data_end wraps to an address
between data_end + 2^31 and 2^32. That is always above
xdp->data + ETH_HLEN, so the check passes and the wrapped pointer is
written to xdp->data_end.
The packet then appears to span gigabytes of kernel memory. Direct
packet access, bpf_xdp_load_bytes() and bpf_xdp_store_bytes(), XDP_TX,
redirect, and skb construction on XDP_PASS all trust data_end after
that.
Should offset be checked against the linear length before the pointer
subtraction? This code is also unchanged at the end of the series.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-stmmac-rx-mb-v10-0-d3d04b65c6bc%40oss.qualcomm.com
Technical Details
Message-ID:
<179484961693.3136.10654880889378798099@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364595-linux-kernel-netdev=dewy.ruReferences:
<20261112-stmmac-rx-mb-v10-2-d3d04b65c6bc@oss.qualcomm.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364595-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v10 2/4] net: xdp: add xdp_buff_shrink_tail() helper Date: Mon, 16 Nov 2026 17:20:16 +0000 Organization: Usenet Network Message-ID: <179484961693.3136.10654880889378798099@kernel.org> References: <20261112-stmmac-rx-mb-v10-2-d3d04b65c6bc@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2122230"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:5x52ngrO/pvINQ6RlEkFD+rxHto= sha256:dlk93m6Rzd0mr1lh03QF/EJggX3cpWoYI3xA5Qxhhhk= sha1:HkYA/c8122ntyfeK+kA7LnwDA0E= sha256:iRNbBLRWIckpmW3Dmc/KrPOVLrMSzBpgMp2xiQwim2g= 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 87AE3114D08; Mon, 16 Nov 2026 20:20:35 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.5 X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[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, URIBL_BLOCKED=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 nun3h4TIFwam; Mon, 16 Nov 2026 20:20:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-364595-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id B3217114D01; Mon, 16 Nov 2026 20:20:21 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id BB2F0603B5F; Mon, 16 Nov 2026 17:20:20 +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=1794849620; b=KNLedM6LGlRkJsbuTAtfdoODzf0LSfrj5oNwsJiW2a21YK1cIZYoDDG43bto6O5QOmiO UT+rmZv4U2bRexOmwcmTKlR70WrJAL85FOtLczV3haYBxKI2zeajgaPLUbM6GyMNvtaxO luMBBof6/tRTa4SO9ZDxQmVctRUjYqeijPBNCYJ4sQr5s944CCyVwDHgO++pMqQ87oV9Q e6kTeJJO7MNfjIpAii/yjyr4k8/3NQ2ua6E5wS12gt1GBhGW379UeNEPOMrFT7zRYcbHq +2T8Q5uaJVw1w3abDr4wgW5I2z2Yy9jPc5RCimBmJuDzSLc6Io4BzreMWUqe98NpmqA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794849620; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=qo+XNJi3+qAMT97TnlZtT0eegnezla+dXLwHmpOKv2w=; b=hi/QYuUTNEXF+ZkHDxpcaX+r1CW2EFF8toXS1eVsfhfUxvUOCQlJAomRSrmhwoW+ly+/ 4uoN2/BqpFII8wzy7yLVCkIOjjGuIN8n5IgYpm4t4gJ9DXK1LFgCZHf5n3p7FxIfFDmWO 2c5XDysfgd9e44d4oSkPps5zw3BoIZDhh5noMpCfqVW08Ubnwx6GUvDwo4SFPIAGgVzgz EjDPQTonBCdj0NPkJzOdyajYb13Ce3LDaOdQocAZeJVq4aK7fAV/gCsDhNpiZQ+VGD5Rj BgoCZXRt4ItJLvPcPo7sq84AFYE9YswMB/b0mIrGt2bRzPJ4q/MmEmYcQKQuFGfKz7g== 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=QDRAy9Sj; 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 F0FAB606A336; Mon, 16 Nov 2026 17:20:19 +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=QDRAy9Sj 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=1794849619; b=qhsihwCMy3E332FiCQAITR+kz6du3n4+ohqU+J0Zub07BU4xGny7iUcozexx//ZHsCfp oS/gCF9PX1VDmQp9ky3siFo24Cyv2FwQ7JET+7u+XtLNyFgxpWJL3uJE1FaxgeoZ5jtHO Tsqe3VRQPLSGKrvjxxl/qN534Ez0y8s407kHUF2gx+gEc5iF0qhNru+uPe/CM3buOqysv gCi4Vh/NQfaJSxjqijHg/mIcIGhWNK+Tfat6LG+Rc8Su9I6Qonj0kUj6s3bd6+t8/6fro QueaDQ+d4uK761Jpi5VhyW1g444xIUoffUihlfe+nqEUaWDomP87abal6JoXL3arNSw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794849619; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=qo+XNJi3+qAMT97TnlZtT0eegnezla+dXLwHmpOKv2w=; b=K7gKXvjdyyFIO0PxRjBh7KQQDgImJZSpdieCoykuZ8EQ5+/kjiE3e3WEtUVuCFkr/ajj x7HW1AV3MvfIFFw74+EDfT1S0k9B+oVwR5bMyPO+NynZRiD2Q4W18krHxNITVTuvKeudV D/8qzKBwfLsqIXfkn1pV1JedPtu5Kfn1jiNjxu0Cl01X1dmPTF/u0WDX+2KDowB2SUp3L PF/ULrbDl0jwjR7Bo3ZHmBwnPmv2dr1kw/mXF7IyExlxQ6AdYRva7gkvvQfbvss8zbuMh ej3oSfR0q+Sz+Gx5VRYBcA1HR+6TPDLwppzPT1sKLpAOUfp7WWpHstBJnpv4TSW5MiA== 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=QDRAy9Sj; 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 1AEB4606A322; Mon, 16 Nov 2026 17:20:19 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E2451F000C9; Mon, 16 Nov 2026 17:20:17 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794849619; bh=qo+XNJi3+qAMT97TnlZtT0eegnezla+dXLwHmpOKv2w=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=QDRAy9SjFh2jGKg+EHev99/5hoZVQikPXRgMoyNqsTyGo2dMmUyUdqzqvn/82ia2d lGiup191uGYqRKv60FZobuw2GEvamHnW0aIJou9Gi3YYtlnAA8ykCXj5BH9HDnvmca FZ7WUBYkpt2mNIU7kwloD86l72adJtDk9lCVTnPwAoY3RlWbKCFE6Ft0MsI4gHqJfn Nw0dmfZ1eHn6IJQGZjV/p3ECgGZWUF4jYADpd7Y06Wm1q4ULD8yxQNRB5DJFRcIeYz nqYCAzG6W4n8lS5MEwoOtzjLuZRnc2ozVgMS2xztuwFx+yoyHO4ATBGJTqvsYDfKgP MSMEpQRNqx6Yw== X-Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, Jose.Abreu@synopsys.com, boon.leong.ong@intel.com, horms@kernel.org, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org, nb@tipi-net.de X-In-Reply-To: <20261112-stmmac-rx-mb-v10-2-d3d04b65c6bc@oss.qualcomm.com> X-sashiko-severity: Critical 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