* [PATCH] ipv6: ndisc: fix potential out-of-bounds read in ndisc_router_discovery()
@ 2025-06-02 6:58 Rafal Bilkowski
2025-06-02 21:32 ` Kuniyuki Iwashima
0 siblings, 1 reply; 2+ messages in thread
From: Rafal Bilkowski @ 2025-06-02 6:58 UTC (permalink / raw)
To: netdev
Cc: linux-kernel, davem, dsahern, edumazet, kuba, pabeni, alex.aring,
rafalbilkowski
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.
Fixes: 8610c7c6e3bd ("net: ipv6: add support for rpl sr exthdr")
Signed-off-by: Rafal Bilkowski <rafalbilkowski@gmail.com>
---
net/ipv6/ndisc.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 8d853971f2f6..bdaac5a195d6 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ipv6: ndisc: fix potential out-of-bounds read in ndisc_router_discovery()
2025-06-02 6:58 [PATCH] ipv6: ndisc: fix potential out-of-bounds read in ndisc_router_discovery() Rafal Bilkowski
@ 2025-06-02 21:32 ` Kuniyuki Iwashima
0 siblings, 0 replies; 2+ messages in thread
From: Kuniyuki Iwashima @ 2025-06-02 21:32 UTC (permalink / raw)
To: rafalbilkowski
Cc: alex.aring, davem, dsahern, edumazet, kuba, linux-kernel, netdev,
pabeni
From: Rafal Bilkowski <rafalbilkowski@gmail.com>
Date: Mon, 2 Jun 2025 08:58:26 +0200
> 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<---
> 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 ?
>
> Fixes: 8610c7c6e3bd ("net: ipv6: add support for rpl sr exthdr")
> Signed-off-by: Rafal Bilkowski <rafalbilkowski@gmail.com>
> ---
> net/ipv6/ndisc.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
> index 8d853971f2f6..bdaac5a195d6 100644
> --- a/net/ipv6/ndisc.c
> +++ b/net/ipv6/ndisc.c
> @@ -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().
> +
> struct ra_msg *ra_msg = (struct ra_msg *)skb_transport_header(skb);
> bool send_ifinfo_notify = false;
> struct neighbour *neigh = NULL;
> --
> 2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-02 21:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-02 6:58 [PATCH] ipv6: ndisc: fix potential out-of-bounds read in ndisc_router_discovery() Rafal Bilkowski
2025-06-02 21:32 ` Kuniyuki Iwashima
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).