Skip to content

Commit 3b15b3e

Browse files
committed
Merge branch 'net-sysctl-races-round-4'
Kuniyuki Iwashima says: ==================== sysctl: Fix data-races around ipv4_net_table (Round 4). This series fixes data-races around 17 knobs after fib_multipath_use_neigh in ipv4_net_table. tcp_fack was skipped because it's obsolete and there's no readers. So, round 5 will start with tcp_dsack, 2 rounds left for 27 knobs. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents ef56217 + a11e5b3 commit 3b15b3e

File tree

15 files changed

+45
-42
lines changed

15 files changed

+45
-42
lines changed

drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,8 @@ static struct sock *chtls_recv_sock(struct sock *lsk,
12361236
csk->sndbuf = newsk->sk_sndbuf;
12371237
csk->smac_idx = ((struct port_info *)netdev_priv(ndev))->smt_idx;
12381238
RCV_WSCALE(tp) = select_rcv_wscale(tcp_full_space(newsk),
1239-
sock_net(newsk)->
1240-
ipv4.sysctl_tcp_window_scaling,
1239+
READ_ONCE(sock_net(newsk)->
1240+
ipv4.sysctl_tcp_window_scaling),
12411241
tp->window_clamp);
12421242
neigh_release(n);
12431243
inet_inherit_port(&tcp_hashinfo, lsk, newsk);
@@ -1384,7 +1384,7 @@ static void chtls_pass_accept_request(struct sock *sk,
13841384
#endif
13851385
}
13861386
if (req->tcpopt.wsf <= 14 &&
1387-
sock_net(sk)->ipv4.sysctl_tcp_window_scaling) {
1387+
READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling)) {
13881388
inet_rsk(oreq)->wscale_ok = 1;
13891389
inet_rsk(oreq)->snd_wscale = req->tcpopt.wsf;
13901390
}

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10324,7 +10324,7 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp,
1032410324
unsigned long *fields = config->fields;
1032510325
u32 hash_fields;
1032610326

10327-
switch (net->ipv4.sysctl_fib_multipath_hash_policy) {
10327+
switch (READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_policy)) {
1032810328
case 0:
1032910329
mlxsw_sp_mp4_hash_outer_addr(config);
1033010330
break;
@@ -10342,7 +10342,7 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp,
1034210342
mlxsw_sp_mp_hash_inner_l3(config);
1034310343
break;
1034410344
case 3:
10345-
hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
10345+
hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
1034610346
/* Outer */
1034710347
MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP);
1034810348
MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP);

include/net/ip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ static inline bool sysctl_dev_name_is_allowed(const char *name)
357357

358358
static inline bool inet_port_requires_bind_service(struct net *net, unsigned short port)
359359
{
360-
return port < net->ipv4.sysctl_ip_prot_sock;
360+
return port < READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
361361
}
362362

363363
#else

include/net/tcp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,8 @@ static inline void tcp_slow_start_after_idle_check(struct sock *sk)
14031403
struct tcp_sock *tp = tcp_sk(sk);
14041404
s32 delta;
14051405

1406-
if (!sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle || tp->packets_out ||
1407-
ca_ops->cong_control)
1406+
if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) ||
1407+
tp->packets_out || ca_ops->cong_control)
14081408
return;
14091409
delta = tcp_jiffies32 - tp->lsndtime;
14101410
if (delta > inet_csk(sk)->icsk_rto)

include/net/udp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static inline bool udp_sk_bound_dev_eq(struct net *net, int bound_dev_if,
238238
int dif, int sdif)
239239
{
240240
#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
241-
return inet_bound_dev_eq(!!net->ipv4.sysctl_udp_l3mdev_accept,
241+
return inet_bound_dev_eq(!!READ_ONCE(net->ipv4.sysctl_udp_l3mdev_accept),
242242
bound_dev_if, dif, sdif);
243243
#else
244244
return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);

net/core/secure_seq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ u32 secure_tcpv6_ts_off(const struct net *net,
6464
.daddr = *(struct in6_addr *)daddr,
6565
};
6666

67-
if (net->ipv4.sysctl_tcp_timestamps != 1)
67+
if (READ_ONCE(net->ipv4.sysctl_tcp_timestamps) != 1)
6868
return 0;
6969

7070
ts_secret_init();
@@ -120,7 +120,7 @@ EXPORT_SYMBOL(secure_ipv6_port_ephemeral);
120120
#ifdef CONFIG_INET
121121
u32 secure_tcp_ts_off(const struct net *net, __be32 saddr, __be32 daddr)
122122
{
123-
if (net->ipv4.sysctl_tcp_timestamps != 1)
123+
if (READ_ONCE(net->ipv4.sysctl_tcp_timestamps) != 1)
124124
return 0;
125125

126126
ts_secret_init();

net/ipv4/fib_semantics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,7 @@ void fib_select_multipath(struct fib_result *res, int hash)
22162216
}
22172217

22182218
change_nexthops(fi) {
2219-
if (net->ipv4.sysctl_fib_multipath_use_neigh) {
2219+
if (READ_ONCE(net->ipv4.sysctl_fib_multipath_use_neigh)) {
22202220
if (!fib_good_nh(nexthop_nh))
22212221
continue;
22222222
if (!first) {

net/ipv4/route.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ static u32 fib_multipath_custom_hash_outer(const struct net *net,
19291929
const struct sk_buff *skb,
19301930
bool *p_has_inner)
19311931
{
1932-
u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
1932+
u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
19331933
struct flow_keys keys, hash_keys;
19341934

19351935
if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK))
@@ -1958,7 +1958,7 @@ static u32 fib_multipath_custom_hash_inner(const struct net *net,
19581958
const struct sk_buff *skb,
19591959
bool has_inner)
19601960
{
1961-
u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
1961+
u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
19621962
struct flow_keys keys, hash_keys;
19631963

19641964
/* We assume the packet carries an encapsulation, but if none was
@@ -2018,7 +2018,7 @@ static u32 fib_multipath_custom_hash_skb(const struct net *net,
20182018
static u32 fib_multipath_custom_hash_fl4(const struct net *net,
20192019
const struct flowi4 *fl4)
20202020
{
2021-
u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;
2021+
u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
20222022
struct flow_keys hash_keys;
20232023

20242024
if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK))
@@ -2048,7 +2048,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
20482048
struct flow_keys hash_keys;
20492049
u32 mhash = 0;
20502050

2051-
switch (net->ipv4.sysctl_fib_multipath_hash_policy) {
2051+
switch (READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_policy)) {
20522052
case 0:
20532053
memset(&hash_keys, 0, sizeof(hash_keys));
20542054
hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;

net/ipv4/syncookies.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ bool cookie_timestamp_decode(const struct net *net,
247247
return true;
248248
}
249249

250-
if (!net->ipv4.sysctl_tcp_timestamps)
250+
if (!READ_ONCE(net->ipv4.sysctl_tcp_timestamps))
251251
return false;
252252

253253
tcp_opt->sack_ok = (options & TS_OPT_SACK) ? TCP_SACK_SEEN : 0;
254254

255-
if (tcp_opt->sack_ok && !net->ipv4.sysctl_tcp_sack)
255+
if (tcp_opt->sack_ok && !READ_ONCE(net->ipv4.sysctl_tcp_sack))
256256
return false;
257257

258258
if ((options & TS_OPT_WSCALE_MASK) == TS_OPT_WSCALE_MASK)
@@ -261,7 +261,7 @@ bool cookie_timestamp_decode(const struct net *net,
261261
tcp_opt->wscale_ok = 1;
262262
tcp_opt->snd_wscale = options & TS_OPT_WSCALE_MASK;
263263

264-
return net->ipv4.sysctl_tcp_window_scaling != 0;
264+
return READ_ONCE(net->ipv4.sysctl_tcp_window_scaling) != 0;
265265
}
266266
EXPORT_SYMBOL(cookie_timestamp_decode);
267267

net/ipv4/sysctl_net_ipv4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
8484
* port limit.
8585
*/
8686
if ((range[1] < range[0]) ||
87-
(range[0] < net->ipv4.sysctl_ip_prot_sock))
87+
(range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
8888
ret = -EINVAL;
8989
else
9090
set_local_port_range(net, range);
@@ -110,7 +110,7 @@ static int ipv4_privileged_ports(struct ctl_table *table, int write,
110110
.extra2 = &ip_privileged_port_max,
111111
};
112112

113-
pports = net->ipv4.sysctl_ip_prot_sock;
113+
pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
114114

115115
ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
116116

@@ -122,7 +122,7 @@ static int ipv4_privileged_ports(struct ctl_table *table, int write,
122122
if (range[0] < pports)
123123
ret = -EINVAL;
124124
else
125-
net->ipv4.sysctl_ip_prot_sock = pports;
125+
WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
126126
}
127127

128128
return ret;

0 commit comments

Comments
 (0)