The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Rafal Bilkowski <rafalbilkowski@gmail.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, davem@davemloft.net,
	dsahern@kernel.org, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, alex.aring@gmail.com,
	rafalbilkowski@gmail.com
Subject: [PATCH] ipv6: ndisc: fix potential out-of-bounds read in ndisc_router_discovery()
Date: Mon,  2 Jun 2025 08:58:26 +0200	[thread overview]
Message-ID: <20250602065826.168402-1-rafalbilkowski@gmail.com> (raw)

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


             reply	other threads:[~2025-06-02  6:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-02  6:58 Rafal Bilkowski [this message]
2025-06-02 21:32 ` [PATCH] ipv6: ndisc: fix potential out-of-bounds read in ndisc_router_discovery() Kuniyuki Iwashima

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=20250602065826.168402-1-rafalbilkowski@gmail.com \
    --to=rafalbilkowski@gmail.com \
    --cc=alex.aring@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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