Netdev List
 help / color / mirror / Atom feed
* [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
@ 2026-11-20 13:45 mdshahid03
  2026-11-20 13:49 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: mdshahid03 @ 2026-11-20 13:45 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni; +Cc: netdev, linux-kernel, Mohammad Shahid

From: Mohammad Shahid <mdshahid03@gmail.com>

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-20 13:45 [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link() mdshahid03
@ 2026-11-20 13:49 ` netdev-bot+sinfo
  2026-11-20 18:04 ` Jakub Kicinski
  2026-11-24 13:58 ` netdev-bot+sashiko
  2 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sinfo @ 2026-11-20 13:49 UTC (permalink / raw)
  To: mdshahid03; +Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel

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.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-20 13:45 [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link() mdshahid03
  2026-11-20 13:49 ` netdev-bot+sinfo
@ 2026-11-20 18:04 ` Jakub Kicinski
  2026-11-21 11:10   ` mdshahid03
  2026-11-24 13:58 ` netdev-bot+sashiko
  2 siblings, 1 reply; 10+ messages in thread
From: Jakub Kicinski @ 2026-11-20 18:04 UTC (permalink / raw)
  To: mdshahid03; +Cc: davem, edumazet, pabeni, netdev, linux-kernel

On Fri, 20 Nov 2026 19:15:48 +0530 mdshahid03@gmail.com wrote:
> From: Mohammad Shahid <mdshahid03@gmail.com>
> 
> 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]);
>  }
>  


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-20 18:04 ` Jakub Kicinski
@ 2026-11-21 11:10   ` mdshahid03
  2026-11-23 10:56     ` Paolo Abeni
  0 siblings, 1 reply; 10+ messages in thread
From: mdshahid03 @ 2026-11-21 11:10 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: mdshahid03, davem, edumazet, pabeni, netdev, linux-kernel

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@gmail.com wrote:
> > From: Mohammad Shahid <mdshahid03@gmail.com>
> > 
> > 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]);
> >  }
> >  
> 
> 
> 



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-21 11:10   ` mdshahid03
@ 2026-11-23 10:56     ` Paolo Abeni
  2026-11-23 16:01       ` mdshahid03
  0 siblings, 1 reply; 10+ messages in thread
From: Paolo Abeni @ 2026-11-23 10:56 UTC (permalink / raw)
  To: mdshahid03, Jakub Kicinski; +Cc: davem, edumazet, netdev, linux-kernel

On 11/21/26 12:10, mdshahid03@gmail.com 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-23 10:56     ` Paolo Abeni
@ 2026-11-23 16:01       ` mdshahid03
  2026-11-23 18:01         ` Eric Dumazet
  2026-11-24  8:56         ` Paolo Abeni
  0 siblings, 2 replies; 10+ messages in thread
From: mdshahid03 @ 2026-11-23 16:01 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: mdshahid03, Jakub Kicinski, davem, edumazet, netdev, linux-kernel

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.

On 2026-11-23 11:56 +0100, Paolo Abeni wrote:
> On 11/21/26 12:10, mdshahid03@gmail.com 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
> 
> 
> 



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-23 16:01       ` mdshahid03
@ 2026-11-23 18:01         ` Eric Dumazet
  2026-11-24  8:56         ` Paolo Abeni
  1 sibling, 0 replies; 10+ messages in thread
From: Eric Dumazet @ 2026-11-23 18:01 UTC (permalink / raw)
  To: mdshahid03; +Cc: Paolo Abeni, Jakub Kicinski, davem, netdev, linux-kernel

Le lun. 23 nov. 2026 à 17:02, <mdshahid03@gmail.com> a écrit :
>
> 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 ?

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.

>
> 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.

>
> 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.

>
> I am asking because, like to understand the correct approach and apply
> it to my future kernel contributions.
>
> Have a nice day !!!
>
> Thanks
> Shahid.
>
> On 2026-11-23 11:56 +0100, Paolo Abeni wrote:
> > On 11/21/26 12:10, mdshahid03@gmail.com 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
> >
> >
> >
>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-23 16:01       ` mdshahid03
  2026-11-23 18:01         ` Eric Dumazet
@ 2026-11-24  8:56         ` Paolo Abeni
  2026-11-24 13:34           ` mdshahid03
  1 sibling, 1 reply; 10+ messages in thread
From: Paolo Abeni @ 2026-11-24  8:56 UTC (permalink / raw)
  To: mdshahid03; +Cc: Jakub Kicinski, davem, edumazet, netdev, linux-kernel

On 11/23/26 17:01, mdshahid03@gmail.com 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-24  8:56         ` Paolo Abeni
@ 2026-11-24 13:34           ` mdshahid03
  0 siblings, 0 replies; 10+ messages in thread
From: mdshahid03 @ 2026-11-24 13:34 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: mdshahid03, Jakub Kicinski, davem, edumazet, netdev, linux-kernel

Thanks Eric and Paolo for the detailed explanation.

On 2026-11-24 09:56 +0100, Paolo Abeni wrote:
> On 11/23/26 17:01, mdshahid03@gmail.com 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
> 
> 
> 



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link()
  2026-11-20 13:45 [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link() mdshahid03
  2026-11-20 13:49 ` netdev-bot+sinfo
  2026-11-20 18:04 ` Jakub Kicinski
@ 2026-11-24 13:58 ` netdev-bot+sashiko
  2 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 13:58 UTC (permalink / raw)
  To: mdshahid03; +Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The commit message describes a crash that cannot happen.

--

rtnetlink: fix NULL pointer dereference in rtnl_get_link()

This patch adds a NULL check in rtnl_get_link(). The check covers the case
where the PF_UNSPEC fallback handler table is also NULL, so the function
returns NULL instead of dereferencing tab[msgtype].

> 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.

[Severity: Medium]
Can rtnl_msg_handlers[PF_UNSPEC] actually become NULL at runtime? Nothing
in the tree seems to call rtnl_unregister_all(PF_UNSPEC). Its callers all
pass a specific family:

  net/can/gw.c:        rtnl_unregister_all(PF_CAN);
  net/ipv6/addrconf.c: rtnl_unregister_all(PF_INET6);
  net/ipv6/af_inet6.c: rtnl_unregister_all(PF_INET6);
  net/ipv6/route.c:    rtnl_unregister_all(PF_INET6);
  net/mpls/af_mpls.c:  rtnl_unregister_all(PF_MPLS);
  net/phonet/pn_dev.c: rtnl_unregister_all(PF_PHONET);

The PF_UNSPEC table is allocated at boot in the __init function
rtnetlink_init():

	rtnl_register_many(rtnetlink_rtnl_msg_handlers);

Nothing frees that table afterwards.

Modules that remove PF_UNSPEC handlers do it through
rtnl_unregister()/rtnl_unregister_many(). Those only clear individual slots:

net/core/rtnetlink.c:rtnl_unregister() {
    ...
	link = rcu_replace_pointer_rtnl(tab[msgindex], NULL);
    ...
}

They never set rtnl_msg_handlers[PF_UNSPEC] to NULL.

The callers in rtnetlink_rcv_msg() already handle a NULL link:

	link = rtnl_get_link(family, type);
	if (!link || !link->doit) {

So the new check looks like harmless defensive code, not a fix for a crash
anyone can reach. Could the commit message say that, or show the real
trigger, with a reproducer or oops trace if there is one? As written, the
subject and body read like a reachable NULL dereference fix, and stable
backport tooling might pick it up as one.

There are also some typos: "cass" should be "case", "msgtyp" should be
"msgtype", and "NULL,for" is missing a space.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120134548.214126-1-mdshahid03%40gmail.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-24 13:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 13:45 [PATCH] rtnetlink: fix NULL pointer dereference in rtnl_get_link() mdshahid03
2026-11-20 13:49 ` netdev-bot+sinfo
2026-11-20 18:04 ` Jakub Kicinski
2026-11-21 11:10   ` mdshahid03
2026-11-23 10:56     ` Paolo Abeni
2026-11-23 16:01       ` mdshahid03
2026-11-23 18:01         ` Eric Dumazet
2026-11-24  8:56         ` Paolo Abeni
2026-11-24 13:34           ` mdshahid03
2026-11-24 13:58 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox