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=1795704193; b=Wy+79kR6fP8Byl4jEdaCwI/d0BqEiitarWCiB6B7aanJoze9gwyXCRl17d77hyURbvNs CkgGhRvINoBV694g0FdA3IhCnW1b2SUjQi/S6ObZ+OKRKgIQ3m7NjveeonGMZ88B//A6U aNOmTL/bhvw9Ts5v0f6KyCP6slHmNx2fe5nujM517U9v8gHJD4KJnbFwTYCJhk/nIYVqT VlWlqidmOJg2FSYEzIsS+6x0BdiyWthnhghTgu4m7WYfmEnb9E/U14/y+izWlcF7lFFia AwHQM1eVBkbGOKTMAJrNEAOGLvBjDBbt59CMcGdILY9nCX3lDqnip35we17RKsetzbA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795704193; 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=ZIxIeE2REYUDdnT+sWRk0f9ylDZYQSZjqUV5VDJUbWs=; b=oB0u/6LLI6VoOuYtgM7pQDunrzG9uVQVSwo301rii+xmQGDhoRdyuNvKgdQQrLeUI6fp 7yPpgW0sLK17jZ8DuSXQJxHmSOyGQgXeYQxfXKEXkC5X1dwFJrt2eMNFXPKiTV1Z2rdGx rvHDdlTjWqs/9TW4A1EGMgFfVp4UDmpg5NreMZ19KX84zhHOAVDh+BDKWCrCc4dzs1zAS wGtmF9CCt7W0ah1wCjWeapsgNIFvQgEaFX596hjqK3UXr8YzrllCpY600xzaRVYkrcaPP AAkepPbOu00U72N0D55MaHy8tLm6vzr3vtSVCQr0RpzusVtJlmdi6y+m/+54Oa3spuw== 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=xfWenlNY; 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 9E34E606A326; Thu, 26 Nov 2026 14:43:13 +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=xfWenlNY Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F0091F000C0; Thu, 26 Nov 2026 14:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795704193; bh=ZIxIeE2REYUDdnT+sWRk0f9ylDZYQSZjqUV5VDJUbWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xfWenlNYBd988NFdCkLl24E6OKVtUybM9Q1A4fNZ2ULvoHIH9AB0+yHfyXWUChSJY wMYItzw5yLjKtnzFIEuEjF3mgLo3fGmilQ+UGjrUBcaqNqHusbInBc7DKvnGZcreDL rpj4HNTIpAE8e49hc2Wntnbgq3DmxU6MgoEHml3s= 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 5.10 037/265] bpf: Limit the SRH length in bpf_lwt_seg6_adjust_srh() Date: Thu, 26 Nov 2026 15:36:07 +0100 Message-ID: <20261126143607.719478365@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261126143605.076581697@linuxfoundation.org> References: <20261126143605.076581697@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 5.10-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 c58b4f8aa57c1..2cb67c6f24e62 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5982,6 +5982,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