History

ipv4: Fix data-races around sysctl_ip_dynaddr.

While reading sysctl_ip_dynaddr, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.

Kuniyuki Iwashima committed 4 years ago

Commit e49e4af1 parent 12b8d9c2 files · +3 −3Browse files

Unified · Split

2 files
  1. Documentation/networking/ip-sysctl.rst +1 −1
  2. net/ipv4/af_inet.c +2 −2
Documentation/networking/ip-sysctl.rst+1−1
@@ -1179,7 +1179,7 @@ ip_autobind_reuse - BOOLEAN · 1178 unmodified lines
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
net/ipv4/af_inet.c+2−2
@@ -1246,7 +1246,7 @@ static int inet_sk_reselect_saddr(struct sock *sk) · 1245 unmodified lines
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) · 48 unmodified lines
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)