Netdev List
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: Hangbin Liu <hangbin.liu@linux.dev>
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>
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	[thread overview]
Message-ID: <aw6j7lz9lxN0t4Er@luna.proxmox.com> (raw)
In-Reply-To: <aw5awTuHzLyY-XES@fedora>

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


  reply	other threads:[~2026-12-01 10:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  3:16 [PATCH net] seg6: check segments_left in the pulled SRH to fix an out-of-bounds read Juan Agustin Niccolini
2026-12-01  5:27 ` Hangbin Liu
2026-12-01 10:43   ` Gabriel Goller [this message]
2026-12-02  6:30     ` Juan Agustin Niccolini
2026-12-02  8:03       ` Hangbin Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw6j7lz9lxN0t4Er@luna.proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=andrea.mayer@uniroma2.it \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=hangbin.liu@linux.dev \
    --cc=horms@kernel.org \
    --cc=juanagusnicco@gmail.com \
    --cc=julien.massonneau@6wind.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox