From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214980; b=ca26bOa3Yfxb2zK3NFO+veGqWWGb5+Ju+TI0eLkxbr3syIcwrXoKHl9uwTK/TlmZMW0u +EySZWRsO33EJESLIfTTwvcOLPBiUD8RLDSbDONRNNyqoh1NVTZIz9AVeyyg2+AYEvAEJ Yh5Ht+VoQ1F4Jat/a/gvlhlG2MY59Pf49S+lspdD8ZXUfHlBLFnqP39FhVQaRyTjJohBv YWA6teObZLVR3HqkfF+XUl1zSkRmIJRFwRJJqS1zEsmC5ZaH8xg5qCeAwHY/lRB+w2YZl sdaJCF3MHvsOucQqYEl96Csg5eN9HAc04qmpkHRJsCdujvMtVyK6QCSzaRMwotvSKsA== 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-Forwarded-Encrypted: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=WyPL1xnX5h6mE2yCvmQbjg9Xft98j7kqS9DJgp8hq3VGxcj9eB7qvAhjf3bGL2XiX9cd crsWhVDUB+PcgxhAMHKhBWDDrqYalQAsggEsd5LgDbsy8D7zyjriylUYbM9id8w0i5Tx/ RMgFgooWhfmy19cHCLFP/6UaRIJOgPzvmutcMx+VYJitmuIztoUg8YXDFl1Aph855dHxJ i+8V+vApRGDbMQ1RTzO4iYNw9lSENzuYWJM3q49VN4369ppeItXVQ/h5Mb6P8PAbl6K6Y XBZpwFFxJ9XgEG/LCoTiXDiZbrymCiokHKk6HbSR6PHP/l43sNanJbUHT7THPrJQNfA== 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.46 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 694C2606A33A for ; Wed, 2 Dec 2026 12:36:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 694C2606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5c10dc41270so13414778e87.2 for ; Wed, 02 Dec 2026 04:36:20 -0800 (PST) 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=GMY79kGPtj7B9kugMusF//0F+me0is5KS8lHL/SzC61KpLtu1qWSlf4iTfDpsK+vF/ f9GXsZiDzWxL/aHW/d16VqhoAC0T5p7V6V591BZCuEEQtbWejUBdMHDCh0wwTsGwci8W ER4A1gopHit6yeu4JnvirM2WH5jFNnnqvOmL2Daq/flZMwphiBk4VyLN+OmYv6gVwNdq KsPIckKS0P4ti9VPm5TB9eCpw5Oi3jQXv152h0iXHOef8rYRSSoDMuGi9hOduukZrIQN uZS7/OoJN1Ob8/yV6V8T32KP0gmmM2Is2cXRg/QFQRJDB5HB5e4SF56+62xml5vgGNwO 9AeQ== X-Forwarded-Encrypted: i=1; AL+hErH7E0ljEJMrmdrLZQrCd3qGcAkqVQilYgdg8Y9EsN139Lng8zicHc7zySYL7TM2cMTQipQgfZiFDg/ArdU=@vger.kernel.org X-Gm-Message-State: APuU4Z/xZSvlaZwMP2/fd6PoYcUQYpSop4P9D1DKvhjje1nJou9bXQ7P Gyq98RPhTVu6ZNoCs8k8g8bTP00sFoNR7isDee+tQ8cZtKgfJpDn7aCt X-Gm-Gg: AZFdTZffLZVV7tGieJedXc7h8sem0ASkLY9nGUE8tEBowtvFdpI8K7gk3dcE6s65BHu L9e2KfdTaz2pbnwMjK2xBu2hHGHZVmpw4yegziphctHPitaCZ0Zx1ktZnXyp1C4csa3EWLjjwbY 4g/XGD0SScbL0ALaSjMmwq29j8jhDA7mPCoscdkEkyBcNHtoTyTARFN5NxDNJCy6e6t7u4hz3fM qOABIk9fg1yBwUghxhrZkLZL70VseJpGr9b1dBk9to1T2L0we5qMDNgCUUftN+mWcnLyawknGR8 T9Ll3K+wewBXysABkHPQ08LR8RaJqbF1KpIo69hss7ZngbjrmRIkLYZ26RkibY+hiu2XIoVf/7J XIBH4DV+GrH1Hy0r7jfPbTDURquFOfK1keiqLL4mLfYyfGvWUNE57otYefpD6f7Ql9tQ6h/mmuF ds3wCE+BJDTq4vqW6+F1HDzyKTKirGGaRjgdqp/0mcNuUGJMrC6+aYDC8idriuNRXQMCV+6ezSz Tsfh5POJmwx1ISRjfbbcr2eY/wVdAngKoOrnYZRkjwVl29HX27CV89lcRd80Q8wdIBs3hfhBaEv MZcKDYCxOQGjmNQTu8Ai3D32UaebXzBXNH0xZt2VbPYtQREgD9bu/4hXTVJxZsbWWuoZ0SJH4Tv N/TSrhyFhD52eHbbb 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) 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) From: Anton Danilov To: netdev@vger.kernel.org Cc: Eric Dumazet , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Simon Horman , David Ahern , Willem de Bruijn , Ido Schimmel , Florian Westphal , William Tu , Meenakshi Vohra , Matthias May , Mazin Al Haddad , Shuah Khan , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org 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 Message-ID: <20261202123613.1708463-2-littlesmilingcloud@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261202123613.1708463-1-littlesmilingcloud@gmail.com> References: <20261202123613.1708463-1-littlesmilingcloud@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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