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=1795617909; b=lGBJa36MhLvsv4eGSjHTckBMCISDFq4qEwd1l/4NtFtRmVO7ikgTsiUcXhiQ5cZPMHHZ Z9XSffKQ0OMWeMB+oIgZVl7NhEWu5gNaZ6+WG4Foqu+5uMBcysxY8JdEoOriHT3kLz2L/ 9J/Dk6kiX/yYNP3AYOyRQqRmga+zx4hBooYJOJrW3vKmYAnozUq7/CHjqS6I3wq5+msXL LXPrvRoFIw4AyVQNrPgYY5sLaJuBTD7lp0s37WZ+lqnuj5g3MaCwtUM9IWDtmPFpLblMt ix62C5uV8RqOMl+S3TnGKWA0h7fhbusSdJelWBjpW3QEigzfJwpdtOz5jyHoMs9m+lw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795617909; 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=CHyqDGzSOY/rfm33gtEuSnxYU0IHWdZcZjgUggPdquU=; b=yEIuXlQ2Xkj2FV4b7qR8/jX6iWOv+8fJhgAWQ6UPNF4XLcahftkVnBIf1w2NMVd1KdHJ H5IDhipgHX1DqZ6s+/xqKHDhqEdAcNNbwpBIPXDS/LlY+ChFHdshLKsUMjlXHhHpItSwb /ZhbwS8nVkvWHabiE+KvZf1ZZKtaKS7M4IMP5bNRpSB0M1GWI7I6XoiMvSVZ6dI9cwTLy HsjSKn4ejF0TQJvbxi5ccb+4rF33lXhgoe0s+wyzJtlYd4X2ceMuqoZtcs1RK6GH7exHA WIzIAp2KqnHkCp0PItmHHJ/UR6JsGTjKrxis2lQWGeSptH9HSkNVOwTHWo3d+TVrM5w== 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=RxGTAgdn; 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 E2954606A32A; Wed, 25 Nov 2026 14:45:08 +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=RxGTAgdn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E3161F000C0; Wed, 25 Nov 2026 14:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795617908; bh=CHyqDGzSOY/rfm33gtEuSnxYU0IHWdZcZjgUggPdquU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RxGTAgdnQxe+7g4MVjLuk0MQfQU5APK/uh6RnrO3oCOYLlrJVH4I9WCEWVBzcz8au FZXAh+pg5kcCnoEHMKj1eZ8D5HaqACVoedlSE5VdmRKpYYDPNift9isqXlwMDJOOiO mdEJ1k9Qa7VITjZy44uJc31TSfecmqqy8zGnXGyc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 0111/1005] bpf: Move the MAC header in bpf_lwt_seg6_adjust_srh() Date: Wed, 25 Nov 2026 15:24:09 +0100 Message-ID: <20261125143824.345195874@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143821.729802100@linuxfoundation.org> References: <20261125143821.729802100@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 0fcb3f11a93d740e7f9ae1aeb48fe4d25838be18 ] bpf_skb_net_hdr_push() and bpf_skb_net_hdr_pop() change skb->data and skb->mac_header by len. That is correct in a tc prog, where skb->data is the MAC header. But bpf_lwt_seg6_adjust_srh() calls them in an End.BPF prog, where skb->data is the network header. The MAC header does not move: before push | free | MAC header | IPv6 | SRH | payload ^ head ^ mac_header ^ data today | free | MAC h| IPv6 | SRH + len | payload ^ head ^ mac_header ^ data this patch | free | MAC header | IPv6 | SRH + len | payload ^ head ^ mac_header ^ data Users of skb_mac_header() get incorrect bytes until __dev_queue_xmit() sets skb->mac_header again. skb_cow_head() reserves only len bytes. Thus the 16-bit offset skb->mac_header can wrap. A push also changes the "not set" value. In both cases skb_mac_header() points after the skb. Move the MAC header too. Pass len + skb->mac_len to skb_cow_head(). Keep the "not set" value. The second Fixes tag is for this case. Since that commit an End.BPF prog can get an skb with skb->mac_header not set. Fixes: fe94cc290f53 ("bpf: Add IPv6 Segment Routing helpers") Fixes: 20a081b7984c ("seg6: add VRF support for SRv6 End.DT6 behavior") Signed-off-by: Chris Mason Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-21-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/filter.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index 2d64d661c0bef..f5931e8964232 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -7159,6 +7159,7 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, { struct seg6_bpf_srh_state *srh_state = this_cpu_ptr(&seg6_bpf_srh_states); + bool mac_set = skb_mac_header_was_set(skb); struct ipv6_sr_hdr *srh = srh_state->srh; void *srh_end, *srh_tlvs, *ptr; struct ipv6hdr *hdr; @@ -7184,20 +7185,38 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, if (unlikely(len > (U8_MAX << 3) - srh_state->hdrlen)) return -EFAULT; + /* + * skb->data is the network header here. The MAC header is in front of + * it, so bpf_skb_net_hdr_push() and bpf_skb_net_hdr_pop() do not move + * it with the other headers. + */ if (len > 0) { - ret = skb_cow_head(skb, len); + ret = skb_cow_head(skb, len + skb->mac_len); if (unlikely(ret < 0)) return ret; + /* The push can write over the MAC header, so move it first. */ + if (mac_set) + memmove(skb->data - len - skb->mac_len, + skb_mac_header(skb), skb->mac_len); ret = bpf_skb_net_hdr_push(skb, offset, len); } else { ret = bpf_skb_net_hdr_pop(skb, offset, -1 * len); + /* The pop has added -len to skb->mac_header. */ + if (likely(!ret) && mac_set) + memmove(skb->data - skb->mac_len, + skb_mac_header(skb) + len, skb->mac_len); } bpf_compute_data_pointers(skb); if (unlikely(ret < 0)) return ret; + if (mac_set) + skb_set_mac_header(skb, -skb->mac_len); + else + skb_unset_mac_header(skb); + hdr = (struct ipv6hdr *)skb->data; hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); -- 2.53.0