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=1795704980; b=zQ0D2P3Orx2LsTrPXOvt1hFxtGcVKedy8G8pQiS2zXQhHLaDdKX8I7124/DQQJ3Sf6kg XL5kkbw0pudiJZjQcRt8gSfw0k8+3sH8QadvG3UIECqZUrUEp0EmZX/DDAzvUgy9y6z1g GvaQoTJe/cJCJ7DQPtGGYGmgJUtqBNGOtb6+Ela1hh/8LPEUSES228MVpqkb4C/zRX1+x wvt/aJ7Nua3JPVfjzUE3DTzIaGBSu969tEDhfbK0WMcYMfjPf8pdrdAYlma3ZVwBTSLox VCr7WtRZFEgeFB1jxD5hlT+ABRcWdO2p3v77xArPfzOLEiKoCXN3lNXg9BWPbjriEig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795704980; 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=OxKRcuP3+M1l1mML/2JWB+GC2hQ/FMsk6tVC+oPzyK0=; b=t5niqFArqn46UAjiUT7E+JGgMphnO3R39aPjplg6ZAZMYdFgeQ//3+oC1yrMir7MQDxc ry/xz0KnGDAp+bpLA2vNdIP0As//BCW4B9oYmxXE29Gags3MAbirF+LzFZgN3eFzO0/nr oMdqCMPiz1U7RbCZFBK5ITayxJcdPBa/ESKAs2Ypttah/qq7JPhKcF9VmWPKqWOf+UmkQ lL4Y9z5D+sLqEcLYTGTgc3uPju89VM3PDbjnQMxAl2dMq3TSfX42arZurPmOBSq6qVFI6 lMvNt39x7Z8XxzcqkBwTtiw8X7ldBymCWWZ3GrK+xfHLl0NBmQOMXbaigx7jxeE+7QA== 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=sxx1fbPg; 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 E5BC6606A31C; Thu, 26 Nov 2026 14:56:19 +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=sxx1fbPg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 023401F000C0; Thu, 26 Nov 2026 14:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795704979; bh=OxKRcuP3+M1l1mML/2JWB+GC2hQ/FMsk6tVC+oPzyK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sxx1fbPgQI+fSupQmEMonnsbEcDJRTwnnopjTr+PAcctOIOyIPS8vt6c7B8TiqiRw cT/PY2ayTfiEWBk4uvWfPf+NfkVfFi6DXRdBqj4ynvBZMGnbbtq8GX0x/PHXq5D99F bbHTByZLDYdsuuf2FmmXjCtEfugAcM2rw7cpryvs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.15 042/319] bpf: Dont leave a stale MAC header in bpf_lwt_push_ip_encap() Date: Thu, 26 Nov 2026 15:36:50 +0100 Message-ID: <20261126144007.685885061@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261126144006.732901931@linuxfoundation.org> References: <20261126144006.732901931@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 701ffd202b9e32942c8cfc065c9fe76ceaccc302 ] With BPF_LWT_ENCAP_IP, bpf_lwt_push_encap() pushes a new IP header. The new header overwrites the MAC header of a received skb. But skb->mac_header continues to point to the same bytes. Code that reads the MAC header after the push, for example netfilter, gets bytes of the new header. before the push | MAC header | old IP | payload ^ mac_header ^ network_header today | new header | old IP | payload network_header ^ ^ mac_header this patch, lwt_in | MAC header | new header | old IP | payload ^ mac_header ^ network_header this patch, lwt_xmit | new header | old IP | payload network_header ^ mac_header is not set For lwt_in, move the MAC header in front of the new header before the memcpy(), as __seg6_do_srh_encap() does. skb_cow_head() already reserves len + skb->mac_len bytes. For lwt_xmit, the output path makes a new MAC header. Thus mark skb->mac_header as not set. This is the state of a locally generated skb. Fixes: 52f278774e79 ("bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-22-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/lwt_bpf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c index 7953a3d0f94e9..548a13052e1fe 100644 --- a/net/core/lwt_bpf.c +++ b/net/core/lwt_bpf.c @@ -639,6 +639,14 @@ int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len, bool ingress) if (ingress) skb_postpush_rcsum(skb, iph, len); skb_reset_network_header(skb); + /* + * The new header goes over the MAC header. On ingress move it first. + * On egress the packet gets a new one, so forget the old one. + */ + if (ingress) + skb_mac_header_rebuild(skb); + else + skb_unset_mac_header(skb); if (is_udp_tunnel) { size_t iph_sz = ipv4 ? iph->ihl * 4 : sizeof(struct ipv6hdr); -- 2.53.0