Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
From: Jakub Kicinski
Date: Fri Nov 20 2026 - 13:06:01 EST
On Fri, 20 Nov 2026 19:15:48 +0530 mdshahid03@xxxxxxxxx wrote:
> 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.
How can this happen? If you can't answer that - please do
not submit any patches to Linux networking for at least
6 months.
> 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]);
> }
>