From: Jon M. <jon...@er...> - 2019-12-24 13:20:15
|
Acked-by: Jon Maloy <jon...@er...> > -----Original Message----- > From: Tuong Lien <tuo...@de...> > Sent: 24-Dec-19 03:06 > To: tip...@li...; Jon Maloy <jon...@er...>; ma...@do...; > yin...@wi... > Subject: [net] tipc: fix wrong connect() return code > > The current 'tipc_wait_for_connect()' function makes a loop and waits > for the condition 'sk->sk_state != TIPC_CONNECTING' to conclude if the > connecting has done. However, when the condition is met, it always > returns '0' even in the case the connecting was actually failed (e.g. > refused because the server socket has closed...) and the socket state > was set to 'TIPC_DISCONNECTING'. > This results in a wrong return code for the 'connect()' call from user, > making it believe that the connection is established and goes ahead > with more actions e.g. building & sending a message but then finally > gets an unexpected result (e.g. '-EPIPE'). > > This commit fixes the issue by returning the corresponding error code > if any when the wait process is waken up. > > Signed-off-by: Tuong Lien <tuo...@de...> > --- > net/tipc/socket.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/net/tipc/socket.c b/net/tipc/socket.c > index 8b1daf3634b0..2e5faf89ef80 100644 > --- a/net/tipc/socket.c > +++ b/net/tipc/socket.c > @@ -2428,7 +2428,7 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) > { > DEFINE_WAIT_FUNC(wait, woken_wake_function); > struct sock *sk = sock->sk; > - int done; > + int done = 0; > > do { > int err = sock_error(sk); > @@ -2438,12 +2438,14 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) > return -ETIMEDOUT; > if (signal_pending(current)) > return sock_intr_errno(*timeo_p); > + if (done) > + return 0; > > add_wait_queue(sk_sleep(sk), &wait); > done = sk_wait_event(sk, timeo_p, > sk->sk_state != TIPC_CONNECTING, &wait); > remove_wait_queue(sk_sleep(sk), &wait); > - } while (!done); > + } while (1); > return 0; > } > > -- > 2.13.7 |