🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7782

[PATCH net 1/5] net: add eth_type_trans_careful()

#7782
From: Eric Dumazet
Date: Tue, 27 Oct 2026 08:26
62 lines
10344 bytes
eth_type_trans() assumes ETH_HLEN bytes are present in skb->head.
NIC drivers always provide this, and they should keep using the fast
version.

Devices looping skbs from their transmit path back to their receive
path get skbs built by the stack instead. Their link-layer header
might have been popped by tc actions (act_vlan pop_eth, act_ife decode)
or OVS actions (pop_eth + pop_mpls / pop_nsh), leaving fewer than
ETH_HLEN bytes in the linear part. eth_type_trans() then hits
the BUG() in __skb_pull().

Add eth_type_trans_careful(), which first pulls the Ethernet header,
and returns a drop reason on failure, so that the few devices exposed
to this can drop such packets.

Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
 include/linux/etherdevice.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index df8f88f63a7063fbd1df5248d2fc02c859a7bc74..1f833ebd71ed917d138ec1e64c29689ae7dd0dd5 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -38,6 +38,34 @@ int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr);
 
 u32 eth_get_headlen(const struct net_device *dev, const void *data, u32 len);
 __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev);
+
+/**
+ * eth_type_trans_careful - eth_type_trans() for skbs coming from the stack
+ * @skb: buffer, possibly with less than ETH_HLEN bytes in its linear area
+ * @dev: receiving network device
+ *
+ * eth_type_trans() expects ETH_HLEN bytes in skb->head, which NIC drivers
+ * provide. Devices looping skbs from their transmit path back to the
+ * receive path (loopback, OVS internal ports) get skbs built by the stack,
+ * whose link-layer header might have been popped by tc or OVS actions.
+ *
+ * Sets skb->protocol on success.
+ *
+ * Return: SKB_NOT_DROPPED_YET on success, or a drop reason. In the latter
+ * case, the caller must free @skb.
+ */
+static inline enum skb_drop_reason
+eth_type_trans_careful(struct sk_buff *skb, struct net_device *dev)
+{
+	enum skb_drop_reason reason = pskb_may_pull_reason(skb, ETH_HLEN);
+
+	if (unlikely(reason))
+		return reason;
+
+	skb->protocol = eth_type_trans(skb, dev);
+	return SKB_NOT_DROPPED_YET;
+}
+
 extern const struct header_ops eth_header_ops;
 
 int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
-- 
2.53.0
Technical Details
Message-ID: <20261027082604.1485903-2-edumazet@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352276-linux-kernel-netdev=dewy.ru
References: <20261027082604.1485903-1-edumazet@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352276-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 1/5] net: add eth_type_trans_careful()
Date: Tue, 27 Oct 2026 09:26:00 +0100
Organization: Usenet Network
Message-ID: <20261027082604.1485903-2-edumazet@kernel.org>
References: <20261027082604.1485903-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1492337"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:O1KQRe91LB7b0Z+oX6wRZnbQaKQ= sha256:iRevfpGzWl6GVkW9kXDk7lMiXdgvfsz7acDp5CHnHp8=
	sha1:AehATVrS5fWBYUjS+Lyn1Rl1ty0= sha256:cBcOu97rhX1NGHYQK+nb9v00f9KsaJr0P4koaA4JzcY=
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 92666125BDF; Tue, 27 Oct 2026 11:28:23 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.739
X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, 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] 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 kzexChk9TCfF;
	Tue, 27 Oct 2026 11:28:20 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-352276-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 6A314125BDD; Tue, 27 Oct 2026 11:28:12 +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 B6F2C2AF97; Tue, 27 Oct 2026 08:26:28 +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=1793089588;
	b=ww9XwalCx1j7dvrpVYundy3QJHd2cSooxExl4aAHM5vjzwvKyFYbz8TVEWGj7gnJCwJt
	 m7i1lf84I0iPKrn098ZBLho59pO5dGKVh15oXAbI63+xKCO6HEn5sviSJnOpDQ8ikgRxS
	 fSDPQWBWVw27SSQBq/mwK1z8DWMZtLb4yFQrcN94N4tss4YnF9fyfDCi2bEO7St80/Yef
	 SC3L5Qtc+towQU4r1wmH+Ng6W/RVeiVouB4/wrr7clzOgx2n/7TVyrTVAU8qUc8Hcxy+8
	 H8tQ7uRZr1o2NV48TiIvA6EwYCHOHafnVJYadPVqynhOHFywT/HANCD1zXcz24dvjGQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793089588;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=oBdIxhoBqeVADlismHhWbqj1ZPcyaQv3xKqNln+xxfM=;
	b=XqLNoxiZVDEkKZq0kvoSrAq16dCggGS1F5HVtcQ22rw+ywkkcoXxzmK141jb5P2euwLj
	 LQz/GKfVgyoT8fPb2YqAKjtMJ12AFuvkA5yO+w4uTks3/BtS3Qm9p7LXNTmLm3wH1Q1Xb
	 7HnP0eFlfKAnQK2/TBaO1i4SEKHe+Fryxu+kEdDkKO1iZlMWPgFbO3ROM9Q25EcSZ/Y0q
	 csW35R551tT4NH56AAKsJ5dBUy2OFY612vKbYQ2qz8NI3Pd5kA/6w35cdz9Y8y11T4F20
	 EmTCxg6kFXY+GR/0oUHN3TBSImAM0V6aYc2SnnweasYSnsmerGsdwTfXC1KPQKakiCw==
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=WqNj1JDj;
	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 85B3D606A322;
	Tue, 27 Oct 2026 08:26:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WqNj1JDj
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=1793089587;
	b=G4yc7rHmVVAgIFiZFYFzQkZkbX11opT3zOKo+9McKwT2CwivFLgEDI471TgDJ092eDpz
	 P4rZUDM4VoDnU/JXSmzNNAuojEUKfKk/fWeMeuDG13wRfYsNgOregSX5XyhLFUH4Km0gZ
	 L3R/cVoqCQ96mlHxKFfCP5b+Lh/36ZQkZzxwXq1B6h1VD66XTvUH+lwb+SORlEg6OUs6c
	 fSLPIA673gQEaDmsqKAYfKnlmHLs6JxGgQlv6sOfqEUVRkLINK6kvfqrWO0D+CX4U1b36
	 6PXT/PTbaqtNJv8yk/f/p3VX0BZBiX8RzHShUqeIyHsjAiRVnKlUYVEoR8u38FQqHFQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793089587;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Transfer-Encoding;
	bh=oBdIxhoBqeVADlismHhWbqj1ZPcyaQv3xKqNln+xxfM=;
	b=4/EYW2jsjYGHVhuBlqTv3eaIIdelS/HvIuoExQUOeenk6CVMEarVvt0T4UddoJ2jBpVf
	 a7GVEMNCnAp0qkGMp57e6dXY/Lz0Ynedr1IIMgXWSh/zUVunfY2J4BcigD/14tTEJN6nf
	 FxztxU8Y8AwbJPiv6S6mvkIs0Y1pZlVr9DaTtFDw+u1WqfCTTeTtvinImLYjVy+fUzWUa
	 1zncjV/3GLkZCCFtJeLbf820NfxDsGmaY/HU0lOaUVbyGHweEi7/yrTDxFY35Wkcugh0U
	 gwEAvdUB0tgtK+KGtYSQUsdSY7Xx0OzrBy7LBzKvlSx8jURciN8Qa62zJC+EaXfHIHw==
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=WqNj1JDj;
	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 6781B606A31B
	for <netdev@vger.kernel.org>; Tue, 27 Oct 2026 08:26:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C25A1F01828;
	Tue, 27 Oct 2026 08:26:23 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793089587;
	bh=oBdIxhoBqeVADlismHhWbqj1ZPcyaQv3xKqNln+xxfM=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=WqNj1JDjGMTFX21RAKQMHHCHfilXB5NmJybt6Vzv4zbc0gwRFGnX+ZXVwQ18nQim9
	 6yFwny2xm+SnJWYgy5wPmBA5zNKJsbA5iC9JMgCXp2OCj0qTx6kqR9RIYMgTNMVG/8
	 37a70gYnCx+jC0aioZdLY7o//VvmV7WYlEtNf0T0l0HYW7hp+ohW66sm/+PmOYCEB6
	 pYZSTG7KKdq5kxHGJ/w8DDzpwwaGcnvZ0wufgP+XbWwKXS6+mNUUpek/Nubu9LwYZJ
	 NKQIrsme3hCus0oNhXy/ADSL7LJs1NGBtALwp8SzzXVKuWX45mDLOg9MTlEaU65bBr
	 OONBsePEWJPog==
X-Cc: Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org,
	Eric Dumazet <edumazet@kernel.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Aaron Conole <aconole@redhat.com>,
	Eelco Chaudron <echaudro@redhat.com>,
	Ilya Maximets <i.maximets@ovn.org>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Pirko <jiri@resnulli.us>,
	dev@openvswitch.org,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Ren Wei <weir@nebusec.ai>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261027082604.1485903-1-edumazet@kernel.org>
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