]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
netconsole: take target_cleanup_list_lock in drop_netconsole_target()
authorBreno Leitao <leitao@debian.org>
Thu, 4 Jun 2026 16:10:12 +0000 (09:10 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 9 Jun 2026 10:42:21 +0000 (12:42 +0200)
drop_netconsole_target() unlinks the target while only holding
target_list_lock. However, when the underlying interface has been
unregistered, netconsole_netdev_event() moves the target from
target_list to target_cleanup_list, and netconsole_process_cleanups_core()
walks that list under target_cleanup_list_lock only.

If a user removes the configfs target at the same time the cleanup
worker is iterating target_cleanup_list, list_del() can corrupt the list
because the two paths take disjoint locks while operating on the same
list node.

Acquire target_cleanup_list_lock around the list_del() so the unlink is
serialised against netconsole_process_cleanups_core() regardless of
which list the target currently belongs to. The state transition that
downgrades STATE_DEACTIVATED to STATE_DISABLED is left intact and is
performed under the same combined locking, preserving the existing
ordering with resume_target().

Signed-off-by: Breno Leitao <leitao@debian.org>
Link: https://patch.msgid.link/20260604-netcons_fix_before_move-v3-3-ab055b3a6aa5@debian.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/netconsole.c

index 58250e648f8ba2754099f5288ff871e4c3d620d0..d8be2fef3826b9a23f154d3ebd03b5e70f029024 100644 (file)
@@ -1452,6 +1452,7 @@ static void drop_netconsole_target(struct config_group *group,
 
        dynamic_netconsole_mutex_lock();
 
+       mutex_lock(&target_cleanup_list_lock);
        spin_lock_irqsave(&target_list_lock, flags);
        /* Disable deactivated target to prevent races between resume attempt
         * and target removal.
@@ -1460,6 +1461,7 @@ static void drop_netconsole_target(struct config_group *group,
                nt->state = STATE_DISABLED;
        list_del(&nt->list);
        spin_unlock_irqrestore(&target_list_lock, flags);
+       mutex_unlock(&target_cleanup_list_lock);
 
        dynamic_netconsole_mutex_unlock();