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=1796379643; b=Ix1prnOtVFKibAyoZ/oQ91soKIFeTUzrtg8J7ICKzT7GLzEvWEqJVv4feYSOjDAkpMDM 8NjKY5dTBQOW6Xv4iTGrHhUqej9QuWMD8QREUzoR8edeyt47+lTYq8POk7xs4L96tYRJ/ Uh3KrI/Uoinp+wZb9vHf4ihC/alTLB5lEn95YuxQMvBv9J6ka6WH/f1ndZSknt7GNQvKY xu9JOBcaa0WDrdIo79OyC6Ry5Jn69Rl47yaig0JUh06rUd599m8h55Q4IAyph0rDzs2Fq N35GcnKLy4bgehLD8OoqSb4OPfeZ9+igSisIcC7+7VVEp2a79gTzHrdEtH0fwmwliSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379643; 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=TqqCegXrOIFLSrvvNCPVGFjBCnoPIlBjs3lzwJCCGpY=; b=qldc0KPnbs7k8X0WC6lBwY0zwIc7lTqeVvUR5um21zBaxzEemy/ykqKj+mKav8L3YEPb fzejLxW/D5OOgSMUx6mCmMa5C6ewSYdWT0KYsxOP3PFt1DYva5vgWU47BWUbpMtXqASrc 9N4VJ/svdP2DBzOsT4QYiM9stspOPaw3efYrhEPAJ6dg1x3exnD5eL1Slc4QfweMbzFKT 4EID8D9D07mKRandp8k10B/Ta8d/Rq/BaYLqGCtmEER18vgRUlYIY8EvKfWaRlMTb4nk/ TxSQ3ExO0P304q4aP271Fag2Zq8oG1Vq7x4YjxgXgkjoSGPlu4D+rkbBgX8WBOXuCcw== 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=ADvha31Z; 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 7F4FB606A322; Fri, 4 Dec 2026 10:20:43 +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=ADvha31Z Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3A3B1F000CE; Fri, 4 Dec 2026 10:20:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379643; bh=TqqCegXrOIFLSrvvNCPVGFjBCnoPIlBjs3lzwJCCGpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ADvha31ZEUAteJE2Krwxaczbjm6AXGQFubN0bkhx2WlH45KXCEjhmcIxHqyyh4KQ+ E9iK8vXHD7UaU6lZhQmBiXFAbHdxF+ApFBMuNihuUrA+79AUN0hESRwDNcyOBuxFjQ EQEDJm3U7TTqdMKujBC/4NY0WY5SpIFZT7UFRDU0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 0051/1059] bpf: Dont leave a stale MAC header in bpf_lwt_push_ip_encap() Date: Fri, 4 Dec 2026 18:53:02 +0900 Message-ID: <20261204100645.392052182@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: 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 8c83b34ed58af..87a892c1a587b 100644 --- a/net/core/lwt_bpf.c +++ b/net/core/lwt_bpf.c @@ -640,6 +640,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