netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: rtnetlink: Fix rtnl_dereference return value is NULL
@ 2021-07-08  7:37 Yajun Deng
  2021-07-08  8:08 ` Eric Dumazet
  0 siblings, 1 reply; 2+ messages in thread
From: Yajun Deng @ 2021-07-08  7:37 UTC (permalink / raw)
  To: davem, kuba, ryazanov.s.a, johannes.berg, avagin, vladimir.oltean,
	cong.wang, roopa, yajun.deng, zhudi21
  Cc: netdev, linux-kernel

rtnl_dereference() may be return NULL in rtnl_unregister(),
so add this case handling.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 net/core/rtnetlink.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index f6af3e74fc44..57ce22669b06 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -289,24 +289,27 @@ int rtnl_unregister(int protocol, int msgtype)
 	struct rtnl_link __rcu **tab;
 	struct rtnl_link *link;
 	int msgindex;
+	int ret = -ENOENT;
 
 	BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
 	msgindex = rtm_msgindex(msgtype);
 
 	rtnl_lock();
 	tab = rtnl_dereference(rtnl_msg_handlers[protocol]);
-	if (!tab) {
-		rtnl_unlock();
-		return -ENOENT;
-	}
+	if (!tab)
+		goto unlock;
 
 	link = rtnl_dereference(tab[msgindex]);
-	rcu_assign_pointer(tab[msgindex], NULL);
-	rtnl_unlock();
+	if (!link)
+		goto unlock;
 
+	rcu_assign_pointer(tab[msgindex], NULL);
 	kfree_rcu(link, rcu);
+	ret = 0;
 
-	return 0;
+unlock:
+	rtnl_unlock();
+	return ret;
 }
 EXPORT_SYMBOL_GPL(rtnl_unregister);
 
-- 
2.32.0


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

end of thread, other threads:[~2021-07-08  8:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-08  7:37 [PATCH] net: rtnetlink: Fix rtnl_dereference return value is NULL Yajun Deng
2021-07-08  8:08 ` Eric Dumazet

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).