From: Nicolai Buchwitz <nb@tipi-net.de>
To: Simon Horman <horms@kernel.org>
Cc: davem@davemloft.net, mbloch@rooftopnetworks.de,
edumazet@google.com, linux-kernel@vger.kernel.org,
vikas.gupta@broadcom.com, rajashekar.hudumula@broadcom.com,
opendmb@gmail.com, bhargava.marreddy@broadcom.com,
netdev@vger.kernel.org, ebiggers@kernel.org,
andrew+netdev@lunn.ch, hkallweit1@gmail.com,
florian.fainelli@broadcom.com, kuba@kernel.org, arnd@arndb.de,
bcm-kernel-feedback-list@broadcom.com, pabeni@redhat.com
Subject: Re: [net-next,v2,3/6] net: bcmgenet: add basic XDP support (PASS/DROP)
Date: Tue, 17 Mar 2026 20:27:54 +0100 [thread overview]
Message-ID: <dd8cc7a1f13cf02b4d9ae54f7ed07d19@tipi-net.de> (raw)
In-Reply-To: <20260317161906.1758581-1-horms@kernel.org>
On 17.3.2026 17:19, Simon Horman wrote:
> [...]
>>
>> +static struct sk_buff *bcmgenet_xdp_build_skb(struct bcmgenet_rx_ring
>> *ring,
>> + struct xdp_buff *xdp,
>> + struct page *rx_page)
>> +{
>> + unsigned int metasize;
>> + struct sk_buff *skb;
>> +
>> + skb = napi_build_skb(xdp->data_hard_start, PAGE_SIZE);
>> + if (unlikely(!skb))
>> + return NULL;
>> +
>> + skb_mark_for_recycle(skb);
>> +
>> + metasize = xdp->data - xdp->data_meta;
>> + skb_reserve(skb, xdp->data - xdp->data_hard_start);
>> + __skb_put(skb, xdp->data_end - xdp->data);
>> +
>> + if (metasize)
>> + skb_metadata_set(skb, metasize);
> ^^^^
>
> Can this corrupt memory? Looking at bcmgenet_desc_rx(), the xdp_buff is
> initialized with meta_valid=false:
>
> xdp_prepare_buff(&xdp, page_address(rx_page),
> GENET_RX_HEADROOM, pkt_len, false);
>
> When meta_valid is false, xdp_prepare_buff() sets xdp->data_meta to
> xdp->data + 1 as a sentinel value to indicate no metadata is present.
>
> In bcmgenet_xdp_build_skb(), the metasize calculation becomes:
>
> metasize = xdp->data - xdp->data_meta
> = xdp->data - (xdp->data + 1)
> = (ptrdiff_t)-1
>
> When assigned to 'unsigned int metasize', this wraps to UINT_MAX. The
> 'if (metasize)' check passes since UINT_MAX != 0, and
> skb_metadata_set(skb, metasize) truncates UINT_MAX to u8, setting
> skb_shinfo(skb)->meta_len = 255.
>
> This incorrect meta_len of 255 can cause downstream SKB consumers (TC
> BPF
> programs, skb_data_move) to read or write 255 bytes before
> skb_mac_header(skb) when accessing the metadata region.
>
> Other XDP drivers that use skb_metadata_set() (bnxt, mvneta, ixgbe,
> i40e, virtio_net) all pass meta_valid=true to xdp_prepare_buff(), which
> sets data_meta=data, giving metasize=0 and correctly skipping
> skb_metadata_set().
>
> Should xdp_prepare_buff() be called with meta_valid=true instead of
> false, since bcmgenet_xdp_build_skb() handles XDP metadata?
Will fix this in v3 by passing meta_valid=true, matching what other XDP
drivers do.
Thanks
Nicolai
> [...]
next prev parent reply other threads:[~2026-03-17 19:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 21:49 [PATCH net-next v2 0/6] net: bcmgenet: add XDP support Nicolai Buchwitz
2026-03-15 21:49 ` [PATCH net-next v2 1/6] net: bcmgenet: convert RX path to page_pool Nicolai Buchwitz
2026-03-15 21:49 ` [PATCH net-next v2 2/6] net: bcmgenet: register xdp_rxq_info for each RX ring Nicolai Buchwitz
2026-03-15 21:49 ` [PATCH net-next v2 3/6] net: bcmgenet: add basic XDP support (PASS/DROP) Nicolai Buchwitz
2026-03-17 16:19 ` [net-next,v2,3/6] " Simon Horman
2026-03-17 19:27 ` Nicolai Buchwitz [this message]
2026-03-15 21:49 ` [PATCH net-next v2 4/6] net: bcmgenet: add XDP_TX support Nicolai Buchwitz
2026-03-17 16:20 ` [net-next,v2,4/6] " Simon Horman
2026-03-17 19:25 ` Nicolai Buchwitz
2026-03-15 21:49 ` [PATCH net-next v2 5/6] net: bcmgenet: add XDP_REDIRECT and ndo_xdp_xmit support Nicolai Buchwitz
2026-03-15 21:49 ` [PATCH net-next v2 6/6] net: bcmgenet: add XDP statistics counters Nicolai Buchwitz
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=dd8cc7a1f13cf02b4d9ae54f7ed07d19@tipi-net.de \
--to=nb@tipi-net.de \
--cc=andrew+netdev@lunn.ch \
--cc=arnd@arndb.de \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bhargava.marreddy@broadcom.com \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mbloch@rooftopnetworks.de \
--cc=netdev@vger.kernel.org \
--cc=opendmb@gmail.com \
--cc=pabeni@redhat.com \
--cc=rajashekar.hudumula@broadcom.com \
--cc=vikas.gupta@broadcom.com \
/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