Skip to contentSkip to conversation

net: rtnetlink: Fix rtnl_dereference return value is NULL

PATCH Superseded Yajun Deng 2 participants 2 messages Jul 8, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yajun Deng

author
#0 lore raw

PATCH 1/1 net: rtnetlink: Fix rtnl_dereference return value is NULL

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

---
 net/core/rtnetlink.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
net/core/rtnetlink.c +10 -7
index f6af3e74fc44..57ce22669b06 100644
@@ -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);
 
Signature · 1 line
2.32.0
#1 lore raw
Quoted 8 lines · Yajun Deng

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

---
 net/core/rtnetlink.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

I do not see a use case for this.
None of rtnl_unregister() callers check the return value anyway.

Can you elaborate ?

If this was a bug fix, we would need a Fixes: tag.

If this is something you need for an upcoming work, you would need to tag this for net-next tree.

Thanks.