ipv6: ndisc: fix potential out-of-bounds read in ndisc_router_discovery()
Subsystems (3)
PATCH 1/1 ipv6: ndisc: fix potential out-of-bounds read in ndisc_router_discovery()
This patch adds a length check at the start of ndisc_router_discovery() to prevent a potential out-of-bounds read if a short packet is received. Without this check, the function may dereference memory outside the buffer.
--- net/ipv6/ndisc.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/ndisc.c +4 -0
@@ -1235,6 +1235,10 @@ static void ndisc_ra_useropt(struct sk_buff *ra, struct nd_opt_hdr *opt)static enum skb_drop_reason ndisc_router_discovery (struct sk_buff *skb) { +// Check if the buffer contains enough data for the struct ra_msg +if (!pskb_may_pull (skb,skb_transport_offset (skb) +sizeof (struct ra_msg ))) +return SKB_DROP_REASON_PKT_TOO_SMALL ; +struct ra_msg *ra_msg = (struct ra_msg *)skb_transport_header (skb);bool send_ifinfo_notify = false;struct neighbour *neigh =NULL ;
Signature · 1 line
2.43.0
From: Rafal Bilkowski <[email protected]>
Date: Mon, 2 Jun 2025 08:58:26 +0200
Quoted 1 line
This patch adds a length check at the start of
ndisc_router_discovery()
I think it already has the check.
---8<---
optlen = (skb_tail_pointer(skb) - skb_transport_header(skb)) -
sizeof(struct ra_msg);
...
if (optlen < 0)
return SKB_DROP_REASON_PKT_TOO_SMALL;---8<---
Quoted 3 lines
to prevent a potential out-of-bounds read if a short packet is received. Without this check, the function may dereference memory outside the buffer.
Do you have a KMSAM splat ?
Quoted 12 lines
Fixes 8610c7c6e3bd ("net: ipv6: add support for rpl sr exthdr")Signed-off-by Rafal Bilkowski <[email protected]>--- net/ipv6/ndisc.c | 4 ++++ 1 file changed, 4 insertions(+)net/ipv6/ndisc.c +0
-0
net/ipv6/ndisc.c static void ndisc_ra_useropt(struct sk_buff *ra, struct nd_opt_hdr *opt) · line 1240
Quoted 6 lines
net/ipv6/ndisc.c +3
-0@@ -1235,6 +1235,10 @@ static void ndisc_ra_useropt(struct sk_buff *ra, struct nd_opt_hdr *opt)static enum skb_drop_reason ndisc_router_discovery (struct sk_buff *skb) { +// Check if the buffer contains enough data for the struct ra_msg +if (!pskb_may_pull (skb,skb_transport_offset (skb) +sizeof (struct ra_msg ))) +return SKB_DROP_REASON_PKT_TOO_SMALL ;
Please run checkpatch.pl. We don't add code before variable declarations.
Also, the skb is linearized in ndisc_rcv().
Quoted 6 lines
net/ipv6/ndisc.c +1
-0+struct ra_msg *ra_msg = (struct ra_msg *)skb_transport_header (skb);bool send_ifinfo_notify = false;struct neighbour *neigh =NULL ;Signature · 1 line
2.43.0