* [PATCH net v2] seg6: check segments_left in the pulled SRH to fix an out-of-bounds read
@ 2026-12-02 6:34 Juan Agustin Niccolini
2026-12-02 8:17 ` Hangbin Liu
0 siblings, 1 reply; 2+ messages in thread
From: Juan Agustin Niccolini @ 2026-12-02 6:34 UTC (permalink / raw)
To: Andrea Mayer, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: netdev, Simon Horman, Hangbin Liu, Gabriel Goller, David Ahern,
Julien Massonneau
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:
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. The
other SRH fields are already validated there, by seg6_validate_srh().
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
Reviewed-by: Gabriel Goller <g.goller@proxmox.com>
Signed-off-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
---
v2:
- add a comment above the check (Gabriel Goller)
- say that the other SRH fields are validated in the pulled header
(question from Hangbin Liu)
- add Gabriel's Reviewed-by tag
v1: https://lore.kernel.org/netdev/20261130031647.45247-1-juanagusnicco@gmail.com/
Reproducer: github.com/AgusNicco/seg6local-oob-read/blob/main/seg6_sl_race.c
The code is unchanged since v1, which 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 the 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 | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
index 82207da08dfd..27157a4456b5 100644
--- a/net/ipv6/seg6_local.c
+++ b/net/ipv6/seg6_local.c
@@ -235,6 +235,13 @@ static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb)
if (!srh)
return NULL;
+ /* IP6_FH_F_SKIP_RH makes ipv6_find_hdr() check segments_left in place,
+ * possibly in a page fragment that the sender can still write to.
+ * Check it again now that the SRH is in the linear area.
+ */
+ if (srh->segments_left == 0)
+ return NULL;
+
#ifdef CONFIG_IPV6_SEG6_HMAC
if (!seg6_hmac_validate_skb(skb, srh))
return NULL;
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net v2] seg6: check segments_left in the pulled SRH to fix an out-of-bounds read
2026-12-02 6:34 [PATCH net v2] seg6: check segments_left in the pulled SRH to fix an out-of-bounds read Juan Agustin Niccolini
@ 2026-12-02 8:17 ` Hangbin Liu
0 siblings, 0 replies; 2+ messages in thread
From: Hangbin Liu @ 2026-12-02 8:17 UTC (permalink / raw)
To: Juan Agustin Niccolini
Cc: Andrea Mayer, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, netdev, Simon Horman,
Gabriel Goller, David Ahern, Julien Massonneau
On Wed, Dec 02, 2026 at 01:34:04AM -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:
>
> 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. The
> other SRH fields are already validated there, by seg6_validate_srh().
> 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
> Reviewed-by: Gabriel Goller <g.goller@proxmox.com>
> Signed-off-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
> ---
> v2:
> - add a comment above the check (Gabriel Goller)
> - say that the other SRH fields are validated in the pulled header
> (question from Hangbin Liu)
> - add Gabriel's Reviewed-by tag
> v1: https://lore.kernel.org/netdev/20261130031647.45247-1-juanagusnicco@gmail.com/
>
> Reproducer: github.com/AgusNicco/seg6local-oob-read/blob/main/seg6_sl_race.c
>
> The code is unchanged since v1, which 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 the 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 | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
> index 82207da08dfd..27157a4456b5 100644
> --- a/net/ipv6/seg6_local.c
> +++ b/net/ipv6/seg6_local.c
> @@ -235,6 +235,13 @@ static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb)
> if (!srh)
> return NULL;
>
> + /* IP6_FH_F_SKIP_RH makes ipv6_find_hdr() check segments_left in place,
> + * possibly in a page fragment that the sender can still write to.
> + * Check it again now that the SRH is in the linear area.
> + */
> + if (srh->segments_left == 0)
> + return NULL;
> +
> #ifdef CONFIG_IPV6_SEG6_HMAC
> if (!seg6_hmac_validate_skb(skb, srh))
> return NULL;
> --
> 2.53.0
>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 8:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 6:34 [PATCH net v2] seg6: check segments_left in the pulled SRH to fix an out-of-bounds read Juan Agustin Niccolini
2026-12-02 8:17 ` Hangbin Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.