public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: prevent NULL pointer dereference in rt_fibinfo_free() and rt_fibinfo_free_cpus()
@ 2024-09-09 18:48 Jeongjun Park
  2024-09-09 19:01 ` Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jeongjun Park @ 2024-09-09 18:48 UTC (permalink / raw)
  To: davem, dsahern
  Cc: edumazet, kuba, pabeni, kafai, weiwan, netdev, linux-kernel,
	Jeongjun Park

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);
 }
--

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-09-10 16:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-09 18:48 [PATCH net] net: prevent NULL pointer dereference in rt_fibinfo_free() and rt_fibinfo_free_cpus() Jeongjun Park
2024-09-09 19:01 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox