[PATCH] seg6: fix OOB read in advance_nextseg when segments_left is 0
From: Tang Bin
Date: Wed Oct 28 2026 - 07:35:23 EST
advance_nextseg() decrements srh->segments_left and uses it to index
srh->segments without checking it is non-zero. seg6_validate_srh() permits
segments_left == 0, so a packet with SRH segments_left==0 reaching an End*
action underflows the u8 (255) and reads srh->segments[255] (~4KB out of
bounds); the read bytes are then used as the new IPv6 destination address
(info leak) or crash on unmapped memory. The decap path
(decap_and_validate) already checks segments_left > 0, but the standard
End/End.X/End.T/End.B6.Encap/End.BPF paths do not. Reject segments_left ==
0 before decrementing.
Fixes: d7a669dd2f8b ("ipv6: sr: add helper functions for seg6local")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tang Bin <tangbin@xxxxxxxxxxxxxxxxxxxx>
---
net/ipv6/seg6_local.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
index 53f7b2452..1d8312467 100644
--- a/net/ipv6/seg6_local.c
+++ b/net/ipv6/seg6_local.c
@@ -310,6 +310,10 @@ static struct ipv6_sr_hdr *advance_nextseg(struct sk_buff *skb,
/* skb_ensure_writable() may change skb pointers; evaluate srh again */
srh = (struct ipv6_sr_hdr *)(skb->data + srhoff);
+ if (srh->segments_left == 0) {
+ *reason = SKB_DROP_REASON_NOT_SPECIFIED;
+ return NULL;
+ }
srh->segments_left--;
addr = srh->segments + srh->segments_left;
ipv6_hdr(skb)->daddr = *addr;
--
2.52.0.windows.1