From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.141 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796102866; b=hPhpyLiAvHFnfHWGvK+qxnkvgJCejJ4R8YrXLdu5+Xt9rLn3p2xkzaKgAlckmByzaFuZ uzVdnhT8GEVgTHms9wrN2MPy/HlAHz7KwHN1Aglb26g9fjyYp7pPv7lFCrgSV03o0uk7q 0G1HFNDLLPgnvuHZdbbEoL4AbObfl3f0IqojN9E5ClcKlx5gqe9zOpYzw/DU5MC2US0E2 oGvczGUDjUCsYSt/H+8VH0XF3J8xSFJIsKXAGHlpUbEzQ/fnv4FqUTltAOICxUrmoYZVF Wywng7AgcsjUwjiNajIwESrj2uUy2Nwodp9dAqZ8Hk4kwWQKs10tWELntHGCH4of99g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796102866; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=kt8JP2MwBVq6MvcVtYkrKrMY+yMisaswanPKV/OYsPc=; b=Ytpw5BUsS3S9Lc0Gi4LBbsMTc0jtZzYti6R2ciU/ADDhZqqZBPBc2I2hcbMpn5RY1Tsf imBndvc9ZoqB0uRgVHFKd8eF2BbETTRxfhWEri1H02B5jDmIY9M+FU5DzYENqUASBUXZC Muv6AsuwWwrMCeMg2YW+j+H93E0sHlTcTJ0wUh6oslEQ/rZ4Q4BQ7gNnWtuj20zKgIw2w lVM3kTEVs6oYmE2VhmEO1jbISZO8GJLQsx1lKusu77lzIsxuVyZD7f9PQSSfGh1Ml7bSa PWWIIGGmIvD4sMevHxSQbJn5zG4FFWOUn1s+qdZ9p4K+Np/8uOUwNuDqDab/5uhFAQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=oZ5Keb6d; arc=none smtp.remote-ip=91.218.175.141 Received: from mta0.migadu.com (out-141.mta0.migadu.com [91.218.175.141]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06358606A320 for ; Tue, 1 Dec 2026 05:27:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 06358606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=oZ5Keb6d X-Envelope-To: netdev@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=hYClrZhiv6bhLBaADGISdJoeUVIw/zcO0Ffng58XE2I=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796102864; v=1; x=1796707664; b=oZ5Keb6dXQ0rXBznn1fcyURqBAKwL55fXqyJlW1r4/JQhTEai7+/1FcqLdkdqXgEpGUpxa2g A2HGLHTLCMy8VnhFHSIDKwak5wi8WQd6gtR7YLwjTmKsWLo/r/PGqfPt9VbTfNQDierPt+BwuL4 N3SBjsTIQj363vQi9PK4rq5Q= X-Envelope-To: netdev@vger.kernel.org Received: by mta10.migadu.com with ESMTPS id 11eae3e08de9d8e0; Tue, 01 Dec 2026 05:27:43 +0000 X-Mizu-Trace-ID: 11eae3e08de9d8e0 X-Migadu-Flow: FLOW_OUT Date: Tue, 1 Dec 2026 13:27:29 +0800 From: Hangbin Liu To: Juan Agustin Niccolini Cc: 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=us-ascii Content-Disposition: inline In-Reply-To: <20261130031647.45247-1-juanagusnicco@gmail.com> 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? And we put the check in get_and_validate_srh, what if it changed later and before or after advance_nextseg()? 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; > > + if (srh->segments_left == 0) > + return NULL; > + > #ifdef CONFIG_IPV6_SEG6_HMAC > if (!seg6_hmac_validate_skb(skb, srh)) > return NULL; > -- > 2.53.0 >