* [PATCH net v2] phonet: check register_netdevice_notifier() error in phonet_device_init()
@ 2026-07-16 10:15 Minhong He
2026-07-16 13:40 ` Andrew Lunn
0 siblings, 1 reply; 2+ messages in thread
From: Minhong He @ 2026-07-16 10:15 UTC (permalink / raw)
To: courmisch, davem, edumazet, kuba, pabeni, horms, remi.denis-courmont
Cc: netdev, linux-kernel, Minhong He
phonet_device_init() registers a netdevice notifier before calling
phonet_netlink_register(), but does not check whether notifier
registration succeeded. On failure, netlink setup still proceeds and
init may return success without the notifier in place.
Check the notifier registration error and unwind only the resources
that were already registered (proc entry and pernet), without calling
unregister_netdevice_notifier() for a notifier that was never
registered.
Fixes: f8ff60283de2 ("Phonet: network device and address handling")
Signed-off-by: Minhong He <heminhong@kylinos.cn>
---
v2:
- On notifier registration failure, unwind only proc/pernet; do not call
phonet_device_exit() / unregister_netdevice_notifier() for a notifier
that was never registered.
v1: https://lore.kernel.org/netdev/20260713075212.431455-1-heminhong@kylinos.cn/
net/phonet/pn_dev.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index ad44831d6745..e6c31cfdad9a 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -356,7 +356,12 @@ int __init phonet_device_init(void)
proc_create_net("pnresource", 0, init_net.proc_net, &pn_res_seq_ops,
sizeof(struct seq_net_private));
- register_netdevice_notifier(&phonet_device_notifier);
+ err = register_netdevice_notifier(&phonet_device_notifier);
+ if (err) {
+ remove_proc_entry("pnresource", init_net.proc_net);
+ unregister_pernet_subsys(&phonet_net_ops);
+ return err;
+ }
err = phonet_netlink_register();
if (err)
phonet_device_exit();
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH net v2] phonet: check register_netdevice_notifier() error in phonet_device_init()
2026-07-16 10:15 [PATCH net v2] phonet: check register_netdevice_notifier() error in phonet_device_init() Minhong He
@ 2026-07-16 13:40 ` Andrew Lunn
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2026-07-16 13:40 UTC (permalink / raw)
To: Minhong He
Cc: courmisch, davem, edumazet, kuba, pabeni, horms,
remi.denis-courmont, netdev, linux-kernel
On Thu, Jul 16, 2026 at 06:15:04PM +0800, Minhong He wrote:
> phonet_device_init() registers a netdevice notifier before calling
> phonet_netlink_register(), but does not check whether notifier
> registration succeeded. On failure, netlink setup still proceeds and
> init may return success without the notifier in place.
>
> Check the notifier registration error and unwind only the resources
> that were already registered (proc entry and pernet), without calling
> unregister_netdevice_notifier() for a notifier that was never
> registered.
It is a good idea to look around, and see if the same sort of bug
appears again. Think about what happens when phonet_netlink_register()
fails.
> Fixes: f8ff60283de2 ("Phonet: network device and address handling")
Does this bother people
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-16 13:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-16 10:15 [PATCH net v2] phonet: check register_netdevice_notifier() error in phonet_device_init() Minhong He
2026-07-16 13:40 ` Andrew Lunn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox