net: annotate data-races around cleanup_net_task
authorEric Dumazet <edumazet@google.com>
Wed, 4 Jun 2025 09:39:28 +0000 (09:39 +0000)
committerJakub Kicinski <kuba@kernel.org>
Thu, 5 Jun 2025 15:02:26 +0000 (08:02 -0700)
from_cleanup_net() reads cleanup_net_task locklessly.

Add READ_ONCE()/WRITE_ONCE() annotations to avoid
a potential KCSAN warning, even if the race is harmless.

Fixes: 0734d7c3d93c ("net: expedite synchronize_net() for cleanup_net()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Link: https://patch.msgid.link/20250604093928.1323333-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/dev.c
net/core/net_namespace.c

index a388f45..be97c44 100644 (file)
@@ -10499,7 +10499,7 @@ static void dev_index_release(struct net *net, int ifindex)
 static bool from_cleanup_net(void)
 {
 #ifdef CONFIG_NET_NS
-       return current == cleanup_net_task;
+       return current == READ_ONCE(cleanup_net_task);
 #else
        return false;
 #endif
index 42ee7fc..ae54f26 100644 (file)
@@ -654,7 +654,7 @@ static void cleanup_net(struct work_struct *work)
        struct net *net, *tmp, *last;
        LIST_HEAD(net_exit_list);
 
-       cleanup_net_task = current;
+       WRITE_ONCE(cleanup_net_task, current);
 
        /* Atomically snapshot the list of namespaces to cleanup */
        net_kill_list = llist_del_all(&cleanup_list);
@@ -704,7 +704,7 @@ static void cleanup_net(struct work_struct *work)
                put_user_ns(net->user_ns);
                net_passive_dec(net);
        }
-       cleanup_net_task = NULL;
+       WRITE_ONCE(cleanup_net_task, NULL);
 }
 
 /**