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

From: mdshahid03

Date: Sat Nov 21 2026 - 06:11:18 EST


Hi Jakub,

I tested this issue on both original and patched kernels in qemu.

First, I used a test module to unregister all PF_UNSPEC handlers.

On the original kernel ,running ip link show caused a kernel crash
due to a NULL pointer dereference.

~ # ip link show
[ 84.803284][ T65] BUG: kernel NULL pointer dereference, address: 0000000000000010
[ 84.803926][ T65] #PF: supervisor read access in kernel mode
[ 84.804231][ T65] #PF: error_code(0x0000) - not-present page
[ 84.804698][ T65] PGD 4d55067 P4D 4d55067 PUD 4d56067 PMD 0
[ 84.805370][ T65] Oops: Oops: 0000 [#1] NOPTI
[ 84.806277][ T65] CPU: 0 UID: 0 PID: 65 Comm: ip Tainted: G OE 7.3.0-13253-gbc2a37970c19 #1 PREEMPT(lazy)
[ 84.807170][ T65] Tainted: [O]=OOT_MODULE, [E]=UNSIGNED_MODULE
[ 84.807477][ T65] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[ 84.808195][ T65] RIP: 0010:rtnetlink_rcv_msg+0xc1/0x350
[ 84.809058][ T65] Code: e5 f1 6a 01 4a 8b 44 f8 80 48 85 c0 74 09 4c 8b 68 08 4d 85 ed 75 2e 48 8b 05 cb f1 6a 01 48 85 c0 75 07 48 8b 05 bf f1 6a 01 <4a> 8b 44 f8 80 48 85 c0 0f 84 9d 01 00 00 4c 8b 68 08 4d 85 ed 0f

On the patched kernel, the same test did not cause a crash ,instead
the command returned "Operation not supported" ,which is expected
becasue no handler was avibale.

~ # insmod /modules/rtnl_unspec_trigger.ko
[ 71.413827][ T62] rtnl_unspec_trigger: loading out-of-tree module taints kernel.
[ 71.414093][ T62] rtnl_unspec_trigger: module verification failed: signature and/or required key missing - tainting kernel
[ 71.428825][ T62] rtnl_test: unregistering PF_UNSPEC handlers
[ 71.430356][ T62] rtnl_test: PF_UNSPEC handlers unregistered
~ # ip link show
ip: RTNETLINK answers: Operation not supported
ip: dump terminated

This confirms that the NULL check prevents the crash in this case.

I have collected the logs. BTW,This issue was reported by CLANG.
239873:net/core/rtnetlink.c:409:9: warning: Dereference of null pointer [clang-analyzer-core.NullDereference]

Thanks
Shahid.

On 2026-11-20 10:04 -0800, Jakub Kicinski wrote:
> 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]);
> > }
> >
>
>
>