Skip to content

Commit af67508

Browse files
q2vendavem330
authored andcommitted
net: Fix data-races around sysctl_fb_tunnels_only_for_init_net.
While reading sysctl_fb_tunnels_only_for_init_net, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 79134e6 ("net: do not create fallback tunnels for non-default namespaces") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fa45d48 commit af67508

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

include/linux/netdevice.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,14 @@ extern int sysctl_devconf_inherit_init_net;
640640
*/
641641
static inline bool net_has_fallback_tunnels(const struct net *net)
642642
{
643-
return !IS_ENABLED(CONFIG_SYSCTL) ||
644-
!sysctl_fb_tunnels_only_for_init_net ||
645-
(net == &init_net && sysctl_fb_tunnels_only_for_init_net == 1);
643+
#if IS_ENABLED(CONFIG_SYSCTL)
644+
int fb_tunnels_only_for_init_net = READ_ONCE(sysctl_fb_tunnels_only_for_init_net);
645+
646+
return !fb_tunnels_only_for_init_net ||
647+
(net_eq(net, &init_net) && fb_tunnels_only_for_init_net == 1);
648+
#else
649+
return true;
650+
#endif
646651
}
647652

648653
static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)

0 commit comments

Comments
 (0)