Skip to content

Commit 7d5424b

Browse files
committed
Merge branch 'net-sysctl-races'
Kuniyuki Iwashima says: ==================== sysctl: Fix data-races around ipv4_net_table (Roun). This series fixes data-races around the first 13 knobs and nexthop_compat_mode in ipv4_net_table. I will post another patch for three early_demux knobs later, so the next round will start from ip_default_ttl. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 22b9c41 + bdf00bf commit 7d5424b

File tree

15 files changed

+43
-28
lines changed

15 files changed

+43
-28
lines changed

Documentation/networking/ip-sysctl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ ip_autobind_reuse - BOOLEAN
11791179
option should only be set by experts.
11801180
Default: 0
11811181

1182-
ip_dynaddr - BOOLEAN
1182+
ip_dynaddr - INTEGER
11831183
If set non-zero, enables support for dynamic addresses.
11841184
If set to a non-zero value larger than 1, a kernel log
11851185
message will be printed when dynamic address rewriting

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ static void chtls_pass_accept_request(struct sock *sk,
13921392
th_ecn = tcph->ece && tcph->cwr;
13931393
if (th_ecn) {
13941394
ect = !INET_ECN_is_not_ect(ip_dsfield);
1395-
ecn_ok = sock_net(sk)->ipv4.sysctl_tcp_ecn;
1395+
ecn_ok = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn);
13961396
if ((!ect && ecn_ok) || tcp_ca_needs_ecn(sk))
13971397
inet_rsk(oreq)->ecn_ok = 1;
13981398
}

include/net/raw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static inline bool raw_sk_bound_dev_eq(struct net *net, int bound_dev_if,
7575
int dif, int sdif)
7676
{
7777
#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
78-
return inet_bound_dev_eq(!!net->ipv4.sysctl_raw_l3mdev_accept,
78+
return inet_bound_dev_eq(READ_ONCE(net->ipv4.sysctl_raw_l3mdev_accept),
7979
bound_dev_if, dif, sdif);
8080
#else
8181
return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);

kernel/sysctl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,13 +1007,13 @@ int proc_dou8vec_minmax(struct ctl_table *table, int write,
10071007

10081008
tmp.maxlen = sizeof(val);
10091009
tmp.data = &val;
1010-
val = *data;
1010+
val = READ_ONCE(*data);
10111011
res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
10121012
do_proc_douintvec_minmax_conv, &param);
10131013
if (res)
10141014
return res;
10151015
if (write)
1016-
*data = val;
1016+
WRITE_ONCE(*data, val);
10171017
return 0;
10181018
}
10191019
EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
@@ -1224,9 +1224,9 @@ static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
12241224

12251225
if (jif > INT_MAX)
12261226
return 1;
1227-
*valp = (int)jif;
1227+
WRITE_ONCE(*valp, (int)jif);
12281228
} else {
1229-
int val = *valp;
1229+
int val = READ_ONCE(*valp);
12301230
unsigned long lval;
12311231
if (val < 0) {
12321232
*negp = true;
@@ -1294,8 +1294,8 @@ int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
12941294
* @ppos: the current position in the file
12951295
*
12961296
* Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1297-
* values from/to the user buffer, treated as an ASCII string.
1298-
* The values read are assumed to be in 1/1000 seconds, and
1297+
* values from/to the user buffer, treated as an ASCII string.
1298+
* The values read are assumed to be in 1/1000 seconds, and
12991299
* are converted into jiffies.
13001300
*
13011301
* Returns 0 on success.

net/ipv4/af_inet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
12461246
if (new_saddr == old_saddr)
12471247
return 0;
12481248

1249-
if (sock_net(sk)->ipv4.sysctl_ip_dynaddr > 1) {
1249+
if (READ_ONCE(sock_net(sk)->ipv4.sysctl_ip_dynaddr) > 1) {
12501250
pr_info("%s(): shifting inet->saddr from %pI4 to %pI4\n",
12511251
__func__, &old_saddr, &new_saddr);
12521252
}
@@ -1301,7 +1301,7 @@ int inet_sk_rebuild_header(struct sock *sk)
13011301
* Other protocols have to map its equivalent state to TCP_SYN_SENT.
13021302
* DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme
13031303
*/
1304-
if (!sock_net(sk)->ipv4.sysctl_ip_dynaddr ||
1304+
if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_ip_dynaddr) ||
13051305
sk->sk_state != TCP_SYN_SENT ||
13061306
(sk->sk_userlocks & SOCK_BINDADDR_LOCK) ||
13071307
(err = inet_sk_reselect_saddr(sk)) != 0)

net/ipv4/fib_semantics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
18111811
goto nla_put_failure;
18121812
if (nexthop_is_blackhole(fi->nh))
18131813
rtm->rtm_type = RTN_BLACKHOLE;
1814-
if (!fi->fib_net->ipv4.sysctl_nexthop_compat_mode)
1814+
if (!READ_ONCE(fi->fib_net->ipv4.sysctl_nexthop_compat_mode))
18151815
goto offload;
18161816
}
18171817

net/ipv4/icmp.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static bool icmpv4_mask_allow(struct net *net, int type, int code)
282282
return true;
283283

284284
/* Limit if icmp type is enabled in ratemask. */
285-
if (!((1 << type) & net->ipv4.sysctl_icmp_ratemask))
285+
if (!((1 << type) & READ_ONCE(net->ipv4.sysctl_icmp_ratemask)))
286286
return true;
287287

288288
return false;
@@ -320,7 +320,8 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt,
320320

321321
vif = l3mdev_master_ifindex(dst->dev);
322322
peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, vif, 1);
323-
rc = inet_peer_xrlim_allow(peer, net->ipv4.sysctl_icmp_ratelimit);
323+
rc = inet_peer_xrlim_allow(peer,
324+
READ_ONCE(net->ipv4.sysctl_icmp_ratelimit));
324325
if (peer)
325326
inet_putpeer(peer);
326327
out:
@@ -693,7 +694,7 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,
693694

694695
rcu_read_lock();
695696
if (rt_is_input_route(rt) &&
696-
net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr)
697+
READ_ONCE(net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr))
697698
dev = dev_get_by_index_rcu(net, inet_iif(skb_in));
698699

699700
if (dev)
@@ -933,7 +934,7 @@ static enum skb_drop_reason icmp_unreach(struct sk_buff *skb)
933934
* get the other vendor to fix their kit.
934935
*/
935936

936-
if (!net->ipv4.sysctl_icmp_ignore_bogus_error_responses &&
937+
if (!READ_ONCE(net->ipv4.sysctl_icmp_ignore_bogus_error_responses) &&
937938
inet_addr_type_dev_table(net, skb->dev, iph->daddr) == RTN_BROADCAST) {
938939
net_warn_ratelimited("%pI4 sent an invalid ICMP type %u, code %u error to a broadcast: %pI4 on %s\n",
939940
&ip_hdr(skb)->saddr,
@@ -993,7 +994,7 @@ static enum skb_drop_reason icmp_echo(struct sk_buff *skb)
993994

994995
net = dev_net(skb_dst(skb)->dev);
995996
/* should there be an ICMP stat for ignored echos? */
996-
if (net->ipv4.sysctl_icmp_echo_ignore_all)
997+
if (READ_ONCE(net->ipv4.sysctl_icmp_echo_ignore_all))
997998
return SKB_NOT_DROPPED_YET;
998999

9991000
icmp_param.data.icmph = *icmp_hdr(skb);
@@ -1028,7 +1029,7 @@ bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)
10281029
u16 ident_len;
10291030
u8 status;
10301031

1031-
if (!net->ipv4.sysctl_icmp_echo_enable_probe)
1032+
if (!READ_ONCE(net->ipv4.sysctl_icmp_echo_enable_probe))
10321033
return false;
10331034

10341035
/* We currently only support probing interfaces on the proxy node
@@ -1249,7 +1250,7 @@ int icmp_rcv(struct sk_buff *skb)
12491250
*/
12501251
if ((icmph->type == ICMP_ECHO ||
12511252
icmph->type == ICMP_TIMESTAMP) &&
1252-
net->ipv4.sysctl_icmp_echo_ignore_broadcasts) {
1253+
READ_ONCE(net->ipv4.sysctl_icmp_echo_ignore_broadcasts)) {
12531254
reason = SKB_DROP_REASON_INVALID_PROTO;
12541255
goto error;
12551256
}

net/ipv4/inet_timewait_sock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
156156
{
157157
struct inet_timewait_sock *tw;
158158

159-
if (refcount_read(&dr->tw_refcount) - 1 >= dr->sysctl_max_tw_buckets)
159+
if (refcount_read(&dr->tw_refcount) - 1 >=
160+
READ_ONCE(dr->sysctl_max_tw_buckets))
160161
return NULL;
161162

162163
tw = kmem_cache_alloc(sk->sk_prot_creator->twsk_prot->twsk_slab,

net/ipv4/nexthop.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh)
18581858
/* __ip6_del_rt does a release, so do a hold here */
18591859
fib6_info_hold(f6i);
18601860
ipv6_stub->ip6_del_rt(net, f6i,
1861-
!net->ipv4.sysctl_nexthop_compat_mode);
1861+
!READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode));
18621862
}
18631863
}
18641864

@@ -2361,7 +2361,8 @@ static int insert_nexthop(struct net *net, struct nexthop *new_nh,
23612361
if (!rc) {
23622362
nh_base_seq_inc(net);
23632363
nexthop_notify(RTM_NEWNEXTHOP, new_nh, &cfg->nlinfo);
2364-
if (replace_notify && net->ipv4.sysctl_nexthop_compat_mode)
2364+
if (replace_notify &&
2365+
READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode))
23652366
nexthop_replace_notify(net, new_nh, &cfg->nlinfo);
23662367
}
23672368

net/ipv4/syncookies.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ bool cookie_ecn_ok(const struct tcp_options_received *tcp_opt,
273273
if (!ecn_ok)
274274
return false;
275275

276-
if (net->ipv4.sysctl_tcp_ecn)
276+
if (READ_ONCE(net->ipv4.sysctl_tcp_ecn))
277277
return true;
278278

279279
return dst_feature(dst, RTAX_FEATURE_ECN);

0 commit comments

Comments
 (0)