History

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.

Kuniyuki Iwashima committed 4 years ago

Commit af675081 parent fa45d481 file · +8 −3Browse files

Showing the changes to include/linux (1 of 1 file). Show all

Unified · Split

include/linux/netdevice.h+8−3
@@ -640,9 +640,14 @@ extern int sysctl_devconf_inherit_init_net; · 639 unmodified lines
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)