net: hsr: free learned nodes on device setup failure
Subsystems (3)
PATCH 1/1 net: hsr: free learned nodes on device setup failure
hsr_dev_finalize() can fail after a lower-device RX handler has already been registered (slave A is added before the failable slave B and interlink adds). RX handlers run in softirq regardless of the master's state, so frames received in that window can learn dynamic nodes into node_db, and the error unwind never releases them.
Free both owned dynamic databases in the unwind, mirroring hsr_dellink(). proxy_node_db is provably empty on every current error exit (only interlink RX feeds it, and the interlink add is the last failable step) and is freed for symmetry. The order is safe:hsr_del_port() unregisters each RX handler with synchronize_net() before hsr_del_nodes() runs, which removes remaining entries with list_del_rcu() and defers their release with call_rcu() for readers already under RCU.
--- net/hsr/hsr_device.c | 2 ++ 1 file changed, 2 insertions(+)
net/hsr/hsr_device.c +2 -0
@@ -820,6 +820,8 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],hsr_del_ports (hsr); err_add_master:hsr_del_self_node (hsr); +hsr_del_nodes (&hsr->node_db); +hsr_del_nodes (&hsr->proxy_node_db);if (unregister)unregister_netdevice (hsr_dev);
Signature · 1 line
2.43.0
Quoted 15 lines · Xin Xie
hsr_dev_finalize()can fail after a lower-device RX handler has already been registered (slave A is added before the failable slave B and interlink adds). RX handlers run in softirq regardless of the master's state, so frames received in that window can learn dynamic nodes intonode_db, and the error unwind never releases them.Free both owned dynamic databases in the unwind, mirroring
hsr_dellink().proxy_node_dbis provably empty on every current error exit (only interlink RX feeds it, and the interlink add is the last failable step) and is freed for symmetry. The order is safe:hsr_del_port()unregisters each RX handler withsynchronize_net()beforehsr_del_nodes()runs, which removes remaining entries withlist_del_rcu()and defers their release withcall_rcu()for readers already under RCU.
Quoted 1 line
Fixes 81ba6afd6e64 ("net/hsr: Switch from dev_add_pack() to netdev_rx_handler_register()")
Should we use this fix tag? The proxy_node_db is added in 5055cccfc2d1 ("net: hsr: Provide RedBox support (HSR-SAN)").
Thanks
Hangbin
Quoted 5 lines · Hangbin Liu
Should we use this fix tag? The
proxy_node_dbis added in5055cccfc2d1("net: hsr: Provide RedBox support (HSR-SAN)").Thanks
Hangbin
Thanks for checking. I believe 81ba6afd6e64 is the right tag.
The demonstrated leak is node_db, and the window that creates it was born in 81ba6afd6e64: that commit moved per-device RX handler registration into hsr_dev_finalize(), ahead of steps that could still fail (the second handler registration, self-node allocation, register_netdevice()), while the failure unwind never released nodes learned through the already-live handler. Before it, reception used the module-global dev_add_pack() handler, which could not reach an instance until register_hsr_master() at the successful end of finalize, so there was nothing to leak.
proxy_node_db cannot hold entries on any current finalize error
exit: it is fed only by interlink-port RX, and the interlink add is the last failable step in finalize. On this path, the second hsr_del_nodes() call is a harmless no-op on an empty list, keeping the unwind symmetric with hsr_dellink().
Using 5055cccfc2d1 would instead keep the fix away from older stable trees, where the node_db leak does exist.
Signature · 1 line
Xin
Quoted 19 lines · Xin Xie
Quoted 5 lines · Hangbin Liu
Should we use this fix tag? The
proxy_node_dbis added in5055cccfc2d1("net: hsr: Provide RedBox support (HSR-SAN)").Thanks
HangbinThanks for checking. I believe
81ba6afd6e64is the right tag.The demonstrated leak is
node_db, and the window that creates it was born in81ba6afd6e64: that commit moved per-device RX handler registration intohsr_dev_finalize(), ahead of steps that could still fail (the second handler registration, self-node allocation,register_netdevice()), while the failure unwind never released nodes learned through the already-live handler. Before it, reception used the module-globaldev_add_pack()handler, which could not reach an instance untilregister_hsr_master()at the successful end of finalize, so there was nothing to leak.
Quoted 8 lines
proxy_node_dbcannot hold entries on any current finalize error
exit: it is fed only by interlink-port RX, and the interlink add is the last failable step in finalize. On this path, the secondhsr_del_nodes()call is a harmless no-op on an empty list, keeping the unwind symmetric withhsr_dellink().Using
5055cccfc2d1would instead keep the fix away from older stable trees, where thenode_dbleak does exist.
Yes, your explanation is reasonable. I just a little concern about the stable back port. Maybe add a tag like
Let's wait and see other's opinion.
Thanks
Hangbin
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 15 lines · On Sat, 8 Aug 2026 13:08:14 +0200 you wrote:
hsr_dev_finalize()can fail after a lower-device RX handler has already been registered (slave A is added before the failable slave B and interlink adds). RX handlers run in softirq regardless of the master's state, so frames received in that window can learn dynamic nodes intonode_db, and the error unwind never releases them.Free both owned dynamic databases in the unwind, mirroring
hsr_dellink().proxy_node_dbis provably empty on every current error exit (only interlink RX feeds it, and the interlink add is the last failable step) and is freed for symmetry. The order is safe:hsr_del_port()unregisters each RX handler withsynchronize_net()beforehsr_del_nodes()runs, which removes remaining entries withlist_del_rcu()and defers their release withcall_rcu()for readers already under RCU.
Quoted 1 line
[...]
Here is the summary with links:
- [net] net: hsr: free learned nodes on device setup failure
https://git.kernel.org/netdev/net/c/7f16289b91eb
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html