From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: netdev-bot+sashiko@kernel.org
Cc: netdev@vger.kernel.org, kennethbwlee@snu.ac.kr,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
sdf@fomichev.me, kuniyu@google.com, wang.zhan@smartx.com,
mkarsten@uwaterloo.ca, bpf@vger.kernel.org
Subject: Re: [PATCH net v2] net: xdp: fix generic XDP on skbs without an Ethernet header
Date: Tue, 24 Nov 2026 22:23:37 +0800 [thread overview]
Message-ID: <511dade2-01a9-492b-85c2-014880b2379e@linux.dev> (raw)
In-Reply-To: <179552306350.3135.16282643834784138893@kernel.org>
On 11/24/26 8:24 PM, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · 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).
>
> - [High] The new runtime guard in netif_receive_generic_xdp()
> (net/core/dev.c:5827, `if (skb->data - skb_mac_header(skb) < ETH_HLEN)…
>
> --
>
> net: xdp: fix generic XDP on skbs without an Ethernet header
>
> This patch stops generic XDP programs from being attached to devices that
> are not ARPHRD_ETHER or ARPHRD_LOOPBACK. dev->type can change after attach,
> so it also skips generic XDP for skbs whose mac header is shorter than
> ETH_HLEN.
>
> Closes: https://lore.kernel.org/bpf/20260812043643.808295-1-kennethbwlee@snu.ac.kr/
>
>> diff --git a/net/core/dev.c b/net/core/dev.c
>> index 6140fd9d11cd0..df335f361706d 100644
>> --- a/net/core/dev.c
>> +++ b/net/core/dev.c
>> @@ -5823,6 +5823,10 @@ static u32 netif_receive_generic_xdp(struct sk_buff **pskb,
>> if (skb_is_redirected(skb))
>> return XDP_PASS;
>>
>> + /* XDP is Ethernet only, skip skbs without an Ethernet header. */
>> + if (skb->data - skb_mac_header(skb) < ETH_HLEN)
>> + return XDP_PASS;
>
> [Severity: High]
>
> According to the commit message, this check covers the case where dev->type
> changes after attach:
>
> "An empty bond or team takes the type of its first port ... So also
> skip the program for skbs whose mac header is shorter than ETH_HLEN."
>
> What happens with non-Ethernet ports whose L2 or pseudo header is ETH_HLEN
> bytes or longer? In these two cases data - mac_header is at least 24.
>
> IPoIB, in skb_add_pseudo_hdr():
>
> skb_reset_mac_header(skb);
> skb_pull(skb, IPOIB_HARD_LEN);
>
> ipgre with ipgre_header_ops, in __ipgre_rcv():
>
> if (tunnel->dev->header_ops == &ipgre_header_ops)
> skb_pop_mac_header(skb);
>
> That second case leaves mac_header on the outer IP header, so mac_len is
> the outer IP header plus the GRE header.
>
> The sequence looks like this:
>
> 1. Attach an XDP_FLAGS_SKB_MODE program to an empty bond or team while it
> is still ARPHRD_ETHER. This passes the new dev_xdp_attach() check.
>
> 2. Enslave an IPoIB device to the bond
> (bond_enslave()->bond_setup_by_slave()), or add an ipgre device to the
> team (team_dev_type_check_change()->team_setup_by_port()). Nothing
> vetoes NETDEV_PRE_TYPE_CHANGE because of a generic XDP program.
> bond_enslave() only checks the native-mode bond->xdp_prog.
>
> 3. On RX, __netif_receive_skb_core() calls skb_reset_mac_len() on the
> lower device's skb. The rx_handler returns RX_HANDLER_ANOTHER, and at
> another_round do_xdp_generic() runs the upper device's generic program.
>
> 4. The new check is false, so the program treats the IPoIB pseudo header,
> or the outer IP/GRE bytes, as an Ethernet header.
>
> If the program then changes bytes 0-5 or 12-13, bpf_prog_run_generic_xdp()
> does:
>
> __skb_push(skb, ETH_HLEN);
> skb->pkt_type = PACKET_HOST;
> skb->protocol = eth_type_trans(skb, skb->dev);
>
> This leaves mac_header at data - 14 while skb->mac_len stays at 24 or
> more. skb->protocol is also taken from non-Ethernet bytes.
>
> Would tc ingress then hit the same "skb_vlan_push got skb with skb->data
> not at mac header" warning in skb_vlan_push() that this patch is meant to
> fix?
>
> There is also a second gap. bpf_xdp_link_update() calls dev_xdp_install()
> directly and does not go through dev_xdp_attach(). After a type change like
> the one above, could a new generic program be swapped in through an
> existing link without hitting the new ARPHRD check?
>
> Would any of these close the remaining cases?
>
> - require mac_len == ETH_HLEN at run time
> - check skb->dev->type for ARPHRD_ETHER or ARPHRD_LOOPBACK at run time
> - veto NETDEV_PRE_TYPE_CHANGE while a generic XDP program is attached
>
Ok, same as sashiko.
I used < ETH_HLEN to keep VLAN devices with reorder_hdr off working, but the fixup after the program is wrong
for them too, so I'll just skip everything that is not ETH_HLEN.
pw-bot: cr
prev parent reply other threads:[~2026-11-24 14:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 12:15 [PATCH net v2] net: xdp: fix generic XDP on skbs without an Ethernet header Jiayuan Chen
2026-11-24 12:16 ` sashiko-bot
2026-11-24 12:24 ` netdev-bot+sashiko
2026-11-24 14:23 ` Jiayuan Chen [this message]
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=511dade2-01a9-492b-85c2-014880b2379e@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kennethbwlee@snu.ac.kr \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=mkarsten@uwaterloo.ca \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=wang.zhan@smartx.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