提交 b94d4539 编写于 作者: K Kuniyuki Iwashima 提交者: Zheng Zengkai

ipv4: Fix data-races around sysctl_ip_dynaddr.

stable inclusion
from stable-v5.10.132
commit 2c56958de89b9a2efdb19310e3f11a6b97254d39
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5YS3T

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=2c56958de89b9a2efdb19310e3f11a6b97254d39

--------------------------------

[ Upstream commit e49e4aff ]

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

Fixes: 1da177e4 ("Linux-2.6.12-rc2")
Signed-off-by: NKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 b9af62ef
...@@ -1080,7 +1080,7 @@ ip_autobind_reuse - BOOLEAN ...@@ -1080,7 +1080,7 @@ ip_autobind_reuse - BOOLEAN
option should only be set by experts. option should only be set by experts.
Default: 0 Default: 0
ip_dynaddr - BOOLEAN ip_dynaddr - INTEGER
If set non-zero, enables support for dynamic addresses. If set non-zero, enables support for dynamic addresses.
If set to a non-zero value larger than 1, a kernel log If set to a non-zero value larger than 1, a kernel log
message will be printed when dynamic address rewriting message will be printed when dynamic address rewriting
......
...@@ -1255,7 +1255,7 @@ static int inet_sk_reselect_saddr(struct sock *sk) ...@@ -1255,7 +1255,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
if (new_saddr == old_saddr) if (new_saddr == old_saddr)
return 0; return 0;
if (sock_net(sk)->ipv4.sysctl_ip_dynaddr > 1) { if (READ_ONCE(sock_net(sk)->ipv4.sysctl_ip_dynaddr) > 1) {
pr_info("%s(): shifting inet->saddr from %pI4 to %pI4\n", pr_info("%s(): shifting inet->saddr from %pI4 to %pI4\n",
__func__, &old_saddr, &new_saddr); __func__, &old_saddr, &new_saddr);
} }
...@@ -1310,7 +1310,7 @@ int inet_sk_rebuild_header(struct sock *sk) ...@@ -1310,7 +1310,7 @@ int inet_sk_rebuild_header(struct sock *sk)
* Other protocols have to map its equivalent state to TCP_SYN_SENT. * Other protocols have to map its equivalent state to TCP_SYN_SENT.
* DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme * DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme
*/ */
if (!sock_net(sk)->ipv4.sysctl_ip_dynaddr || if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_ip_dynaddr) ||
sk->sk_state != TCP_SYN_SENT || sk->sk_state != TCP_SYN_SENT ||
(sk->sk_userlocks & SOCK_BINDADDR_LOCK) || (sk->sk_userlocks & SOCK_BINDADDR_LOCK) ||
(err = inet_sk_reselect_saddr(sk)) != 0) (err = inet_sk_reselect_saddr(sk)) != 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册