🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21750

Re: [PATCH net v2] net: xdp: fix generic XDP on skbs without an Ethernet header

#21750
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 12:24
107 lines
12042 bytes
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

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123121540.275576-1-jiayuan.chen%40linux.dev
Technical Details
Message-ID: <179552306350.3135.16282643834784138893@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370325-linux-kernel-netdev=dewy.ru
References: <20261123121540.275576-1-jiayuan.chen@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370325-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] net: xdp: fix generic XDP on skbs without an
 Ethernet header
Date: Tue, 24 Nov 2026 12:24:23 +0000
Organization: Usenet Network
Message-ID: <179552306350.3135.16282643834784138893@kernel.org>
References: <20261123121540.275576-1-jiayuan.chen@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4131980"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:G//iasMU2ERyKDi3wLCaR8PqfmU= sha256:6u3XrgFaqR91pF8S8cLcXyc84HSTE6RpwJoFIQ2V4WU=
	sha1:1e5iyYTBb2jvGX1dNEibW/hrxq0= sha256:4zExQl9fKlxLHksz9LQSSiRPqRty8yfi8e95YFu5gZE=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id BB371125E12; Tue, 24 Nov 2026 15:24:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id swULJzknd7mE;
	Tue, 24 Nov 2026 15:24:43 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370325-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9D8FF125E0A; Tue, 24 Nov 2026 15:24:34 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 6876B3A599; Tue, 24 Nov 2026 12:24:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795523071;
	b=nPqKr8Y68FJ/WP9m7NkoFzlL29J39nxnxGIMquG5GMdvpUJ8u+ejBslg5WPvzWHX3kCH
	 SpQA1e4KX95/bnlvbY6j74DSeaTOmzpeyTY3ept11Mf5w31b8TyHWyYuN+L3S7SftLpXe
	 usUm11L/Yu239q/EJk6dgCnyDYjQExA3RXReY63ZAQLn6/MOV4vAfGTepEec9darR8gYQ
	 sUfO5g3muBHdgc+cm2ofvM3OhFk10FHuCkzYujX2HfTAD5aVRswHIbO/2FPjmza14eNIk
	 OCPiFEm1wKfumSVaqkmJsoPDJ3HQ+GFeAlHxQlJ2EaqcgccljR1wVgSAFcbxUworVpw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795523071;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=3RgPDHRoRZYFO88F/iEnQNqSWM4u5BLq3aNl2+2XP7E=;
	b=Jm5c+Wx4FvvfGOnlYs5hb6S8VODAOPSFbsz+13+1JLAEd2G9sG0KvGskVP7yyLntoRhk
	 IVPzqHXETu7lB3UJ/Pdd1d62fDTPH/XFzuKNoCwLN/ifG+h3B8qdiKEWaLxRJzOVddiIm
	 nHnpPb+gzg0CAsRS7kjSpPd7zs3Z6/hBm6xIb0Kn5KA74081J1uuVGCR9FtfJXRMTzioV
	 jc2zSaO/pOUcqmhKawwMgmIjj0EPcwW2Bkp6h4Cl+2XtOLDyvpkw07YUuVwoaYQ8fNREa
	 QjaoyxCGNxRGgrl0OxPl7RphhLQoXGlSDHf2z84GsP2MgLmDQVAAlrZNlaL8eA5nYaA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bnNdBStn;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E02A606A327;
	Tue, 24 Nov 2026 12:24:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bnNdBStn
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795523065;
	b=sicOgQOcX9MjAu6GKiTwWyfz6JNg8eeWAqKaC2IX3eAohroFSS5uOgYwXpw78AZ7gu4n
	 w5zGWmeL67i5roBey87bnuvwaLGUnu/2XoZg3CXikTLxYZHAMZFx9EJS8WQzgBrDSAxJg
	 ITRgjVlGWi08jKJmdX85OupxVHXpZMT1G4UW01bKR92kq/k298eDIOk21uQhTOIJblhCm
	 e7ExT2xUvEQe+FNi82pVvkjDkWcIw1ZSgameOK5l5C0efQxqOGbQsmFXj954+mbau6rUv
	 sgpc1dJIxOsg3aFlg4OmwOIWQQwtzQy1UtpD0u+6FbRLgufal5ilajJK34MmuVKYmVw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795523065;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=3RgPDHRoRZYFO88F/iEnQNqSWM4u5BLq3aNl2+2XP7E=;
	b=hCoWXF7a0KN0cbOLlIHxbg4fdTbu8tRoYcZAaaqV5GuqtN2PH2j4P6iuuOUJEcftUgYn
	 4HpwTC79qNPhoRgqPAoWHuqhnI5BKEbxLFeRiidVdjZ417m4TDi4ltl7qP5J5O76vfHon
	 nxHjhy1sfUMX9SGZJjKW53/ydjK7BuJe4+4bSFh8BUPIm6ssBZVhcFxuBud93Igh9SoSA
	 KVLLkM8GDre1Mi7mJTs55/FmwXYgH3pq4xaK4RhuvX+65Lk4NgoShooHUWpbGc+XKxd2q
	 MWD6imVj9m0QC8EsKBHMpS5ou7Ckl89sz5wHdpVpXFayr+Lf+dWulq9+07e+F73CpWQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bnNdBStn;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58E98606A31E;
	Tue, 24 Nov 2026 12:24:25 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3B211F000D0;
	Tue, 24 Nov 2026 12:24:23 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795523064;
	bh=3RgPDHRoRZYFO88F/iEnQNqSWM4u5BLq3aNl2+2XP7E=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=bnNdBStn1H4rajUmtV4VBas0NXF6RM6XPIkCoMrQlzyVihPKH1jFJT0WmcY8Qc1P+
	 InVi9xco5vwjuNN+1QYb0pX05n+ty4GN3dur/UqJy7TmDr8OIQ89XoSx/eOFAKXNjg
	 q9F8eYkRN74LDy3T5TSsdIXjFKIXXJYQOU8ZONxvV/pkc+sCQYUeYrCOy5RJpvQdYX
	 GI4S/bQ5NMkuKaf8K8eTDUDiQhS0QdKnXZ47iburtU4CabNouI3/0Mtgxkpr0E99kN
	 GDelaOyYRzHLc8mVzDCrD91LSdIUv/Z3eQhVNOb0dsT096jmJZicRHiKqDrw6KXEvO
	 zx3EduhK7vNcw==
X-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
X-In-Reply-To: <20261123121540.275576-1-jiayuan.chen@linux.dev>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list