Skip to contentSkip to conversation

rtnetlink: fix NULL pointer dereference in rtnl_get_link()

PATCH In review [email protected] 5 participants 8 messages Nov 20 – Nov 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtnetlink: fix NULL pointer dereference in rtnl_get_link()

From: Mohammad Shahid <[email protected]>

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.

---
 net/core/rtnetlink.c | 3 +++
 1 file changed, 3 insertions(+)
net/core/rtnetlink.c +3 -0
index e141340172ce..b552cbf17d76 100644
@@ -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]);
 }
 
Signature · 1 line
2.43.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
maintainer
#2 lore raw
In reply to [email protected]
Quoted 11 lines · On Fri, 20 Nov 2026 19:15:48 +0530 [email protected] wrote:

From: Mohammad Shahid <[email protected]>

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.

Quoted 14 lines
net/core/rtnetlink.c +3 -0
index e141340172ce..b552cbf17d76 100644
@@ -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]);
 }
 
#3 lore raw

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.

Quoted 34 lines · Jakub Kicinski
Quoted 11 lines · On Fri, 20 Nov 2026 19:15:48 +0530 [email protected] wrote:

From: Mohammad Shahid <[email protected]>

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.

Quoted 14 lines
net/core/rtnetlink.c +3 -0
index e141340172ce..b552cbf17d76 100644
@@ -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]);
 }
 
maintainer
#4 lore raw
Quoted 3 lines · On 11/21/26 12:10, [email protected] wrote:

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

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

Just in case the are any doubts on the poic: if you need a custom OoO kernel module to trigger a 'bug', it's not a bug.

/P

#5 lore raw

Thanks Paolo.

I think,I may have misunderstood this part from NET documentation guidelines:

"The commit message must disclose whether reproducing the issue required modifying the kernel (e.g. inserting a delay to widen a race, or[[**writing a loadable module to issue the right sequence of calls)**]] or using error injection."

I interpreted this as allowing a out-of-tree test module to produce an issue,provided that it uses legitimate kernel APIs.

1.am i intrepretting incorrectly ?

2.This is general question ,i mean ,we can litrally crash the kernel just with loadable module ? How do we distinguish a legitimate kernel bug exposed through a test module from a crash caused by an artificial or unsupported sequence of operations? is this not vulnerablity in a way or design issue ?

3.Don't you see a gap in documentation w.r.t testing with loadable module in details.

I am asking because, like to understand the correct approach and apply it to my future kernel contributions.

Have a nice day !!!

Thanks
Shahid.

Quoted 12 lines · Paolo Abeni
Quoted 3 lines · On 11/21/26 12:10, [email protected] wrote:

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

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

Just in case the are any doubts on the poic: if you need a custom OoO kernel module to trigger a 'bug', it's not a bug.

/P

maintainer
#6 lore raw
Quoted 5 lines · Le lun. 23 nov. 2026 à 17:02, <[email protected]> a écrit :

Thanks Paolo.

I think,I may have misunderstood this part from NET documentation guidelines:

Quoted 8 lines

"The commit message must disclose whether reproducing the issue required modifying the kernel (e.g. inserting a delay to widen a race, or[[**writing a loadable module to issue the right sequence of calls)**]] or using error injection."

I interpreted this as allowing a out-of-tree test module to produce an issue,provided that it uses legitimate kernel APIs.

1.am i intrepretting incorrectly ?

Yes.

This sentence is a disclosure requirement, so that reviewers know how much weight to give to the reproducer. It does not say that any crash obtained this way is a bug.

A test module (or an added delay) is fine when it only makes it easier to reach a state that the unmodified kernel can reach by itself, for instance to widen a race window, or to exercise an in-tree code path that is hard to trigger from user space.

Your module does something different: it creates a state that no in-tree code can create.

rtnl_msg_handlers[PF_UNSPEC] is populated from rtnetlink_init(), which is built-in and panics if the registration fails. Nothing in the tree calls rtnl_unregister_all(PF_UNSPEC), the only callers are for PF_PHONET, PF_INET6, PF_MPLS and PF_CAN.

So the PF_UNSPEC table is never NULL once the kernel has booted, and rtnl_get_link() relies on this.

This is what Jakub asked in his first reply ("How can this happen?"), and the changelog should have answered it.

Quoted 6 lines

2.This is general question ,i mean ,we can litrally crash the kernel just with loadable module ? How do we distinguish a legitimate kernel bug exposed through a test module from a crash caused by an artificial or unsupported sequence of operations? is this not vulnerablity in a way or design issue ?

Of course a module can crash the kernel. A module runs with full kernel privileges, it can call panic(), or overwrite any memory. Loading one requires CAP_SYS_MODULE. There is no security boundary between a module and the rest of the kernel, so this is not a vulnerability.

Exported functions are not hardened against callers misusing them. We do not add checks for conditions that can not happen, they add code, and they hide the invariants from people reading the code.

The question to ask is: can the unmodified kernel reach this state, from user space, from the network, or from a device?

If yes, you should be able to describe the in-tree call chain in the changelog, and in most cases to trigger it without a module.

If the only way is to add new kernel code calling an API in a way no in-tree user does, there is nothing to fix.

Note that clang-analyzer does not know about this kind of invariant. Its reports are a starting point for an analysis, they are not a proof that a bug exists.

Quoted 3 lines

3.Don't you see a gap in documentation w.r.t testing with loadable module in details.

Not really. The documentation asks how the bug was confirmed to be real. A module unregistering the PF_UNSPEC handlers does not confirm anything about the upstream kernel.

Quoted 24 lines

I am asking because, like to understand the correct approach and apply it to my future kernel contributions.

Have a nice day !!!

Thanks
Shahid.

Quoted 12 lines · Paolo Abeni
Quoted 3 lines · On 11/21/26 12:10, [email protected] wrote:

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

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

Just in case the are any doubts on the poic: if you need a custom OoO kernel module to trigger a 'bug', it's not a bug.

/P

maintainer
#7 lore raw
In reply to [email protected]
Quoted 8 lines · On 11/23/26 17:01, [email protected] wrote:

I think,I may have misunderstood this part from NET documentation guidelines:

"The commit message must disclose whether reproducing the issue required modifying the kernel (e.g. inserting a delay to widen a race, or[[**writing a loadable module to issue the right sequence of calls)**]] or using error injection."

I interpreted this as allowing a out-of-tree test module to produce an issue,provided that it uses legitimate kernel APIs.

Please do not top post.

The problematic point is the 'legitimate API'. Adding a delay under a lock is legitimate, de-registring core functionalities is not.

If you want to use a kernel module to demonstrate an 'issue', such module must do exclusively things the kernel is already doing, it should just enforces specific timing/sequence that must be already possible in vanilla.

And if the race is possible only with such a module, at very best the issue will get low priority.

/P