Skip to content

Commit 535caac

Browse files
edumazetkuba-moo
authored andcommitted
net: annotate data-races around cleanup_net_task
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: 0734d7c ("net: expedite synchronize_net() for cleanup_net()") Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Jason Xing <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e6854be commit 535caac

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10499,7 +10499,7 @@ static void dev_index_release(struct net *net, int ifindex)
1049910499
static bool from_cleanup_net(void)
1050010500
{
1050110501
#ifdef CONFIG_NET_NS
10502-
return current == cleanup_net_task;
10502+
return current == READ_ONCE(cleanup_net_task);
1050310503
#else
1050410504
return false;
1050510505
#endif

net/core/net_namespace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ static void cleanup_net(struct work_struct *work)
654654
struct net *net, *tmp, *last;
655655
LIST_HEAD(net_exit_list);
656656

657-
cleanup_net_task = current;
657+
WRITE_ONCE(cleanup_net_task, current);
658658

659659
/* Atomically snapshot the list of namespaces to cleanup */
660660
net_kill_list = llist_del_all(&cleanup_list);
@@ -704,7 +704,7 @@ static void cleanup_net(struct work_struct *work)
704704
put_user_ns(net->user_ns);
705705
net_passive_dec(net);
706706
}
707-
cleanup_net_task = NULL;
707+
WRITE_ONCE(cleanup_net_task, NULL);
708708
}
709709

710710
/**

0 commit comments

Comments
 (0)