]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.19.6/net-fix-data-races-around-sysctl_fb_tunnels_only_for.patch
6.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 5.19.6 / net-fix-data-races-around-sysctl_fb_tunnels_only_for.patch
CommitLineData
b6527e40
SL
1From 371d28cecdf9fc70b8a830cac7566c83b38d4526 Mon Sep 17 00:00:00 2001
2From: Sasha Levin <sashal@kernel.org>
3Date: Tue, 23 Aug 2022 10:46:56 -0700
4Subject: net: Fix data-races around sysctl_fb_tunnels_only_for_init_net.
5
6From: Kuniyuki Iwashima <kuniyu@amazon.com>
7
8[ Upstream commit af67508ea6cbf0e4ea27f8120056fa2efce127dd ]
9
10While reading sysctl_fb_tunnels_only_for_init_net, it can be changed
11concurrently. Thus, we need to add READ_ONCE() to its readers.
12
13Fixes: 79134e6ce2c9 ("net: do not create fallback tunnels for non-default namespaces")
14Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
15Signed-off-by: David S. Miller <davem@davemloft.net>
16Signed-off-by: Sasha Levin <sashal@kernel.org>
17---
18 include/linux/netdevice.h | 11 ++++++++---
19 1 file changed, 8 insertions(+), 3 deletions(-)
20
21diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
22index 2563d30736e9a..78dd63a5c7c80 100644
23--- a/include/linux/netdevice.h
24+++ b/include/linux/netdevice.h
25@@ -640,9 +640,14 @@ extern int sysctl_devconf_inherit_init_net;
26 */
27 static inline bool net_has_fallback_tunnels(const struct net *net)
28 {
29- return !IS_ENABLED(CONFIG_SYSCTL) ||
30- !sysctl_fb_tunnels_only_for_init_net ||
31- (net == &init_net && sysctl_fb_tunnels_only_for_init_net == 1);
32+#if IS_ENABLED(CONFIG_SYSCTL)
33+ int fb_tunnels_only_for_init_net = READ_ONCE(sysctl_fb_tunnels_only_for_init_net);
34+
35+ return !fb_tunnels_only_for_init_net ||
36+ (net_eq(net, &init_net) && fb_tunnels_only_for_init_net == 1);
37+#else
38+ return true;
39+#endif
40 }
41
42 static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
43--
442.35.1
45