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=1796384308; b=BzL6hYEuGzjYiJgkXlsqYWeg3dyldEAdoduxCfscF8oKBJmVPVWb8LxQK8eVg+IERZwm vF/kR3D7FeMmVsOB5QOgJZdN6wXCKEIPI4jJ+wYCcyf54QYYIOKyjH9HmqA6GZyGhQo1a kXKdYrXvitEI3bQWtA8kr94jZISEwY76cnOgVjTLlTUo/ajWh41bnm6FDCNss14gXZpii Jk9IiYT1a4663YA2QpE/EHmahCZmm7qby8gcDs9+BgPPzxHNerqGwf8B3+I28NhkF2SVU Ca80cZd/3bdM/upUdIWurFPYj2fimYaS1Co4MA1fXagG0s9iwl4MsDtBI09iQn+YB7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384308; 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=lejauQSPbeozUxdkvQ0ozAK/YQ/x8XaG/SHgBQTmzyQ=; b=o0wQ3ZasEVnrCrX4WKMezaU0Q9inVeniBn80pB548Ukd8Z0IDV0gzb73rwaCr/AfKTZX fv78rO9izoNjT8zHxQQVLg5r4rFMQLxZRFjaCl4V6eodeYdwMB3Jqsex5woRHud1fElrm iyeFM+ai/q7CQrJ0kdoE+PxcoVQYvlPZsqjV57Sn52hYijB9GvYqPr7Yw321wGfPbh9YP iNVpg8pTcS8ZsWHnLwbw1Ho9UBNEgpBqPAypxRfUIJjw6n5yt3RcPIscxo3Y9dtgNcVWP 7V3OMx2JeM/7LKUgnoU0pdM3yGQOgNDqKhRVJEkzhtzqTw59kkK4LIT08p6FaC82CGg== 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=iqGgpXUV; 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 7E9F0606A322; Fri, 4 Dec 2026 11:38:28 +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=iqGgpXUV Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBA171F000CE; Fri, 4 Dec 2026 11:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384308; bh=lejauQSPbeozUxdkvQ0ozAK/YQ/x8XaG/SHgBQTmzyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iqGgpXUVmnWz/Dnh7FFoyHfq/gnSIx8q8f7cGn9A8bwM83AQPvc1jtwN52EX86Hiv LXFVAMU8PWOIE5pM7TsvkqapSLgOUTlM7BxY1SfX8OKU67TXpyC1OqByk+caJGXhUy RUtwVu/wGDDpvPkhdb5hGw3RfcMJQOQpHUc4xljQ= 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.6 0069/1167] bpf: Limit the SRH length in bpf_lwt_seg6_adjust_srh() Date: Fri, 4 Dec 2026 18:51:36 +0900 Message-ID: <20261204100703.876969937@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit ac159f39b252971141c49b68a27de0b637debfad ] bpf_lwt_seg6_adjust_srh() lets an End.BPF prog change the size of the TLVs in the SRH. The helper keeps the SRH length in srh_state->hdrlen, in bytes and without the first 8 bytes. Later seg6_bpf_has_valid_srh() writes it to srh->hdrlen, an 8-bit field in units of 8 bytes. But srh_state->hdrlen has no upper limit, and the cast to u8 can truncate it. After that, seg6_validate_srh() gets the SRH length from srh->hdrlen, and thus it can accept the SRH. Then srh->hdrlen is too small, and a parser reads TLVs as the subsequent header. Return -EFAULT when the new srh_state->hdrlen is larger than 2040, the largest length that srh->hdrlen can hold. To replace a TLV in the largest SRH, a prog can no longer add bytes first. It must remove bytes first. Fixes: fe94cc290f53 ("bpf: Add IPv6 Segment Routing helpers") Signed-off-by: Chris Mason Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-19-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/filter.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index 50078e5549d79..4b6b45da40400 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6710,6 +6710,9 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, return -EFAULT; if (unlikely(len < 0 && (void *)((char *)ptr - len) > srh_end)) return -EFAULT; + /* The length field of the SRH has 8 bits, in units of 8 bytes. */ + if (unlikely(len > (U8_MAX << 3) - srh_state->hdrlen)) + return -EFAULT; if (len > 0) { ret = skb_cow_head(skb, len); -- 2.53.0