🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24883

[PATCH net-next v7 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}()

#24883
From: Anton Danilov
Date: Tue, 01 Dec 2026 00:59
98 lines
15125 bytes
erspan_build_header() and erspan_build_header_v2() decide whether the
mirrored frame is VLAN tagged by reading the EtherType at offset 12
and, for ETH_P_8021Q, the TCI at offset 14, without checking that the
frame is that long. Shorter frames do reach them: the transmit paths
check the length with pskb_inet_may_pull_reason() on IPv4 and
pskb_inet_may_pull() on IPv6. These only make sure that the IPv4 or
IPv6 header announced by skb->protocol is there. A frame
that announces anything else gets through, whatever its length.

syzbot reported the EtherType read for a short frame redirected into
an erspan device by bpf. It does not take bpf: a 10 byte frame
redirected into erspan or ip6erspan by tc mirred from a tun device
gives "KMSAN: uninit-value in erspan_build_header".

The TCI read has the same problem two bytes further on. A 14 byte
frame that ends right after the 0x8100 EtherType gets two bytes from
past its end copied into the VLAN field of the ERSPAN header, and KMSAN
reports them when the packet is received on the other side.

Read both fields with skb_header_pointer(), so that a frame too short
to carry a tag is treated as untagged.

The TCI read was found by an AI code review agent, in a review of
another series that touches these functions. Both reads were confirmed
in a VM on an unmodified kernel built with KMSAN, with the two frames
above. With this patch and the next one, which bounds the remaining
read of this kind, the same frames give no report on erspan.

Fixes: 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")
Fixes: f551c91de262 ("net: erspan: introduce erspan v2 for ip_gre")
Reported-by: syzbot+9e27778c0edc62cb97d8@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9e27778c0edc62cb97d8
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 include/net/erspan.h | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/include/net/erspan.h b/include/net/erspan.h
index c6209e7b6c96..6bda757b6da2 100644
--- a/include/net/erspan.h
+++ b/include/net/erspan.h
@@ -174,13 +174,12 @@ static inline void erspan_build_header(struct sk_buff *skb,
 				u32 id, u32 index,
 				bool truncate, bool is_ipv4)
 {
-	struct ethhdr *eth = (struct ethhdr *)skb->data;
 	enum erspan_encap_type enc_type;
 	struct erspan_base_hdr *ershdr;
 	struct qtag_prefix {
 		__be16 eth_type;
 		__be16 tci;
-	} *qp;
+	} *qp, _qp;
 	u16 vlan_tci = 0;
 	u8 tos;
 	__be32 *idx;
@@ -194,8 +193,8 @@ static inline void erspan_build_header(struct sk_buff *skb,
 	/* If mirrored packet has vlan tag, extract tci and
 	 * preserve vlan header in the mirrored frame.
 	 */
-	if (eth->h_proto == htons(ETH_P_8021Q)) {
-		qp = (struct qtag_prefix *)(skb->data + 2 * ETH_ALEN);
+	qp = skb_header_pointer(skb, 2 * ETH_ALEN, sizeof(_qp), &_qp);
+	if (qp && qp->eth_type == htons(ETH_P_8021Q)) {
 		vlan_tci = ntohs(qp->tci);
 		enc_type = ERSPAN_ENCAP_INFRAME;
 	}
@@ -268,13 +267,12 @@ static inline void erspan_build_header_v2(struct sk_buff *skb,
 					  u32 id, u8 direction, u16 hwid,
 					  bool truncate, bool is_ipv4)
 {
-	struct ethhdr *eth = (struct ethhdr *)skb->data;
 	struct erspan_base_hdr *ershdr;
 	struct erspan_md2 *md2;
 	struct qtag_prefix {
 		__be16 eth_type;
 		__be16 tci;
-	} *qp;
+	} *qp, _qp;
 	u16 vlan_tci = 0;
 	u8 gra = 0; /* 100 usec */
 	u8 bso = 0; /* Bad/Short/Oversized */
@@ -288,10 +286,9 @@ static inline void erspan_build_header_v2(struct sk_buff *skb,
 	/* Unlike v1, v2 does not have En field,
 	 * so only extract vlan tci field.
 	 */
-	if (eth->h_proto == htons(ETH_P_8021Q)) {
-		qp = (struct qtag_prefix *)(skb->data + 2 * ETH_ALEN);
+	qp = skb_header_pointer(skb, 2 * ETH_ALEN, sizeof(_qp), &_qp);
+	if (qp && qp->eth_type == htons(ETH_P_8021Q))
 		vlan_tci = ntohs(qp->tci);
-	}
 
 	bso = erspan_detect_bso(skb);
 	skb_push(skb, sizeof(*ershdr) + ERSPAN_V2_MDSIZE);
-- 
2.47.3
Technical Details
Message-ID: <20261201005941.1536429-2-littlesmilingcloud@gmail.com>
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-374582-linux-kernel-netdev=dewy.ru
References: <20261201005941.1536429-1-littlesmilingcloud@gmail.com>

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-374582-linux-kernel-netdev=dewy.ru
From: littlesmilingcloud@gmail.com (Anton Danilov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v7 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}()
Date: Tue,  1 Dec 2026 03:59:37 +0300
Organization: Usenet Network
Message-ID: <20261201005941.1536429-2-littlesmilingcloud@gmail.com>
References: <20261201005941.1536429-1-littlesmilingcloud@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1579559"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Efc0tgTdZZdJcnhYwVLErVQAo4k= sha256:JxNxjeCFd4dcb3cJ6gRvnFgL3c5vI5mAhpAtVN1l1Mo=
	sha1:nu+js+3BgQ/vIgJgj7WGpUYqK7g= sha256:oIsCz9zprPg1ze86qV236mDls2kKEa0jM7QI6Z2dUYs=
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 98E0E126019; Tue,  1 Dec 2026 04:00:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=gmail.com
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 lf5hmGFhm6dl;
	Tue,  1 Dec 2026 04:00:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374582-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id B8E71126017; Tue,  1 Dec 2026 03:59:52 +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 EC7E5259E8; Tue,  1 Dec 2026 00:59:50 +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=1796086788;
	b=tQ0Guy/q9dSU7lKgzGG6ysftvcbN+MgLpaaA89/x9hzXajqTP76QtErsD7tXKF8DCenT
	 hlqTT74BCgDR2Q0im+UxG1GB6SWkb02oJbiTgiOXp092IfwvNopv91A5QD0r5P7PevXRD
	 RA9FYEYeiN8Ao1LWyMcaKRetRkTlpzoz5g1CiwDqFUfSAIGaHmFn/ETOKFlPyNYrSKvJs
	 IDZAeFmjtSujZXqwdYuKb03jlmQhHUP7baJkHWP64shT/F96aVGJOtEtjrBt6xULO1mkV
	 YyiEKxd937wUJ4fqGjuagwnpeN+9bPVqAVeiLCMxY8cr/hkpaE1pfZAdRVMR0agQEPg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796086788;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received: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=tAaoCixZy5GRXccPe1zkKorN4wQ5BUMlw71Tsl4uIXk=;
	b=pnOmb77fEe54lqhzSoj02/RGQ8cXSl+K/pfRTLXsalw8cEPjHiPlwqbXg9bHWzLSKHfj
	 4b3rTMl+BD0x9/MH2ctw2bHRF923meWnsw5y/zxIqeiLlDl0fJQqM2r3oFru5MVWWSUVg
	 lq3U1w/sC392n+nTQ6M2GG+MiQMIxrK9qgHTT1OK9Y+7CG4ZuYS3bAaAS3UOQoIEU+4ry
	 3HoZ/JLq3+xzmw1bpRygDAmXF/39QU1B5Iek7pnOlxTMKGe7tO4wrp7BiyCxUnqWy+mBU
	 lXKY4uvUHK1NgowTEn1LVeFshTpqnnwUJziE65WJyNw8E30etKIZgj8ZCklu0EAnQSw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eu9zcm4P;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 B4D98606A32D;
	Tue,  1 Dec 2026 00:59:48 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eu9zcm4P
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.53
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796086787;
	b=ESESYE4Lj/ZxfPHj4rzFYSbDzBF0HWXOinTtO/hFh6S9vPC4nvoUHrQAuS2hGwvm59pI
	 CzoQKRm2I666tYE2y6aGnoLmBmp5CnVDrYwykkk4Az1AQJKAtvo/UMVbXrePu0441/1c0
	 ckDGQ0xMaCPcBaiGYCDqb7QyFPTPH7FAGuqf1R90KNzSvQ5/elPnqXHuWAVD0QWpiNfc8
	 uthtofRU/KyhuzJIZtl2xmIs258mhuEHVXmOMQtxX5MnE0Y4aX1w/gBMnyuO8oHbY4BPU
	 MDW8hGF7cv4zniT5OVSwymKlyEGHdxtdR9PtR61klUYrdjX+QyWWLrTKwHKzPVc7Pgw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796086787;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=tAaoCixZy5GRXccPe1zkKorN4wQ5BUMlw71Tsl4uIXk=;
	b=TP6Nyq3X7WWmyXRxpGJbJnb7xXVwMlXKClu2l6WOQSy5Vgi4ug/ltX/J3pV1A1U3mKpv
	 hDPZG6BZPEBmyr4IwAGq1vZ3gtRWSEohESZIKwHHUUvUfGpXxsoRJEaQimKrsLGvAJxlU
	 DJbiOLJP6BSFwbluR7aiagu5ntT1O60YT3+KnwZjSnosph59UpVY0a2eCImyGpzt/O25I
	 bgX8xlVnkwNlOGqooTVqdqdc0UJCRn9cILHPU+lFcw5yCeq2nN2qvqe+jEevf+ZviY1Lo
	 dhqekK47RpN7gRxO6/LJMvkXWmbQJUSzyBbHdsJ5XwmRZIXF5QsGKj7cLORYpV6lVwg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eu9zcm4P;
	arc=none smtp.remote-ip=209.85.167.53
X-Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53])
	(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 2A835606A332
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 00:59:47 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2A835606A332
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5c126fa1e3aso381706e87.2
        for <netdev@vger.kernel.org>; Mon, 30 Nov 2026 16:59:46 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796086785; x=1796691585; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=tAaoCixZy5GRXccPe1zkKorN4wQ5BUMlw71Tsl4uIXk=;
        b=eu9zcm4PrPwKrzr3y9Epl5SYl0k421wxly1HNhP8PYhxoBTz2kU8bWty4wDUK6FgGt
         IAD6HPcxr9+bT6w8LTAXSM7/h3FrfzfBEKJQfu1ON55qjL51rA1NzCSs99bivCyuoNpo
         tY8XCP9po88y4vDt4GovzOdxuEfD+iAmXcdYWHP2I4Na7hkN+W2kUPbLvW3h+P8K8JQ+
         KDaf/J/+rG5FQik5pbQJ6yOvJPIsrVVmTBqit8KLEYNfFWerhxdgg1fJ6j/u2t+CAblc
         DQZlnRjLcDBbaEaZub2ldV7BBcBFkVEQ8exN0t3AEKv2azvdOdhJ2s/1KvGxevETMCq9
         Rf8w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796086785; x=1796691585;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=tAaoCixZy5GRXccPe1zkKorN4wQ5BUMlw71Tsl4uIXk=;
        b=i7srUa031w359PsYjnG8jnOR2dFjpPkx1LP9ZV7xqlJ88uuRVFi9uBSL76hmlsVLR2
         ziaICeh7TfZWdL/VgHD0BO5A3zukurbgMC+rlQpA3T2nOOQovsfLzWG5brY+7Owu0m6o
         RipHMHNejAnCwkt1udhflIpJMrjOfM3HTEaJDAqW4HhFsr5ABXfxfqwq7GqPRHnem/3n
         dBJCevSq+cxOu58mc/UvFabtl/mmAr+g0i7Grs2Srp6qWrPdZwOpOpYSrAEEt4Lb3Ixw
         cM8G1BmmgZ3leNL7S14HKcSK35leBvn/E4b5E0cCY6wkWlhdQl7RjCpSPR88aoDAB7zR
         fRTw==
X-Gm-Message-State: APuU4Z90ESPHMu6A47blbWY2RZkT2yajM/CXfqCTPJY3GtrUfCWXD3rk
	wFam/aWrv3oNb4XWiVOpj7GcctSZ3DgYfAKM8uw3TNGUz1Q+sWBig1st46+vsuro
X-Gm-Gg: AZFdTZfVRJF2wytTxUP6bom+3earnKZFoG8vJlcUhu68Y2vvXSo7QW1d5ail5LtKkDC
	UWLXQH5V8CVunl3ALM3xjwZNcjecvWCpQUtXAUtZtikrAZF6oxOTNQRo0dq3EBshzWJaoSyMOqj
	nCJ75F4d66X8kT9DzFaaxVs3C9Dw/wybRHl25vlae0yfaRrV51GeJDze1OYUBoIoXcw1IlYok2L
	0eaTefOxjcBwY6dtJfzkPOVqkfWRM/jlpofHKPVnbdoalfzHz1R5cgSaMdEdhRbKVPVt/6hvR/d
	6ncz3L1lBqHWNjn+4dFYp+GkzgxRGM3SPQfy9EHmZWY6/h7FhTM+8t0MIll/I5tjAJufdR1Zo3t
	zRMPLdXGcADs+aMZ7/C4Qva3NlCD7zxLXtzYR8hJffIU0rz1hGVzctlWg+2Nck/ej4y1ZSpjtw/
	g3ekeEsfFxqeL1jijgUAZ+5zLKjNXiLqiAwDFsCq0Q6wMclbAbHPoAM/4iWnOn70YxN70gARN9f
	ttO1QVJifSplBA405qYoahNviqIw7Djwh+feWRq6F1B/M2Qz1xDKIRCLsV8jZ77HKFk9vSuRAbE
	VTbijt3E6hKAQu+KSzqkAHLpOGb1uiFFa58L1e64QQ1X/C2dz9wDkrKdjjhN0W0XZ4li5NktOcT
	JwWHHdFXpVlimWf4c54XZhvaXLnzkFSlq4nb9AQ==
X-Received: by 2002:a05:6512:39d4:b0:5bf:b994:65ab with SMTP id 2adb3069b0e04-5c1bc844788mr10124629e87.40.1796086785173;
        Mon, 30 Nov 2026 16:59:45 -0800 (PST)
X-Received: from dau-home-pc.megasoftware.org ([94.28.149.75])
        by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bd040a9bsm8895709e87.48.2026.11.30.16.59.43
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 30 Nov 2026 16:59:44 -0800 (PST)
X-Cc: Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Simon Horman <horms@kernel.org>,
	David Ahern <dsahern@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Ido Schimmel <idosch@nvidia.com>,
	Florian Westphal <fw@strlen.de>,
	William Tu <u9012063@gmail.com>,
	Meenakshi Vohra <mvohra@vmware.com>,
	Matthias May <matthias.may@westermo.com>,
	Mazin Al Haddad <mazin@getstate.dev>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261201005941.1536429-1-littlesmilingcloud@gmail.com>
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