Skip to contentSkip to conversation

tcp: tcp_data_ready() must look at SOCK_DONE

PATCH Applied Eric Dumazet 3 participants 3 messages Feb 13, 2021 – Feb 15, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: tcp_data_ready() must look at SOCK_DONE

From: Eric Dumazet <[email protected]>

My prior cleanup missed that tcp_data_ready() has to look at SOCK_DONE. Otherwise, an application using SO_RCVLOWAT will not get EPOLLIN event if a FIN is received in the middle of expected payload.

The reason SOCK_DONE is not examined in tcp_epollin_ready() is that tcp_poll() catches the FIN because tcp_fin() is also setting RCV_SHUTDOWN into sk->sk_shutdown

Fixes 05dc72aba364 ("tcp: factorize logic into tcp_epollin_ready()")
Cc Arjun Roy <[email protected]>
---
 net/ipv4/tcp_input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_input.c +1 -1
index e32a7056cb7640c67ef2d6a4d9484684d2602fcd..69a545db80d2ead47ffcf2f3819a6d066e95f35d 100644
@@ -4924,7 +4924,7 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)
 
 void tcp_data_ready(struct sock *sk)
 {
-	if (tcp_epollin_ready(sk, sk->sk_rcvlowat))
+	if (tcp_epollin_ready(sk, sk->sk_rcvlowat) || sock_flag(sk, SOCK_DONE))
 		sk->sk_data_ready(sk);
 }
 
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

My prior cleanup missed that tcp_data_ready() has to look at SOCK_DONE. Otherwise, an application using SO_RCVLOWAT will not get EPOLLIN event if a FIN is received in the middle of expected payload.

The reason SOCK_DONE is not examined in tcp_epollin_ready() is that tcp_poll() catches the FIN because tcp_fin() is also setting RCV_SHUTDOWN into sk->sk_shutdown

Quoted 5 lines
Fixes 05dc72aba364 ("tcp: factorize logic into tcp_epollin_ready()")
Cc Arjun Roy <[email protected]>

---

Thanks Eric for the fix!

Quoted 19 lines
 net/ipv4/tcp_input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_input.c +1 -2
index e32a7056cb7640c67ef2d6a4d9484684d2602fcd..69a545db80d2ead47ffcf2f3819a6d066e95f35d 100644
@@ -4924,7 +4924,7 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)
 
 void tcp_data_ready(struct sock *sk)
 {
-       if (tcp_epollin_ready(sk, sk->sk_rcvlowat))
+       if (tcp_epollin_ready(sk, sk->sk_rcvlowat) || sock_flag(sk, SOCK_DONE))
                sk->sk_data_ready(sk);
 }
 
--

2.30.0.478.g8a0d178c01-goog

#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 11 lines · On Sat, 13 Feb 2021 06:26:34 -0800 you wrote:

From: Eric Dumazet <[email protected]>

My prior cleanup missed that tcp_data_ready() has to look at SOCK_DONE. Otherwise, an application using SO_RCVLOWAT will not get EPOLLIN event if a FIN is received in the middle of expected payload.

The reason SOCK_DONE is not examined in tcp_epollin_ready() is that tcp_poll() catches the FIN because tcp_fin() is also setting RCV_SHUTDOWN into sk->sk_shutdown

[...]

Here is the summary with links:
- [net-next] tcp: tcp_data_ready() must look at SOCK_DONE

    https://git.kernel.org/netdev/net-next/c/39354eb29f59

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html