Netdev List
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Jiayuan Chen <jiayuan.chen@linux.dev>, netdev-bot+sashiko@kernel.org
Cc: netdev@vger.kernel.org, kennethbwlee@snu.ac.kr,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	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 v3] net: xdp: fix generic XDP on skbs without an Ethernet header
Date: Wed, 2 Dec 2026 12:51:30 +0100	[thread overview]
Message-ID: <1323c2e2-02ab-42b1-8bee-57a61d7a9e40@redhat.com> (raw)
In-Reply-To: <675a13e9-ed23-4a73-8d09-28517c377353@linux.dev>

On 11/26/26 03:16, Jiayuan Chen wrote:
> 
> 
> On 11/25/26 10:27 PM, netdev-bot+sashiko@kernel.org wrote:
>> Thank you for your contribution! Sashiko AI review found 3 potential
>> issue(s) to consider.
>>
>> Critical: 0 · High: 0 · Medium: 2 · Low: 1
>>
>> 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).
>>
>> - [Medium] dev_xdp_attach() (net/core/dev.c) now rejects every
>>    XDP_MODE_SKB attach with -EOPNOTSUPP when dev->type is neither…
>> - [Medium] The new early return in netif_receive_generic_xdp() (`if
>>    (skb->data - skb_mac_header(skb) != ETH_HLEN) return XDP_PASS;`) skips…
>> - [Low] Documentation/networking/af_xdp.rst (around line 86) says XDP_SKB
>>    mode, which is used when the driver has no XDP support or XDP_SKB is…
>>
>> --
>>
>> net: xdp: fix generic XDP on skbs without an Ethernet header
>>
>> The patch refuses to attach a generic XDP program to a device that is
>> neither ARPHRD_ETHER nor ARPHRD_LOOPBACK. It also skips the generic XDP
>> program at runtime for any skb whose mac header is not exactly ETH_HLEN
>> bytes. The goal is to fix a WARN in skb_vlan_push() that comes from the
>> Ethernet header fixup in bpf_prog_run_generic_xdp() on L3 devices such as
>> sit0.
>>
>> 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 cd0796a1dbfdf..a9ef193967bab 100644
>>> --- a/net/core/dev.c
>>> +++ b/net/core/dev.c
>>> @@ -5825,6 +5825,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: Medium]
>> Can this silently skip a program that was attached successfully to an
>> ARPHRD_ETHER device?
>>
>> Take a VLAN device with reorder_hdr off. Its type is ARPHRD_ETHER and it
>> has no ndo_bpf, so dev_xdp_attach() defaults to XDP_MODE_SKB and accepts
>> the program. On receive, vlan_do_receive() does this:
>>
>> net/8021q/vlan_core.c:vlan_do_receive() {
>>      ...
>> 	if (!(READ_ONCE(vlan_dev_priv(vlan_dev)->flags) & VLAN_FLAG_REORDER_HDR) &&
>> 	    ...
>> 		skb_push(skb, offset);
>> 		skb = *skbp = vlan_insert_inner_tag(skb, skb->vlan_proto,
>> 						    skb->vlan_tci, skb->mac_len);
>> 		...
>> 		skb_pull(skb, offset + VLAN_HLEN);
>> 		skb_reset_mac_len(skb);
>> 	}
>>      ...
>> }
>>
>> That leaves skb->data - skb_mac_header(skb) == 18. Then
>> __netif_receive_skb_core() jumps to another_round and calls
>> do_xdp_generic() with the VLAN device's program. The new check returns
>> XDP_PASS for every packet.
>>
>> Before this patch the program ran on the full Ethernet+VLAN frame, so
>> read-only filters and XDP_DROP filters worked. reorder_hdr can be toggled
>> at runtime, so a filter that is already attached could stop being
>> enforced. Nothing reports this: no warning, no extack and no tracepoint.
>>
>> The commit message justifies the runtime check only by dev->type changing
>> after attach. The VLAN effect appears only in the v2->v3 note below the
>> --- line, and that note won't be kept when the patch is applied.
>>
>> Would it make sense to warn once here, or to reject the attach, and to
>> describe this in the commit message?
>>
> 
> 
> 
> This is on purpose. The direction from the maintainers on v1 was that
> XDP is Ethernet only, so generic XDP only handles skbs with an ETH_HLEN
> mac header. v2 tried to let this VLAN case through, and the review on
> v2 asked to skip it too, because the fixup after the program is wrong
> for it.
> 
> v1: https://lore.kernel.org/netdev/20260813113229.381136-1-jiayuan.chen@linux.dev/
> 
>> A separate point: bpf_xdp_link_update() calls dev_xdp_install() directly:
>>
>> net/core/dev.c:bpf_xdp_link_update() {
>>      ...
>> 	mode = dev_xdp_mode(xdp_link->dev, xdp_link->flags);
>> 	bpf_op = dev_xdp_bpf_op(xdp_link->dev, mode);
>> 	err = dev_xdp_install(xdp_link->dev, mode, bpf_op, NULL,
>> 			      xdp_link->flags, new_prog);
>>      ...
>> }
>>
>> This path never reaches the new dev->type check in dev_xdp_attach(). The
>> device type can change after the link is created, for example through
>> bond/team port enslavement or TUNSETLINK. In that case the link update
>> still succeeds, and the new program never runs either.
>>
>> Is this inconsistency intended?
> 
> 
> Yes. dev->type can change after attach anyway, the run time check is
> what covers it.
> 
>>
>> [ ... ]
>>
>>> @@ -10775,6 +10779,12 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack
>>>   			NL_SET_ERR_MSG(extack, "XDP program already attached");
>>>   			return -EBUSY;
>>>   		}
>>> +		/* lo is ARPHRD_LOOPBACK but uses Ethernet framing. */
>>> +		if (mode == XDP_MODE_SKB && dev->type != ARPHRD_ETHER &&
>>> +		    dev->type != ARPHRD_LOOPBACK) {
>>> +			NL_SET_ERR_MSG(extack, "Generic XDP only supports Ethernet devices");
>>> +			return -EOPNOTSUPP;
>>> +		}
>>
>> [Severity: Medium]
>> Does this break existing generic XDP users on L3 devices?
> 
> Yes, that is the direction from the maintainers on v1: XDP is Ethernet
> only, and BPF on L3 devices should be attached at TC instead.
Given the behavior change, I'm moving this patch to net-next. I know
Jakub suggested the exact opposite in v1, but nowadays we are try
to shrinking the amount of changes landing into 'net'.

/P



  reply	other threads:[~2026-12-02 11:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 14:25 [PATCH net v3] net: xdp: fix generic XDP on skbs without an Ethernet header Jiayuan Chen
2026-11-25 14:27 ` netdev-bot+sashiko
2026-11-26  2:16   ` Jiayuan Chen
2026-12-02 11:51     ` Paolo Abeni [this message]
2026-12-02 12:00 ` patchwork-bot+netdevbpf

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=1323c2e2-02ab-42b1-8bee-57a61d7a9e40@redhat.com \
    --to=pabeni@redhat.com \
    --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=jiayuan.chen@linux.dev \
    --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=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