[PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()

From: mdshahid03

Date: Fri Nov 20 2026 - 08:46:32 EST


From: Mohammad Shahid <mdshahid03@xxxxxxxxx>

The rtnl_get_link() function falls back to the PF_UNSPEC
handler table when no handler table is registered for the
requested protocol.

However, the fallback table can also be NULL,for example
after rtnl_unregister_all(PF_UNSPEC) clears it.

In that cass, dereferencing tab[msgtyp] results in a NULL
pointer dereference.

Signed-off-by: Mohammad Shahid <mdshahid03@xxxxxxxxx>
---
net/core/rtnetlink.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index e141340172ce..b552cbf17d76 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -406,6 +406,9 @@ static struct rtnl_link *rtnl_get_link(int protocol, int msgtype)
if (!tab)
tab = rcu_dereference_rtnl(rtnl_msg_handlers[PF_UNSPEC]);

+ if (!tab)
+ return NULL;
+
return rcu_dereference_rtnl(tab[msgtype]);
}

--
2.43.0