public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeongjun Park <aha310510@gmail.com>
To: davem@davemloft.net, dsahern@kernel.org
Cc: edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	kafai@fb.com, weiwan@google.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Jeongjun Park <aha310510@gmail.com>
Subject: [PATCH net] net: prevent NULL pointer dereference in rt_fibinfo_free() and rt_fibinfo_free_cpus()
Date: Tue, 10 Sep 2024 03:48:27 +0900	[thread overview]
Message-ID: <20240909184827.123071-1-aha310510@gmail.com> (raw)

rt_fibinfo_free() and rt_fibinfo_free_cpus() only check for rt and do not
verify rt->dst and use it, which will result in NULL pointer dereference.

Therefore, to prevent this, we need to add a check for rt->dst.

Fixes: 0830106c5390 ("ipv4: take dst->__refcnt when caching dst in fib")
Fixes: c5038a8327b9 ("ipv4: Cache routes in nexthop exception entries.")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 net/ipv4/fib_semantics.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 2b57cd2b96e2..3a2a92599366 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -153,6 +153,8 @@ static void rt_fibinfo_free(struct rtable __rcu **rtp)
 
 	if (!rt)
 		return;
+	if (!&rt->dst)
+		return;
 
 	/* Not even needed : RCU_INIT_POINTER(*rtp, NULL);
 	 * because we waited an RCU grace period before calling
@@ -202,10 +204,13 @@ static void rt_fibinfo_free_cpus(struct rtable __rcu * __percpu *rtp)
 		struct rtable *rt;
 
 		rt = rcu_dereference_protected(*per_cpu_ptr(rtp, cpu), 1);
-		if (rt) {
-			dst_dev_put(&rt->dst);
-			dst_release_immediate(&rt->dst);
-		}
+		if (!rt)
+			continue;
+		if (!&rt->dst)
+			continue;
+
+		dst_dev_put(&rt->dst);
+		dst_release_immediate(&rt->dst);
 	}
 	free_percpu(rtp);
 }
--

             reply	other threads:[~2024-09-09 18:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-09 18:48 Jeongjun Park [this message]
2024-09-09 19:01 ` [PATCH net] net: prevent NULL pointer dereference in rt_fibinfo_free() and rt_fibinfo_free_cpus() Eric Dumazet
2024-09-10  3:22   ` Jeongjun Park
2024-09-10  6:00     ` Eric Dumazet
2024-09-10  6:19     ` Eric Dumazet
2024-09-10 14:06       ` Jeongjun Park
2024-09-10 14:17         ` Eric Dumazet
2024-09-10 15:00 ` kernel test robot
2024-09-10 16:42 ` kernel test robot

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=20240909184827.123071-1-aha310510@gmail.com \
    --to=aha310510@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=weiwan@google.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