Skip to content

Commit

Permalink
net: netconsole: Disable target before netpoll cleanup
Browse files Browse the repository at this point in the history
commit 97d9fba9a812cada5484667a46e14a4c976ca330 upstream.

Currently, netconsole cleans up the netpoll structure before disabling
the target. This approach can lead to race conditions, as message
senders (write_ext_msg() and write_msg()) check if the target is
enabled before using netpoll. The sender can validate that the target is
enabled, but, the netpoll might be de-allocated already, causing
undesired behaviours.

This patch reverses the order of operations:
1. Disable the target
2. Clean up the netpoll structure

This change eliminates the potential race condition, ensuring that
no messages are sent through a partially cleaned-up netpoll structure.

Fixes: 2382b15 ("netconsole: take care of NETDEV_UNREGISTER event")
Cc: [email protected]
Signed-off-by: Breno Leitao <[email protected]>
Reviewed-by: Eric Dumazet <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
(cherry picked from commit 608a07143563a2a0d1edd57b2f4e95b0199fb497)
Signed-off-by: Vegard Nossum <[email protected]>
  • Loading branch information
leitao authored and whyakari committed Oct 15, 2024
1 parent c9e68b9 commit fa956f0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/net/netconsole.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,14 @@ static int netconsole_netdev_event(struct notifier_block *this,
/* rtnl_lock already held
* we might sleep in __netpoll_cleanup()
*/
nt->enabled = false;
spin_unlock_irqrestore(&target_list_lock, flags);

__netpoll_cleanup(&nt->np);

spin_lock_irqsave(&target_list_lock, flags);
dev_put(nt->np.dev);
nt->np.dev = NULL;
nt->enabled = false;
stopped = true;
netconsole_target_put(nt);
goto restart;
Expand Down

0 comments on commit fa956f0

Please sign in to comment.