lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_F35C58B90E47D014455212BC7110EDBB2106@qq.com>
Date: Tue, 23 Jan 2024 04:24:46 +0800
From: linke li <lilinke99@...com>
To: netdev@...r.kernel.org
Cc: linke li <lilinke99@...com>
Subject: [PATCH] net: use READ_ONCE() to read in concurrent environment

In function sk_stream_wait_memory(), reads of sk->sk_err and sk->sk_shutdown
is protected using READ_ONCE() in line 145, 146.
145: 		ret = sk_wait_event(sk, &current_timeo, READ_ONCE(sk->sk_err) ||
146: 				    (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN) ||

But reads in line 133 are not protected. This may cause unexpected error
when other threads change sk->sk_err and sk->sk_shutdown. Function
sk_stream_wait_connect() has same problem.

There is patch similar to this. https://github.com/torvalds/linux/commit/c1c0ce31b2420d5c173228a2132a492ede03d81f
This patch find two read of same variable while one is protected, another
is not. And READ_ONCE() is added to protect.

Signed-off-by: linke li <lilinke99@...com>
---
 net/core/stream.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/core/stream.c b/net/core/stream.c
index b16dfa568a2d..7e67a2bf4480 100644
--- a/net/core/stream.c
+++ b/net/core/stream.c
@@ -63,7 +63,7 @@ int sk_stream_wait_connect(struct sock *sk, long *timeo_p)
 		int err = sock_error(sk);
 		if (err)
 			return err;
-		if ((1 << sk->sk_state) & ~(TCPF_SYN_SENT | TCPF_SYN_RECV))
+		if ((1 << READ_ONCE(sk->sk_state)) & ~(TCPF_SYN_SENT | TCPF_SYN_RECV))
 			return -EPIPE;
 		if (!*timeo_p)
 			return -EAGAIN;
@@ -130,7 +130,7 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p)
 	while (1) {
 		sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
 
-		if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
+		if (READ_ONCE(sk->sk_err) || (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN))
 			goto do_error;
 		if (!*timeo_p)
 			goto do_eagain;
-- 
2.39.3 (Apple Git-145)


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ