Skip to content

Commit a45835a

Browse files
abattersbykuba-moo
authored andcommitted
bonding: fix oops during rmmod
"rmmod bonding" causes an oops ever since commit cc317ea ("bonding: remove redundant NULL check in debugfs function"). Here are the relevant functions being called: bonding_exit() bond_destroy_debugfs() debugfs_remove_recursive(bonding_debug_root); bonding_debug_root = NULL; <--------- SET TO NULL HERE bond_netlink_fini() rtnl_link_unregister() __rtnl_link_unregister() unregister_netdevice_many_notify() bond_uninit() bond_debug_unregister() (commit removed check for bonding_debug_root == NULL) debugfs_remove() simple_recursive_removal() down_write() -> OOPS However, reverting the bad commit does not solve the problem completely because the original code contains a race that could cause the same oops, although it was much less likely to be triggered unintentionally: CPU1 rmmod bonding bonding_exit() bond_destroy_debugfs() debugfs_remove_recursive(bonding_debug_root); CPU2 echo -bond0 > /sys/class/net/bonding_masters bond_uninit() bond_debug_unregister() if (!bonding_debug_root) CPU1 bonding_debug_root = NULL; So do NOT revert the bad commit (since the removed checks were racy anyway), and instead change the order of actions taken during module removal. The same oops can also happen if there is an error during module init, so apply the same fix there. Fixes: cc317ea ("bonding: remove redundant NULL check in debugfs function") Cc: [email protected] Signed-off-by: Tony Battersby <[email protected]> Reviewed-by: Simon Horman <[email protected]> Acked-by: Jay Vosburgh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent bb48727 commit a45835a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6477,16 +6477,16 @@ static int __init bonding_init(void)
64776477
if (res)
64786478
goto out;
64796479

6480+
bond_create_debugfs();
6481+
64806482
res = register_pernet_subsys(&bond_net_ops);
64816483
if (res)
6482-
goto out;
6484+
goto err_net_ops;
64836485

64846486
res = bond_netlink_init();
64856487
if (res)
64866488
goto err_link;
64876489

6488-
bond_create_debugfs();
6489-
64906490
for (i = 0; i < max_bonds; i++) {
64916491
res = bond_create(&init_net, NULL);
64926492
if (res)
@@ -6501,10 +6501,11 @@ static int __init bonding_init(void)
65016501
out:
65026502
return res;
65036503
err:
6504-
bond_destroy_debugfs();
65056504
bond_netlink_fini();
65066505
err_link:
65076506
unregister_pernet_subsys(&bond_net_ops);
6507+
err_net_ops:
6508+
bond_destroy_debugfs();
65086509
goto out;
65096510

65106511
}
@@ -6513,11 +6514,11 @@ static void __exit bonding_exit(void)
65136514
{
65146515
unregister_netdevice_notifier(&bond_netdev_notifier);
65156516

6516-
bond_destroy_debugfs();
6517-
65186517
bond_netlink_fini();
65196518
unregister_pernet_subsys(&bond_net_ops);
65206519

6520+
bond_destroy_debugfs();
6521+
65216522
#ifdef CONFIG_NET_POLL_CONTROLLER
65226523
/* Make sure we don't have an imbalance on our netpoll blocking */
65236524
WARN_ON(atomic_read(&netpoll_block_tx));

0 commit comments

Comments
 (0)