From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=94.136.29.106 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796121816; b=Oa5BSBe6dTZd7gTvXdpmKk6OY2puw+hQilTP7Ml57x2SJ9sPY6kw4Dn/osokWH8kHMCZ f/EWF8s6nXCJPHgti2k309c4b+9ibfSg+J0IBtNq6kN/0+pfigVgP8P55KlhOC5TIZtCt GolRo07lqhLwbwyhl9X/h2tkhz25ZnsNbuYtvHCBaVm9F05nbXw18xdbmpNQzREehhl7W 1iT6NMX5pLBAAsGIrujYU2emBIS+ug9SnwmqUY3Q0B2JrvNb/J+Xsxmy3DztRm6meikDW SiUGSYoRYoiwxs14XRJiaaXnyPDTh5dSZTUZNiah4tCnZ0ga2Dslif5YaoPWQ25IaKQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796121816; h=DMARC-Filter:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent: X-Bm-Milter-Handled:X-Bm-Transport-Timestamp; bh=CFpK1ptrwn65ffBpVJTOb/LJDU1ADqXK+spHU1c5U8Y=; b=O/+EcuGJbqgEmD8ctfoUxKo6DYT5BrbxQ6T4SeIbmLc1GEsMym6F2hIe95GLBJjBpni6 YZbod/KtfQXeOEgCQaFg/ajDaEQg7doWhSeC+0jWWBBnaEiLlIbdc1ipelOBBZK66QCq9 77+AdatQrZBGPtfmWy2zKv85Os7o2gERxjJ0sDxXvAfryKPCszVWLclaVHF4wSVrPERPS ZMiUSBznyL9RMPlj1nAQfecYaUiOPk1KWk4iSWcVqysDrKZcu7zBKeSb2hUsQxDK8vszc rBH1iddAHl86VkXfRfrTKAxdqqeVJl521sbSm4A1+V/U/23VRbKIVAeuMIE7phJCEXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=proxmox.com; spf=pass smtp.mailfrom=proxmox.com; arc=none smtp.remote-ip=94.136.29.106 Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA599606A31A for ; Tue, 1 Dec 2026 10:43:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DA599606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=proxmox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proxmox.com Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E79C542197; Tue, 01 Dec 2026 11:43:25 +0100 (CET) Date: Tue, 1 Dec 2026 11:43:23 +0100 From: Gabriel Goller To: Hangbin Liu Cc: Juan Agustin Niccolini , Andrea Mayer , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , netdev@vger.kernel.org, Simon Horman , David Ahern , Julien Massonneau Subject: Re: [PATCH net] seg6: check segments_left in the pulled SRH to fix an out-of-bounds read Message-ID: References: <20261130031647.45247-1-juanagusnicco@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20260616 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796121804904 On 01.12.2026 13:27, Hangbin Liu wrote: > Hi Juan, > On Sun, Nov 29, 2026 at 10:16:47PM -0500, Juan Agustin Niccolini wrote: > > get_and_validate_srh() relies on ipv6_find_hdr() and IP6_FH_F_SKIP_RH > > to ignore a routing header whose segments_left is 0. ipv6_find_hdr() > > reads the field where the packet data is, which can be a page > > fragment. seg6_get_srh() then pulls the header into the linear area, > > and nothing checks the field in that copy. > > > > A sender that can still write to the fragment, as with an AF_PACKET TX > > ring, can change the field from 1 to 0 between the two reads. > > advance_nextseg() then decrements it to 255 and copies > > srh->segments[255] into the IPv6 destination address, an out-of-bounds > > read 4088 bytes past the start of the SRH: > > If the user can write the segments_left field, can it write to other fields? Yes, but from a quick glance, no other field can make advance_nextseg() read past the segment list. > And we put the check in get_and_validate_srh, what if it changed later > and before or after advance_nextseg()? I don't think it can be changed, because at that point we use the linearized copy. > Thanks > Hangbin > > > BUG: KASAN: slab-out-of-bounds in advance_nextseg+0x2a7/0x2b0 > > Read of size 16 at addr ff110000128e9030 by task seg6_sl_race/289 > > > > An unprivileged user can trigger this from a user and network > > namespace, with a seg6local End route and a TX ring on loopback. The > > 16 bytes are returned in the ICMPv6 error sent for the new destination > > address: a kernel heap memory disclosure. > > > > get_and_validate_srh() used to check the pulled header. Commit > > fbbc5bc2ab8c ("seg6: ignore routing header with segments left equal to > > 0") replaced that check with the lookup flag. > > > > Fix this by checking segments_left in the pulled header again. A > > header that the lookup skips is still skipped, so a packet with a > > second SRH is handled as before. > > > > Fixes: fbbc5bc2ab8c ("seg6: ignore routing header with segments left equal to 0") > > Cc: stable@vger.kernel.org > > Signed-off-by: Juan Agustin Niccolini > > --- > > Reproducer: github.com/AgusNicco/seg6local-oob-read/blob/main/seg6_sl_race.c > > > > The patch was tested on mainline f4585067150b (same seg6_local.c as > > net) with KASAN: the reproducer gets the report above on 100 of 100 > > runs as an unprivileged user, and on none of 20 with this patch, with > > about 300,000 frames sent in each of those runs. The repository above > > also has the full KASAN report. > > > > net/ipv6/seg6_local.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c > > index 82207da08dfd..ce1d6f09e8f4 100644 > > --- a/net/ipv6/seg6_local.c > > +++ b/net/ipv6/seg6_local.c > > @@ -235,6 +235,9 @@ static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb) > > if (!srh) > > return NULL; > > I'd add a code comment here, otherwise this will be removed again :) > > + if (srh->segments_left == 0) > > + return NULL; > > + > > #ifdef CONFIG_IPV6_SEG6_HMAC > > if (!seg6_hmac_validate_skb(skb, srh)) > > return NULL; > > -- > > 2.53.0 > > If you add the comment, consider: Reviewed-by: Gabriel Goller Thanks, Gabriel