From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388507; b=Uux1HD3cggPSnSwXRVMQSzDQ0wYoau84RogIycVdtOHBwZ3oGbsUha1NfggOaSpxuFoL Usofe2o2/r58mTBnhmXlNwadrYlYFl+Dts5IxAeggeHEhe1cBH9qvI6dX2Hyh96JQunOG ssyOgkBDa1WFzYkBtHl4GpoFuyeJwzyNN5jSM9dR/ki5ym3WLjDe2IjmM31lxDErkQZgn vZ+rmiYIOiYYobU26xGadp9dp/0HYONHe5xDwKFKmfeCRneunkGhHzZRjS5cUOwiozmKF r/gKm17ntPIpJ1a0D0VgYvuoPdurL52P+tZcUzwqx5P7ZqtXrkrjkFiWqlH+1NvKnKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388507; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=QvCsrVSk9JC4m4nJHrWZutHqwoC21QT7Qv7SXSIXMQk=; b=Yi6Bh6+qhYTIuy6epBQbpoll7A0/KRLW9JWodP51jAB2ihesQeLg8kbwxHLTM2FEulrg IMculOhwmXPbNo2FGrq0eETu9/oAwOggljmja+WC7ZFfIUAO3ASCeKp4oT/4Q5LGTsVZG Sb+DvoRT6LJ/iR7hRRDaLyAOO7x1jV94mXUwaIJ/VvzMpoyBJYQWINdtiNnIjCbdJm9pj NH+MX/cdntlAiUw5sVdMeKA+AQN4Nq7ZoxZhTCrsaU/HGCW1tu4wVXXSewPpSnd//j2ob p/WWWNpapqiHke2FZhbIvxcUL6kPxdo45X2RRYr09AwhvZBatTbz+AZQ7u+8L96vjdg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Gi2ALTSa; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91108606A681; Fri, 4 Dec 2026 12:48:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Gi2ALTSa Received: by smtp.kernel.org (Postfix) with ESMTPSA id C70CD1F000C2; Fri, 4 Dec 2026 12:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388507; bh=QvCsrVSk9JC4m4nJHrWZutHqwoC21QT7Qv7SXSIXMQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Gi2ALTSa8Fq7EyvQ3v013zHZT4zgpwhQLs04Cq/OL+9HMHWiONk9sBnFLPCqWlFy7 jP0fgB6C8GwoFglG57Pnu5fspvK4L24dIYNlT2psmQ2FQIRRw2j64IxMbSrrsQ0XCO yEMagdCT7Av1nTHhLoTgq4F4F4Htns2jmpKC8T7s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chengfeng Ye , Theodor Arsenij Larionov Trichkine , Ido Schimmel , Jakub Kicinski Subject: [PATCH 6.1 0643/1059] fou: reserve headroom before pushing the encap header Date: Fri, 4 Dec 2026 19:02:54 +0900 Message-ID: <20261204100700.727100728@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodor Arsenij Larionov Trichkine commit bcb42672751a8786dce871a35bde363b041cb2f7 upstream. ip_tunnel_xmit() and ip_md_tunnel_xmit() push the encap header before reserving headroom. A packet redirected into the tunnel (tc mirred, nft fwd/dup) keeps the headroom of its original device, so fou_build_udp() panics: kernel BUG at net/core/skbuff.c:214! Call Trace: skb_push+0xcc/0xf0 fou_build_udp+0x2f/0x380 gue_build_header+0xfa/0x150 ip_tunnel_xmit+0x87f/0x21c0 With a mirred mirror, the push overwrites the original packet instead. Reachable with CAP_NET_ADMIN in a user namespace. Reserve the headroom in fou_build_header() and gue_build_header(); GUE sizes and builds the header from one copy of the encap fields. The skb head may move, so reload inner_iph after ip_tunnel_encap() and read tnl_params, which points into the head for GRE with header_ops, before the call. sit's ipip6_tunnel_xmit() holds no head pointer across it. Fixes: 56328486539d ("net: Changes to ip_tunnel to support foo-over-udp encapsulation") Fixes: ac931d4cdec3 ("ipip,ip_tunnel,sit: Add FOU support for externally controlled ipip devices") Reported-by: Chengfeng Ye Closes: https://lore.kernel.org/netdev/20260801060115.3538849-1-nicoyip.dev@gmail.com/ Cc: stable@vger.kernel.org Signed-off-by: Theodor Arsenij Larionov Trichkine Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261116113845.166280-1-theodorlarionov@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/ipv4/fou_core.c | 19 +++++++++++++++---- net/ipv4/ip_tunnel.c | 6 ++++-- 2 files changed, 19 insertions(+), 6 deletions(-) --- a/net/ipv4/fou_core.c +++ b/net/ipv4/fou_core.c @@ -1078,6 +1078,9 @@ static int fou_build_header(struct sk_bu __be16 sport; int err; + if (skb_cow_head(skb, fou_encap_hlen(e))) + return -ENOMEM; + err = __fou_build_header(skb, e, protocol, &sport, type); if (err) return err; @@ -1090,16 +1093,24 @@ static int fou_build_header(struct sk_bu static int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, u8 *protocol, struct flowi4 *fl4) { - int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM : - SKB_GSO_UDP_TUNNEL; + struct ip_tunnel_encap encap = { + .flags = READ_ONCE(e->flags), + .sport = READ_ONCE(e->sport), + .dport = READ_ONCE(e->dport), + }; + int type = encap.flags & TUNNEL_ENCAP_FLAG_CSUM ? + SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL; __be16 sport; int err; - err = __gue_build_header(skb, e, protocol, &sport, type); + if (skb_cow_head(skb, gue_encap_hlen(&encap))) + return -ENOMEM; + + err = __gue_build_header(skb, &encap, protocol, &sport, type); if (err) return err; - fou_build_udp(skb, e, fl4, protocol, sport); + fou_build_udp(skb, &encap, fl4, protocol, sport); return 0; } --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -603,6 +603,7 @@ void ip_md_tunnel_xmit(struct sk_buff *s if (ip_tunnel_encap(skb, &tun_info->encap, &proto, &fl4) < 0) goto tx_error; + inner_iph = (const struct iphdr *)skb_inner_network_header(skb); use_cache = ip_tunnel_dst_cache_usable(skb, tun_info); if (use_cache) @@ -745,6 +746,8 @@ void ip_tunnel_xmit(struct sk_buff *skb, } tos = tnl_params->tos; + df = tnl_params->frag_off; + ttl = tnl_params->ttl; if (tos & 0x1) { tos &= ~0x1; if (payload_protocol == htons(ETH_P_IP)) { @@ -763,6 +766,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) goto tx_error; + inner_iph = (const struct iphdr *)skb_inner_network_header(skb); if (connected && md) { use_cache = ip_tunnel_dst_cache_usable(skb, tun_info); @@ -795,7 +799,6 @@ void ip_tunnel_xmit(struct sk_buff *skb, goto tx_error; } - df = tnl_params->frag_off; if (payload_protocol == htons(ETH_P_IP) && !tunnel->ignore_df) df |= (inner_iph->frag_off & htons(IP_DF)); @@ -815,7 +818,6 @@ void ip_tunnel_xmit(struct sk_buff *skb, } tos = ip_tunnel_ecn_encap(tos, inner_iph, skb); - ttl = tnl_params->ttl; if (ttl == 0) { if (payload_protocol == htons(ETH_P_IP)) ttl = inner_iph->ttl;