From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796086787; b=qVMy5g6a1sEuN/vnOAyd7GF0jgwODULoTAY1XkErcy6sG0R3S1nW+uV6SihCU+hoPPpC ajsNb1Ld0R77ht7R+fj1rLRNN6jXnJPNHKI5rKqXQ4LK2LfJN2jwLn055A9NNvZZQKurK w0WMHFw6WjR05MmUoz2nOy8GyMqjPWBqzqMH6+0zT1MfvZXXX3fho0D/ru4DaOJElUSzQ N5cexrrX5gDCQdSuyRyEwh6JDaOLolkPFVW5lOy0jViEmLJjXi1Ljgh+gNS/LM1GDCAA0 1dqCaqlfb1A+PL18NqrjIeH0/YlR+WkjiH9cRG6rgmbIc6s2jQVNQ6C2Gay5B3gcXZw== 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-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=eq/gHQN7Zf7Vs2xSe/0Zot92rKLgwKdki6zOEQLqOBbmgiDMNwxs69uJYN0ULyhsqWzS VPhtFBNSI5Q733oiPBkTOZqFKNb5sh3tFd2GN798V7zKsqAAZDC7T3I8B2j6ebfVe9jnc czBs1OeBPorA9mP5k8eNQ1UVdf1xkJFsG/BcCmc1x2hESlH/BAKr8joxtBLQ5h4Tvv7bI qIHrzBa0muLKMnSl/TeFhcIlELq4WcMGF7iB7Jd4p9kxFcE+19cuy7EChl9uF4Lu6L/hW +662neDoG0vU08dmYGN4SVPhgCEQw8v+ivsZjY48h3R0tiinproSCAi+XFPyZQ5a5Jg== 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.52 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 3FC06606A335 for ; Tue, 1 Dec 2026 00:59:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3FC06606A335 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=eu9zcm4P Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5c126fa1e3aso381705e87.2 for ; Mon, 30 Nov 2026 16:59:47 -0800 (PST) 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=qbB4KVb8cEQoZWuIm+7bT9fQZxKsxy4Ovroj4QYqLx18RCmeAYrsYZVRzMTDJlDNoB zkSNXF89JQGg7Rn7qd1mN1egxBVGNY3I0lytNE2lPkTozryGSf2vLxsjgQIsr5Qo+FDV clozJjoacPsuGSZgHlUrsN5yMOBKBzRc4Nzz4XTT36P2+hqiTYnovB1Uv3BUqjGGkGqn jk4ZRJjV6QRpKs528BN787OFQa31DilHGQsWpSgLqjssQuD62+lxjLI7bZLCFuo5cfD9 55OVlqRmaFhuy+JnXMu5117CU2G2ewJilu6LzBqCZXhw9/lore8j6wDGmAfkd6UzlWy1 A7Vg== X-Forwarded-Encrypted: i=1; AL+hErFdTlAwrUpVj+pM08APKcB2cV1sX4E06aoqvIwVX0HsNg0HzvtXleDjGMxojx4HYqv6mChLHnBnIq+WfB9U5yw=@vger.kernel.org X-Gm-Message-State: APuU4Z93Dqt3OMRxZoRHhVEFn9/2de62PT4fcSDw/gTpg2GwGrIropw1 MYI+WlxpcXa8k4cX4fs6ipz9UxhIXEInHFEDqxgZjmB+RQaqen7yC2pR X-Gm-Gg: AZFdTZfJqr/L6/90ZdjEAXjiRL0LTPTH7ORmdYLF1vdLBB56sYGDnkZueIiz4HrXwua rkrLei3vX5ZAU8ETMLZ7NhIlf+BzWk+Jscj2eFL3hTD4meUTuPGTZiH3+etMdcOHVGcz6p8RMRF oXVsehzlxaEBzXTNlm4uogDt57v4tOxdWDmZtxBZ1p+3D67ZJDpZ4Chxps1fBi/EuUL1CGs0eWJ 0fLvOwvx4iOsnhQdIO1P3w7StCjNCVaxWUHMAe+tsjkgdRNtjwKKY8Q1oSJ+L+wMd/5YhrWkROv Mg65wF/YM1qp8sMpeDcRDsdoFENHv/ghM0yE7M3UHIBGUDkw/zHQ01oQjKqN/jKdLZ9rKvQg5ek /uzSEv/KJEP7E/3fn8U+K9gAh+DaieON+8woSlDtY4MFPVCxlAxoJeCuZi61aWacPWFlJUOYnaP eqXRxG4T0tG3NStxTz6YPbgiVy0w+sXS9U9BZI1rBYYkXc7hWAnpwhyyZZY/wiX5gOiFdNisgLi YETY1Pkd2Gs9pCtEWBUInNEsMbMPxQHKdMri3O/XwFvfZ08HZ7seWT4mibsfTJo7Jy11VJrV66f pxfezNZVtAqXk9QL822xtfeh3PK0J+vVSksVSdpIzGIAWAba9MGadgET1H2vZT0G0pdFgsgv7+q QuvcQHyetk/cFfrPWl3ktDUIb9xxWedyD2kF78Q== 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) 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) 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 v7 1/5] erspan: bound the VLAN tag read in erspan_build_header{,_v2}() Date: Tue, 1 Dec 2026 03:59:37 +0300 Message-ID: <20261201005941.1536429-2-littlesmilingcloud@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201005941.1536429-1-littlesmilingcloud@gmail.com> References: <20261201005941.1536429-1-littlesmilingcloud@gmail.com> X-Mailing-List: linux-kselftest@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