🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25167

Re: [PATCH net] seg6: check segments_left in the pulled SRH to fix an out-of-bounds read

#25167
From: Gabriel Goller
Date: Tue, 01 Dec 2026 10:43
88 lines
10906 bytes
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 <juanagusnicco@gmail.com>
> > ---
> > 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 <g.goller@proxmox.com>

Thanks,
Gabriel
Technical Details
Message-ID: <aw6j7lz9lxN0t4Er@luna.proxmox.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374945-linux-kernel-netdev=dewy.ru
References: <20261130031647.45247-1-juanagusnicco@gmail.com> <aw5awTuHzLyY-XES@fedora>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374945-linux-kernel-netdev=dewy.ru
From: g.goller@proxmox.com (Gabriel Goller)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] seg6: check segments_left in the pulled SRH to fix
 an out-of-bounds read
Date: Tue, 1 Dec 2026 11:43:23 +0100
Organization: Usenet Network
Message-ID: <aw6j7lz9lxN0t4Er@luna.proxmox.com>
References: <20261130031647.45247-1-juanagusnicco@gmail.com>
 <aw5awTuHzLyY-XES@fedora>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Info: usenet.network;
	logging-data="1688436"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:C1iTbBPE6qpzYeEH6jrpgb1cRhk= sha256:SkRyFSOmpJoAZTyMB7b36Iyvy+ukY/sfv7waimbGghw=
	sha1:IODJyY2sYjmPgv5muGVZX/lL7N4= sha256:SdnHVpri5wicLN/UOImAOFuag3HmQ7HrgL2QeEcyr0g=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id AAFA111732F; Tue,  1 Dec 2026 13:43:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Ll7blh2gLS1O;
	Tue,  1 Dec 2026 13:43:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374945-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=proxmox.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id D220B117317; Tue,  1 Dec 2026 13:43:38 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 3A58825147; Tue,  1 Dec 2026 10:43:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796121816;
	b=mBO42GZmSFheHvN5FvJV+02SXsXk+CIu0QCgg3E6xnsHlGrU428qr9NF9d+UZMxtMN9V
	 KNj3FFauEoqe2EloHzGhWzsLSBMi7C6GKR3XhYzTusW2t2axf5xD7HSlwEu125zwcynl4
	 bdCEoi+6Alhim3bxqmK6+gvBGYbUmIIwni77qXFMA1XudBR1vP7CEtGtDf00u2z7RDl9W
	 gGUe2oFNGwo7MDSobqiZJyp6+wnlYXY2KO0oYvSAO+ji5To+vHGbBFY2fUlb//ITSRsAp
	 qZcXQD10/mwEiWgurikoUShpWJiHtWBUrqvCfmAEkYrqtlswkZO5BMZV7JGfQKFs+AQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796121816;
	h=X-Original-To:Received:DMARC-Filter:Received:Date:From:To:Cc:Subject:
	 Message-ID:References:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To:User-Agent:
	 X-Bm-Milter-Handled:X-Bm-Transport-Timestamp;
	bh=CFpK1ptrwn65ffBpVJTOb/LJDU1ADqXK+spHU1c5U8Y=;
	b=CoDYYDkYFPpp1Sq/2gyWhDyxVTtl7nSlyd862Vcl91PNu8FxJihJMNCMQwCMvt+eqVaP
	 tv0bkq3UgXn9d9hj2msLIQZjdYjS/v2WsOH02BakwibOn3SFmMGssGno8sSaFQAur31Sz
	 W5tVjPb1LA75u0NkV42ShTpVXwtoasjFm5c3agrioVSpvSMD1oDOZGb4JAUqV7HWm5dCF
	 PG6oxtqbo2v2f7voVjXR45b2uHg53doJMiwFtEv6NdHGIUES/fIFZ8L5gF3pwZgWGNesK
	 AVjAZQVaI8cxrUmhrLQhRWHG5Cv+Xn+RYIuhBVa3A/H1Oy7kXfVXy17aXvHXNMmAVZQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=proxmox.com;
	spf=pass smtp.mailfrom=proxmox.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id E1378606A32C;
	Tue,  1 Dec 2026 10:43:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=94.136.29.106
X-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==
X-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==
X-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
X-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 <netdev@vger.kernel.org>; Tue,  1 Dec 2026 10:43:34 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DA599606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=proxmox.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proxmox.com
X-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)
X-Cc: Juan Agustin Niccolini <juanagusnicco@gmail.com>, 
	Andrea Mayer <andrea.mayer@uniroma2.it>, "David S . Miller" <davem@davemloft.net>, 
	Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, 
	Paolo Abeni <pabeni@redhat.com>, Willem de Bruijn <willemb@google.com>, netdev@vger.kernel.org, 
	Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>, 
	Julien Massonneau <julien.massonneau@6wind.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <aw5awTuHzLyY-XES@fedora>
X-User-Agent: NeoMutt/20260616
X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2
X-Bm-Transport-Timestamp: 1796121804904