Netdev List
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
To: netdev-bot+sashiko@kernel.org
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
Subject: Re: [PATCH net-next v10 2/4] net: xdp: add xdp_buff_shrink_tail() helper
Date: Tue, 17 Nov 2026 13:56:07 +0100	[thread overview]
Message-ID: <avxO59MbI0ql5YhQ@lore-qca> (raw)
In-Reply-To: <179484961693.3136.10654880889378798099@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 6207 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 =…

I will fix them in v11.

Regards,
Lorenzo

> 
> --
> 
> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-11-17 12:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 16:34 [PATCH net-next v10 0/4] net: stmmac: introduce XDP rx multi-buff support Lorenzo Bianconi
2026-11-12 16:34 ` [PATCH net-next v10 1/4] net: xdp: add __xdp_build_skb_from_buff() helper Lorenzo Bianconi
2026-11-16 17:20   ` netdev-bot+sashiko
2026-11-17 12:55     ` Lorenzo Bianconi
2026-11-12 16:34 ` [PATCH net-next v10 2/4] net: xdp: add xdp_buff_shrink_tail() helper Lorenzo Bianconi
2026-11-16 17:20   ` netdev-bot+sashiko
2026-11-17 12:56     ` Lorenzo Bianconi [this message]
2026-11-12 16:34 ` [PATCH net-next v10 3/4] net: xdp: add __xdp_return_buff() helper Lorenzo Bianconi
2026-11-12 16:34 ` [PATCH net-next v10 4/4] net: stmmac: rework stmmac_rx to support XDP rx multi-buff Lorenzo Bianconi

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=avxO59MbI0ql5YhQ@lore-qca \
    --to=lorenzo.bianconi@oss.qualcomm.com \
    --cc=Jose.Abreu@synopsys.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=boon.leong.ong@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=martin.lau@linux.dev \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=memxor@gmail.com \
    --cc=nb@tipi-net.de \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --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