🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20937

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

#20937
From: Jiayuan Chen
Date: Mon, 23 Nov 2026 12:15
91 lines
12239 bytes
Kenneth Lee reported a bug [1]:

  skb_vlan_push got skb with skb->data not at mac header (offset 14)
  WARNING: net/core/skbuff.c:6474 at skb_vlan_push+0x5ec/0x8a0
   ____bpf_skb_vlan_push net/core/filter.c:3239 [inline]
   bpf_skb_vlan_push+0x216/0x8b0 net/core/filter.c:3229
   bpf_prog_run_data_pointers+0x17c/0x240 include/linux/filter.h:917
   tcf_bpf_act+0x31c/0x940 net/sched/act_bpf.c:50
   tcf_action_exec+0x2c1/0x720 net/sched/act_api.c:1147
   tcf_classify+0x6e4/0x1080 net/sched/cls_api.c:1860
   tc_run+0x31c/0x5d0 net/core/dev.c:4411
   sch_handle_ingress net/core/dev.c:4486 [inline]
   __netif_receive_skb_core+0x141b/0x2ec0 net/core/dev.c:6054

bpf_prog_run_generic_xdp() reads xdp->data as an Ethernet header. On an
L3 device like sit0 there is none, so the "did the program change the
header" check compares garbage, and the fixup:

	__skb_push(skb, ETH_HLEN);
	skb->pkt_type = PACKET_HOST;
	skb->protocol = eth_type_trans(skb, skb->dev);

leaves mac_len == 0 with skb_mac_header(skb) == skb->data - ETH_HLEN.
tc ingress then can't get skb->data back onto the mac header.

XDP is Ethernet only, so refuse to attach a generic XDP program to a
device that is not ARPHRD_ETHER.

The one exception is lo. Its type is ARPHRD_LOOPBACK, but it uses
eth_header_ops and eth_type_trans() like any Ethernet device, so its
skbs do carry an Ethernet header. Generic XDP on lo works today and the
BPF selftests rely on it (xdp_attach, xdp_devmap_attach, check_mtu,
...), so keep allowing it.

Rejecting the attach is not enough on its own, dev->type can change
after the program is attached. An empty bond or team takes the type of
its first port, and TUNSETLINK lets a tun device change its type.
dev->hard_header_len is no help either, it is what the driver wants
reserved on TX and many Ethernet drivers make it larger than ETH_HLEN.
So also skip the program for skbs whose mac header is shorter than
ETH_HLEN.

[1]: https://lore.kernel.org/bpf/20260812043643.808295-1-kennethbwlee@snu.ac.kr/

Fixes: 297249569932 ("net: fix generic XDP to handle if eth header was mangled")
Reported-by: Kenneth Lee <kennethbwlee@snu.ac.kr>
Closes: https://lore.kernel.org/bpf/20260812043643.808295-1-kennethbwlee@snu.ac.kr/
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
v1 -> v2:
 - Generic XDP does not support L3 devices, as discussed on v1. Reject
   the attach and skip skbs without an Ethernet header, instead of
   running the program on them.
 - Target net instead of net-next.

v1: https://lore.kernel.org/netdev/20260813113229.381136-1-jiayuan.chen@linux.dev/
---
 net/core/dev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index 1a63f6b939f7..7598ac4c217b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5844,6 +5844,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;
+
 	/* XDP packets must have sufficient headroom of XDP_PACKET_HEADROOM
 	 * bytes. This is the guarantee that also native XDP provides,
 	 * thus we need to do it here as well.
@@ -10869,6 +10873,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;
+		}
 	}
 
 	/* don't call drivers if the effective program didn't change */
-- 
2.43.0
Technical Details
Message-ID: <20261123121540.275576-1-jiayuan.chen@linux.dev>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369308-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369308-linux-kernel-netdev=dewy.ru
From: jiayuan.chen@linux.dev (Jiayuan Chen)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] net: xdp: fix generic XDP on skbs without an Ethernet header
Date: Mon, 23 Nov 2026 20:15:34 +0800
Organization: Usenet Network
Message-ID: <20261123121540.275576-1-jiayuan.chen@linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3871262"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:yp0x2GSy9lyRRzS3XitbV22VA6o= sha256:/ehMme4L23ptPpEQgh9NJY+VD2SJ6MpUaN0Rw6Xs6sA=
	sha1:5lZMTk/p62GuIL1M6ak5T6POVqM= sha256:vcbehz2NlNOg0G/s+MejBhTE6aSl4A3ZF9kHIdnr5mU=
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 5242B125DAC; Mon, 23 Nov 2026 15:16:23 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.051
X-Spam-Status: No, score=-2.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	HK_RANDOM_FROM=1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
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 O3qgDIM4lh8G;
	Mon, 23 Nov 2026 15:16:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-369308-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 8EBB4125DA6; Mon, 23 Nov 2026 15:16:04 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id D192E268D1; Mon, 23 Nov 2026 12:15:55 +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=1795436153;
	b=cKsBZg0wGGmKxVFm91lFy9gsX8jYzEi0kHiJ62KgiOoBOoHAlc+GxrsqR+apguKgEUmU
	 2BrCzcUVNW98YxA0ZySMMj6UZks+oIfwxdC6FL3GEK50pDMV7Mq67HZOv3WcqnMg/S9wg
	 A9pHHfREqt/pRG7xDNaHO3LhwFS9RRmxsz+8G94MH5CCBKFFIQXUwpGdEZo6p0iEC2TEr
	 okBUNsLkGZuCsW/eVkwrZj4J7JmkXy7ZE6HTIAc+jHPWpysWwby56mMCZ931wuxsg03Pq
	 OUIy535+cuNsCKsEDVv5bXSv6tF7VsYhMn2telQGbRyYX0lqW1BTKNPufSFPdYCq/pQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795436153;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:
	 Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding;
	bh=bZXodFX/JC+676ImzyFGUevH85yaSaEwQLZwFDM7ocA=;
	b=QH0VpLTMNpe+TcneNjbslq9OkSqrBi0JZZE+LRs8RRX3ua7h9dR1+hQMj3hLVHapV4aa
	 XZBDQ6lKpRTnDafBue4I9/VNtHm9K8Oej6G5n9TgAZYejA2G/1dLD4fSZ5iAr3gbBZ206
	 9vfxTBEg+Cr2BHifXc+PyWNxTKpMhg/wCfsZ2UY4rzLmJZ/P7R3YujsgsUVd0mNYu8QnE
	 4I8xEz0pJHDeNiFt3J/1IvB82fPlaoCjerps1e/4L0Fi60WYUTIua84NJ1MKbmDF89Yn8
	 HAf4ZICHAYE7OGZrFINOQr9nYYuoZuDeN29Y5cayMAxZyTmg1J+W4lMmPbgFJ+OhGYw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=paZhpFN4;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 6A3F5606A334;
	Mon, 23 Nov 2026 12:15:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=paZhpFN4
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.67
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795436152;
	b=a5E13dBcvcZzbuZOmRewopekD9S9rjV3LvH5gBpv4rNYChk8Yh+0rFYJljo3k/Tlm9GP
	 cs88EmXBP0AJs5lKPoS0tb+BRHObcG+ePl+g33zUtC1NjLD9kLAqSV41Zcj6U3M9LQbUB
	 YNLVE3tPo8x6Pic4gfFpXF57oqDiOQhIPWdJ4jZwyLZgMJztcgRbazEeL+v5Bwe8uf/rw
	 qKFTI0G7J7xqEEMhucEyCgi46U/881jxL0V2l+MHGZ430QfWECxw6ScSfosppjUP+0mxZ
	 Q0F4FYtLOTzB49RKY+onD7AnXhahGZTpcXuNDOx27fSF9ku2s2J9dev/MZ2gGj8ULRQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795436152;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:MIME-Version:Content-Transfer-Encoding;
	bh=bZXodFX/JC+676ImzyFGUevH85yaSaEwQLZwFDM7ocA=;
	b=BazirNstSbX+pyL1JAfX+ABBxW9oJbrtnoIsoiN+LOKCFzkDWMRTuSwcwaHu43S5R4h0
	 aovgfp30kBQLbGJI6g1/ZIfIyhsmB+PKaUmEXxOYfyDavNnH16Ve9nkQniWotsN6WzbvQ
	 xhnEYQmU7thDhfMIUUhc/wQx5CyoOyHHQZvKWgJtwX4QayZ5V5s/L1mVxSnxQdp8XgZT/
	 P94aA3ywKPpSUK4fu7MRLjWPME8AD68HvMNVvq45Dx9vCKfcUydUDt66XrK/iViJ3hhKt
	 fn3i0HCSb1f40l807zYSFJISUibin+tkvZBfzNUR1AIBMFe0XDgVEbQjedcWzhWYYMA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=paZhpFN4;
	arc=none smtp.remote-ip=91.218.175.67
X-Received: from mta0.migadu.com (out-67.mta0.migadu.com [91.218.175.67])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36AC4606A31E
	for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 12:15:50 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 36AC4606A31E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=oQZk156dD6Bt0vOiMV0cjdp6bnV2K6jfTP6MrnNniCw=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795436149; v=1; x=1796040949;
 b=paZhpFN41ov31O7rLqpKuLrZZR09hWndkUHmR6PrAswDLT3/z6MYNLfeFDkSZ5KVypk13ZyU
 uCoyey0R2GVycZSp7kzYsjkz14Vxq3/Dt1Y6pHCdidZ5ObGthWEN2dLNIjRVNctapGTPAJrqeG2
 DnfAwwzJBRAwIEA9sJc38+yk=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 6e185afc4a3cd36b;
	Mon, 23 Nov 2026 12:15:49 +0000
X-Mizu-Trace-ID: 6e185afc4a3cd36b
X-Migadu-Flow: FLOW_OUT
X-Cc: Jiayuan Chen <jiayuan.chen@linux.dev>,
	Kenneth Lee <kennethbwlee@snu.ac.kr>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Wang Zhan <wang.zhan@smartx.com>,
	Martin Karsten <mkarsten@uwaterloo.ca>,
	bpf@vger.kernel.org
X-Mailer: git-send-email 2.43.0
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