All of lore.kernel.org
 help / color / mirror / Atom feed
* [net] tipc: fix wrong connect() return code
@ 2020-01-08  2:19 Tuong Lien
  2020-01-08 23:58 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Tuong Lien @ 2020-01-08  2:19 UTC (permalink / raw)
  To: davem, jmaloy, maloy, ying.xue, netdev; +Cc: tipc-discussion

The current 'tipc_wait_for_connect()' function does a wait-loop for the
condition 'sk->sk_state != TIPC_CONNECTING' to conclude if the socket
connecting has done. However, when the condition is met, it returns '0'
even in the case the connecting is actually failed, the socket state is
set to 'TIPC_DISCONNECTING' (e.g. when the server socket has closed..).
This results in a wrong return code for the 'connect()' call from user,
making it believe that the connection is established and go ahead with
building, sending a message, etc. but finally failed e.g. '-EPIPE'.

This commit fixes the issue by changing the wait condition to the
'tipc_sk_connected(sk)', so the function will return '0' only when the
connection is really established. Otherwise, either the socket 'sk_err'
if any or '-ETIMEDOUT'/'-EINTR' will be returned correspondingly.

Acked-by: Ying Xue <ying.xue@windriver.com>
Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au>
---
 net/tipc/socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 6ebd809ef207..f9b4fb92c0b1 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -2443,8 +2443,8 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
 			return sock_intr_errno(*timeo_p);
 
 		add_wait_queue(sk_sleep(sk), &wait);
-		done = sk_wait_event(sk, timeo_p,
-				     sk->sk_state != TIPC_CONNECTING, &wait);
+		done = sk_wait_event(sk, timeo_p, tipc_sk_connected(sk),
+				     &wait);
 		remove_wait_queue(sk_sleep(sk), &wait);
 	} while (!done);
 	return 0;
-- 
2.13.7


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

* Re: [net] tipc: fix wrong connect() return code
  2020-01-08  2:19 [net] tipc: fix wrong connect() return code Tuong Lien
@ 2020-01-08 23:58 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-01-08 23:58 UTC (permalink / raw)
  To: tuong.t.lien; +Cc: jmaloy, maloy, ying.xue, netdev, tipc-discussion

From: Tuong Lien <tuong.t.lien@dektech.com.au>
Date: Wed,  8 Jan 2020 09:19:00 +0700

> The current 'tipc_wait_for_connect()' function does a wait-loop for the
> condition 'sk->sk_state != TIPC_CONNECTING' to conclude if the socket
> connecting has done. However, when the condition is met, it returns '0'
> even in the case the connecting is actually failed, the socket state is
> set to 'TIPC_DISCONNECTING' (e.g. when the server socket has closed..).
> This results in a wrong return code for the 'connect()' call from user,
> making it believe that the connection is established and go ahead with
> building, sending a message, etc. but finally failed e.g. '-EPIPE'.
> 
> This commit fixes the issue by changing the wait condition to the
> 'tipc_sk_connected(sk)', so the function will return '0' only when the
> connection is really established. Otherwise, either the socket 'sk_err'
> if any or '-ETIMEDOUT'/'-EINTR' will be returned correspondingly.
> 
> Acked-by: Ying Xue <ying.xue@windriver.com>
> Acked-by: Jon Maloy <jon.maloy@ericsson.com>
> Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au>

Applied.

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

end of thread, other threads:[~2020-01-08 23:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08  2:19 [net] tipc: fix wrong connect() return code Tuong Lien
2020-01-08 23:58 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.