> 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