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=1796379636; b=JlXu/vGp1cHczuFuVWk3lLCi9OMMac2qO+xI2lXchg5qGXT09082KjzkZmEdHOQ1169Z dNFff/a5fFHEH3Fl55ujXOXyUA9++NIykuCG2VFzv/rneWPAQm4KNqkJFw53BrI8ySS3j XyibeqoyfsHnZa5AjCeW1p5Olpemkl7djqfBKBZ6h32MM0iRSPGdsmFQh/OhoihHMkDi9 azdYeQbz3SBJq6XLupG+4VmOe6yC7EIMHxg+mE1IVotjA9dVLknWW9RwCBsiVpeicPmoG HKDVUACpm9YPGO+3y9GHiekqF51S0zZMaeoXb0kLWXJnWRxU9WsezN6NHczJqQuLllg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379636; 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=guvL9DZrp/ohdlCU04f0HKIKBjN88sVUVQtIe6wt0Vo=; b=k1bnKm4AKAxm6dW8x+2+Mi/2mRERleh4nf8FRfTi8LpSewMdKSLhYvLoma/9tJ6EABp1 /S8kplXAfeYGe44CiEumN3Wn5QbldlQxyDf7UpBKliEcVvPCy2l5kC/rm8TyJbx0vG86b ivMZjG/iRWoAwWY0398wW+O3ycCjoPZd3Bk1UiF/tVBJbrT5djwgxqfZwTynppQle0TGg K6+7TktKHT5FW+SZGNpMwWmkxnywnghEE9H2Mw0iN6qjctPX1wdGX9wk/bRklPj2zTJbr r9UzJzN/cKWwV6xYn4AJLN0EIh75xw5utFNSihdgHB8/mqO3n6L//+lKKC8M7tebSIg== 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=zJMB2DVj; 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 51A73606A322; Fri, 4 Dec 2026 10:20:36 +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=zJMB2DVj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 817DC1F00897; Fri, 4 Dec 2026 10:20:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379635; bh=guvL9DZrp/ohdlCU04f0HKIKBjN88sVUVQtIe6wt0Vo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zJMB2DVjhGBxyxScTeEmaC0vTuDKom4ayIel8nCS6bXwntwLYFaac/J4rYu85ikzV ZNzpv0KctgEZ50PsgNaPPontce8txWf/FVJ/SW8SDhNLMcrX+rkRUK5tkgRvYtwcd6 II5e8wXetPBhaNAFk/5NowUHWhHJAfjqgiAdE1f8= 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 0048/1059] bpf: Limit the SRH length in bpf_lwt_seg6_adjust_srh() Date: Fri, 4 Dec 2026 18:52:59 +0900 Message-ID: <20261204100645.306758827@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 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 b480d4d17f47c..ff0d53e1aa2d9 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6630,6 +6630,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