Article View: linux.kernel.netdev
Article #25778[PATCH net-next v8 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}()
From: Anton Danilov
Date: Wed, 02 Dec 2026 12:36
Date: Wed, 02 Dec 2026 12:36
98 lines
15139 bytes
15139 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:
<20261202123613.1708463-2-littlesmilingcloud@gmail.com>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375777-linux-kernel-netdev=dewy.ruReferences:
<20261202123613.1708463-1-littlesmilingcloud@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375777-linux-kernel-netdev=dewy.ru
From: littlesmilingcloud@gmail.com (Anton Danilov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v8 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}()
Date: Wed, 2 Dec 2026 15:36:09 +0300
Organization: Usenet Network
Message-ID: <20261202123613.1708463-2-littlesmilingcloud@gmail.com>
References: <20261202123613.1708463-1-littlesmilingcloud@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1970345"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Hg9dTr/dxS1V/QTQHS8TUeOZzmM= sha256:9ScZ98InqC38V5oujGeR4EI9FWeTLP1C7byXZv6j0Ts=
sha1:eLIQy3eJV1JoQcIhwjM2UeOovWA= sha256:JonV75outQvkG9vhCXuCDrdmmJUx9+aICdLiBZooyNk=
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 E9D58117632; Wed, 2 Dec 2026 15:36:47 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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, 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 pmX673YkdJd4;
Wed, 2 Dec 2026 15:36:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375777-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 5463D11762F; Wed, 2 Dec 2026 15:36:36 +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 4701C37168; Wed, 2 Dec 2026 12:36:23 +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=1796214981;
b=KkqxxcEOaskx9YLt0RXyIbTEf/QNPndwhCnattiN467tehI5DZiBPLpz3qewJYeLYp3g
+k1mDbvIZxrrNUfnF7X2yT93YFrf5pAJbrBA4uIlfjoeCP7tbQWd9H9/Mz8NgHGJhal8Q
5rxx74PEAPu7bvY0DNw+1E+lJEycHUojUCGGNy7ll58A9ubmGTncr/dByb3IeEbZtCluB
Gsssc4eR0nfhRftKro8eNNdQ//qqt4CgqyEw5tj189vnWjd6eDRtyO/nS25hPwrE8WwQL
yvxQhr5XgJxYYVmsApfRsLdfhuTPpjNEdpqB9HyfvdlKc6Q3YHgFWbQztVrdaeyxn0g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796214981;
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=cIvm6zHVNmFmxiL+/7F0Afqe+E58oAfcxLLeWdVqHBrAU8m8Gf44UlFfo/xKacNdxj2n
XkU7pDMzCVElmYjxCjaJEnqGV+apdf/Ai0HccvJYnYPOLDM32Bop8ZIq87sW7m16O8Ytg
fVoG0tNymuP/ElQU0fYd289MUQvu9GMLCRf45CAZm2E2vOhWeu8hg6mEa5aXhWbQxq4so
J7UwfACe2Q670SwCyGzcgJZoreSkT4O/qLXkJ3WSizvsCZGwojaFeLX4te5DPqBbz8wtI
o/homSQi+3kTFefiEd15O9q0IgAUCTd5hnq7Rk81fVzsjUTcb6/AhBNy7BEqmSrWMTw==
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=GkdFeYLy;
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 7EDCF606A330;
Wed, 2 Dec 2026 12:36:21 +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=GkdFeYLy
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796214980;
b=LhVxEDdfD1C5z4CrI6Xsb6Re4AnZnIooZDZqcGNgp9tZlQTsiyI3vqD0O/zBfY+qnjMF
2JXAhwyYSeM6CiXpZbK29ksgDiLJ0P+3YufDzbo9UpJz9gw0l80fiD4bch87fm3boImP+
Lu6lgbj+lvJd5NZwZxxrE8T8PLgqhl5NiUEe0AMwM1xR3sLINGeQulMd7UlgcmebcFDxF
bFXAHvnDv+44YRj/eIIbjm4awBStSoeHxAaoxU/5q5Pcp3/+XWZMSXBGhpT+UU9EZW0T0
xly+y1cAsrRCluG3I7Jdviwir/bKdXvMz+lWalkQkNbswM+CD23vMwedUosQXzBf2dw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796214980;
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=DXibANZERn0J6J4rWoc3xyKVBahy9eh6ZHjoKE55j/DhS1cmdouS4ro4e4lqPoDA55M2
/nKEI7fassZSNCHDQTsFp8W75t4a606tZKf8zI9OiZolsfNQHDPbknzbl9Hj2vDtofBTS
69WdTdDJG0nP3bhXhW1FdpT6r79xis7EnuwgqK8X/ODrgE0dv0tTOc/bKQXQUaH2jyE8w
V8wdor9ysafVUh4O4ugfslDQe0hKaJyA7KwS+xakiOlLIGVpegD0bdLq0kuZn1oLs7ete
jzEV47b0ZJNhJ4LEwtMQ/8ugRmo42pe+MmvXgJnLHIndU1oqPCBUG0tFH5fVzNEz93w==
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=GkdFeYLy;
arc=none smtp.remote-ip=209.85.167.47
X-Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47])
(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 504F4606A337
for <netdev@vger.kernel.org>; Wed, 2 Dec 2026 12:36:20 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 504F4606A337
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-f47.google.com with SMTP id 2adb3069b0e04-5c10dc41270so13414779e87.2
for <netdev@vger.kernel.org>; Wed, 02 Dec 2026 04:36:20 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796214979; x=1796819779; 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=GkdFeYLy1myCuyUrjDQChfCUe4JMoz05409SR+1ZCDVq2NYF/b3vAeTc8DGtaZdv1g
nJtXu91FnDxd2mmeo37If6sil9hweEpXAaPNtqtNINAVeJvnNfaerUADjUHHbb5WUrXu
Znb2j2TVJh9RKvKSBhTQG9B8sLf4zPleyeQpZXDldmA6FTP3COKXn/m4Zdd0dW09XqtZ
Hk1lAb3LI0wM6NBoI0F41Sa7waRQWznEG2670SC0+XhacbRY146hYATmJyXLrSA4fR5T
AZY7hl8rPyJ5FgvxKg9YGB0oo579LZqdeZaIulEf5GFYloGNTk3RHW/Bmt/RhU/egE1M
ibCA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796214979; x=1796819779;
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=Gte08esh3vIlqShP9fzoSnbeNBd1uCTYzCO9U4LNZpW0okDJ4PpdO6Q/8+Xijc5vB+
ygLH30kP7CrG+aPa5fhcS4iEuhCY022Poo8YIbhxaz5yuE8e/F5vkMufgVwlGkDdPZ9E
pUjXwtBjeV5995zHNBbHyWvAmFBzB14XCP/B7Jr0031lfEHBVJ8BokloA25X+JxiiTLu
3b+K8rzuFg6RT3GBSOSz0bVlyyFf4W5Nh+32s+LcatCxfdMLr/js7Y5WiIDlA27AQrpQ
OsMvIm69h+AEJOaGUOo/6oNrgDSjJe/jUpoEK1GGYQMj7KID+sUQJnfFJ/JdIW9fR6Ua
3/Rg==
X-Gm-Message-State: APuU4Z/bbY3yUw4gkXCw6ml+9kyGiH5BXWu/YJR3zqb19JgeCpPp5wZ9
set6nEG0AZ3GDVCIUYonVNGmaq51evv8LlbPnN+ADNgD+RlVc2xG7nVAUYjDsA0eTwB9WA==
X-Gm-Gg: AZFdTZegAs8VvhB8Qdusf80G0OQkNZV/iJgyfZg9dzLiUw14M3NEHJBQlk7D4ln/3bI
VhoGAySmkfLJIyYw3bPgNfgDLlWOEYDe7+dIt5SAHSt1X+/VLeYF5cQOsAQIUqdyX34jGJJDqBs
IIc+6pW4GVFL83uofEtR0gtxtlbFy2g+WddQAANZKuCQyMxSGgcuuBqy9G8ZcWavzsyW+/sBgob
uofyqOQaPUUEx6YkJmVZ2VBbL3mbauKHG3dq3Geg6FhcFJVJDQj2/wqcJ2HaIpAV7j5cd9QZaZn
a5ASwPRE0At0cHjWF0NqfoBRGV6TfDfdIZ2YVFNer6a+A/C8mLSr+KekhVIhcW4ix16BO8I/YNt
5pmjIrksPh0uvrLczN6kY4ODAuWQs+IzkfiOY2kF7iK8yFs9y3CvDF9wSNbipxH9dgYunLEMZsl
nZM2+CluYT9cHKuzS3IhLuuo3WypM3uHpV3cqOhwq2OLelaVXawVYUEpqcpZe0sLWxyEnoOEQ/6
y9NqpXWbEAro/VVXEVU2OpGtdCvKx9KA9Gwob1yXAH6+PMA+Smbo45h0BSF73POyraHKsi+HcH2
bG9gULlO4R4/b+XNGC4ZuHZzWW09E7reiOc/lMd5E31S7mAGoJs1+q/nFg52b+157PBoIIKhP8p
IS1NXasIbcWxTWlDc
X-Received: by 2002:a05:6512:3d0f:b0:5c0:4cb:2415 with SMTP id 2adb3069b0e04-5c1bc7c9a8bmr11518444e87.28.1796214978346;
Wed, 02 Dec 2026 04:36:18 -0800 (PST)
X-Received: from dau-home-pc.megasoftware.org ([94.28.149.75])
by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bd0171c7sm9529553e87.31.2026.12.02.04.36.17
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 02 Dec 2026 04:36:17 -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: <20261202123613.1708463-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