]>
Commit | Line | Data |
---|---|---|
b6527e40 SL |
1 | From 371d28cecdf9fc70b8a830cac7566c83b38d4526 Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Tue, 23 Aug 2022 10:46:56 -0700 | |
4 | Subject: net: Fix data-races around sysctl_fb_tunnels_only_for_init_net. | |
5 | ||
6 | From: Kuniyuki Iwashima <kuniyu@amazon.com> | |
7 | ||
8 | [ Upstream commit af67508ea6cbf0e4ea27f8120056fa2efce127dd ] | |
9 | ||
10 | While reading sysctl_fb_tunnels_only_for_init_net, it can be changed | |
11 | concurrently. Thus, we need to add READ_ONCE() to its readers. | |
12 | ||
13 | Fixes: 79134e6ce2c9 ("net: do not create fallback tunnels for non-default namespaces") | |
14 | Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> | |
15 | Signed-off-by: David S. Miller <davem@davemloft.net> | |
16 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
17 | --- | |
18 | include/linux/netdevice.h | 11 ++++++++--- | |
19 | 1 file changed, 8 insertions(+), 3 deletions(-) | |
20 | ||
21 | diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h | |
22 | index 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 | -- | |
44 | 2.35.1 | |
45 |