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=1796379656; b=nZxIgHJKCiTRIZ9lvnFmThdiSUJRMeG4KOKaUt575lk6Ry2BkxTPIfMmF0tUm8PrRYx9 bxNCxHRodDw++g92REmwrm36/dDuHDxkTA5LxbIvpt2mzSpUcIOz+7ZkAWnkk2QRRxIpv +Agonk6G2db5gkyeNCa5oOSGURkp9EKQjGFepk1vbitBQ5Hk57PlJZjEKuM7rUx5iM7eF IQCGpqp0fLUXy+D5RmmQ/QGzdSMloi+CQnIIrKCZ4/uimU2JUg5HhINix/vSxNh2aV6Yf mOIMT6sy9FBYIGicbdnO9aG5B2v8mKxGppGupHA9YlY59HqwpQnWPDNkv+bQgGeEG8A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379656; 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=SZa0kyCKOic2e9Ivo/2lBpJ425VB8rtWCJTSJ/uJHJo=; b=CVkfjRwOzwkig5/95LruIPtL1QAJqQuw4nqPZ5lhevt06AUGKVD2k9C3uWSF41tzuMvo MRTJJ//NLvXTF9A/ZFC+FBnPPTaQDwwEr4qz+N//W2v3Wo6UhOa1FYV4T7iUC6xtc/Z6M OuV2QP/ApUaIWPOQrNGiudJ5GNIIysTJK+SYxHr3tvE389eLE2ZDrHRjaFbFJySlrmlSk VkoAchrxhb8yDKYpA1dJdySjNlD1nh1kDZyzL1mrA8el/XARlgB1e2gzvSEewnNNe/Iqw RR8DxOFMBPtxPSfZuUFImaAyt4AIHNTs0JUGBD1LgJjZogPMpP5mX26m4LEJmC45G0A== 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=augFiu3U; 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 8BE36606A32C; Fri, 4 Dec 2026 10:20:56 +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=augFiu3U Received: by smtp.kernel.org (Postfix) with ESMTPSA id 015551F000C2; Fri, 4 Dec 2026 10:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379656; bh=SZa0kyCKOic2e9Ivo/2lBpJ425VB8rtWCJTSJ/uJHJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=augFiu3UUIylvtaVRungdrB0mMQOUVfVLdZZLI431EXuV1GXq1JLz7sJ2LnsYEExk dOFjwuEWu1T7FEYShmcxulWlDvCulluJzTsENnp7NtOHx+yLt0GXcYWl6YnsRUxCde 7DXOg5z/PEy13Zli0Ii+1+WFtwngTrn1AdJhEjlA= 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 6.1 0056/1059] bpf: Move the transport header with the moved headers Date: Fri, 4 Dec 2026 18:53:07 +0900 Message-ID: <20261204100645.530351228@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: Chris Mason [ Upstream commit a9d08fe60fa728ce0e3a99085241e8e790fb14c6 ] bpf_skb_net_hdr_pop() removes len bytes at offset off. bpf_skb_net_hdr_push() does the opposite. skb->data off before | A | removed | B | after | A | B | skb->data off mac_header and network_header move with A. transport_header moves only when it is equal to network_header. inner_transport_header never moves. This is correct only for a header in B. In bpf_lwt_seg6_adjust_srh() transport_header is in A. bpf_skb_adjust_room() can remove both transport headers. With an incorrect header offset, the stack can drop the skb or read outside of it. Also move transport_header with A when it is in A. Set it to offset off when it is in the removed bytes. In BPF_ADJ_ROOM_MAC mode it is then equal to network_header. Do not unset it, because skb_gso_validate_mac_len() uses it without a check. After a removal, set inner_transport_header to off when it is not in B and skb->encapsulation is set. A has only outer headers. Fixes: fe94cc290f53 ("bpf: Add IPv6 Segment Routing helpers") Fixes: 868d523535c2 ("bpf: add bpf_skb_adjust_room encap flags") Signed-off-by: Chris Mason Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-26-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/filter.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index bbf96dfbcb95b..5a7ec964f740b 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3320,9 +3320,25 @@ static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len) return 0; } +/* + * bpf_skb_net_hdr_push() inserts bytes at @off, bpf_skb_net_hdr_pop() removes + * bytes at @off. Both move the bytes in front of @off together with skb->data, + * and leave the rest of the packet where it is. Return true if the transport + * header is in the part that moves. A transport header that is equal to the + * network header stays equal to it. + */ +static bool bpf_skb_trans_hdr_moves(const struct sk_buff *skb, u32 off) +{ + if (skb->transport_header == skb->network_header) + return true; + + return skb_transport_header_was_set(skb) && + (u32)skb_transport_offset(skb) < off; +} + static int bpf_skb_net_hdr_push(struct sk_buff *skb, u32 off, u32 len) { - bool trans_same = skb->transport_header == skb->network_header; + bool trans_moves = bpf_skb_trans_hdr_moves(skb, off); int ret; /* There's no need for __skb_push()/__skb_pull() pair to @@ -3333,8 +3349,8 @@ static int bpf_skb_net_hdr_push(struct sk_buff *skb, u32 off, u32 len) if (likely(!ret)) { skb->mac_header -= len; skb->network_header -= len; - if (trans_same) - skb->transport_header = skb->network_header; + if (trans_moves) + skb->transport_header -= len; } return ret; @@ -3342,7 +3358,7 @@ static int bpf_skb_net_hdr_push(struct sk_buff *skb, u32 off, u32 len) static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len) { - bool trans_same = skb->transport_header == skb->network_header; + bool trans_moves = bpf_skb_trans_hdr_moves(skb, off); int ret; /* Same here, __skb_push()/__skb_pull() pair not needed. */ @@ -3350,8 +3366,17 @@ static int bpf_skb_net_hdr_pop(struct sk_buff *skb, u32 off, u32 len) if (likely(!ret)) { skb->mac_header += len; skb->network_header += len; - if (trans_same) - skb->transport_header = skb->network_header; + if (trans_moves) { + skb->transport_header += len; + } else if (skb_transport_header_was_set(skb) && + skb_transport_offset(skb) < (int)off) { + /* It was in the removed bytes or before skb->data. */ + skb_set_transport_header(skb, off); + } + /* Do not leave the inner transport header in front of @off. */ + if (skb->encapsulation && + skb_inner_transport_offset(skb) < (int)off) + skb_set_inner_transport_header(skb, off); } return ret; -- 2.53.0