mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: remove release/lock_sock in tcp_splice_read
@ 2024-08-15  8:43 sunyiqi
  2024-08-15 10:00 ` Paolo Abeni
  2024-08-15 10:48 ` Jason Xing
  0 siblings, 2 replies; 6+ messages in thread
From: sunyiqi @ 2024-08-15  8:43 UTC (permalink / raw)
  To: edumazet, davem, dsahern, kuba, pabeni; +Cc: netdev, linux-kernel, sunyiqi

When enters tcp_splice_read, tcp_splice_read will call lock_sock
for sk in order to prevent other threads acquiring sk and release it
before return.

But in while(tss.len) loop, it releases and re-locks sk, give the other
thread a small window to lock the sk.

As a result, release/lock_sock in the while loop in tcp_splice_read may
cause race condition.

Fixes: 9c55e01c0cc8 ("[TCP]: Splice receive support.")
Signed-off-by: sunyiqi <sunyiqixm@gmail.com>
---
 net/ipv4/tcp.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index e03a342c9162..7a2ce0e2e5be 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -856,8 +856,6 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
 
 		if (!tss.len || !timeo)
 			break;
-		release_sock(sk);
-		lock_sock(sk);
 
 		if (sk->sk_err || sk->sk_state == TCP_CLOSE ||
 		    (sk->sk_shutdown & RCV_SHUTDOWN) ||
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-08-15 11:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-15  8:43 [PATCH] net: remove release/lock_sock in tcp_splice_read sunyiqi
2024-08-15 10:00 ` Paolo Abeni
2024-08-15 10:55   ` Jason Xing
2024-08-15 11:22     ` Paolo Abeni
2024-08-15 11:34       ` Jason Xing
2024-08-15 10:48 ` Jason Xing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®