All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hyunwoo Kim <imv4bel@gmail.com>
To: Michal Luczaj <mhal@rbox.co>
Cc: sgarzare@redhat.com, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	leonardi@redhat.com, bobbyeshleman@meta.com, stefanha@redhat.com,
	mst@redhat.com, virtualization@lists.linux.dev,
	netdev@vger.kernel.org, imv4bel@gmail.com
Subject: Re: [PATCH net] vsock: do not reset a socket in connect() once it has connected
Date: Fri, 14 Aug 2026 10:45:11 +0900	[thread overview]
Message-ID: <an5zJ9Uf94_L9TyB@v4bel> (raw)
In-Reply-To: <218226a4-38e6-4a16-a660-6c1bb92f9f96@rbox.co>

On Thu, Aug 13, 2026 at 11:42:17AM +0200, Michal Luczaj wrote:
> On 8/12/26 22:13, Hyunwoo Kim wrote:
> > commit 002541ef650b ("vsock: Ignore signal/timeout on connect() if
> > already established") stopped connect() from resetting an established
> > socket. The check only looks at whether sk_state is TCP_ESTABLISHED at
> > that moment, and the state can change while connect() sleeps.
> 
> I guess this makes my fix incomplete. "Fixes: 002541ef650b"?

It is incomplete, yes. But this has been triggerable since d021c344051a, so
I'd keep Fixes: d021c344051a.

> 
> > A peer RST moves the socket to TCP_CLOSING, and it is not removed from
> > vsock_connected_table on that path. connect() then wakes up, fails the
> > check, and resets a socket that had actually connected to TCP_CLOSE and
> > SS_UNCONNECTED.
> 
> Thanks for the details. Do I get it right: connect() misses the fact that
> socket might have already transitioned TCP_ESTABLISHED -> TCP_CLOSING
> during schedule_timeout()?

Yes, that's it.

> 
> How about:
> 
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 622dbd046799..39c42ef016c3 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -1807,15 +1807,18 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
>  		timeout = schedule_timeout(timeout);
>  		lock_sock(sk);
>  
> -		/* Connection established. Whatever happens to socket once we
> +		/* Connection (has been) established. Whatever happens to socket once we
>  		 * release it, that's not connect()'s concern. No need to go
>  		 * into signal and timeout handling. Call it a day.
>  		 *
>  		 * Note that allowing to "reset" an already established socket
>  		 * here is racy and insecure.
>  		 */
> -		if (sk->sk_state == TCP_ESTABLISHED)
> -			break;
> +		if (sk->sk_state == TCP_ESTABLISHED ||
> +		    sk->sk_state == TCP_CLOSING) {
> +			err = -sk->sk_err;
> +			goto out_wait;
> +		}
>  
>  		/* If connection was _not_ established and a signal/timeout came
>  		 * to be, we want the socket's state reset. User space may want
> 
> ?

Yes, I like it better than mine. I confirmed it fixes the issue.

If you don't mind, would you take the patch from here?


Best regards,
Hyunwoo Kim

      reply	other threads:[~2026-08-14  1:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 20:13 [PATCH net] vsock: do not reset a socket in connect() once it has connected Hyunwoo Kim
2026-08-13  9:42 ` Michal Luczaj
2026-08-14  1:45   ` Hyunwoo Kim [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=an5zJ9Uf94_L9TyB@v4bel \
    --to=imv4bel@gmail.com \
    --cc=bobbyeshleman@meta.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=leonardi@redhat.com \
    --cc=mhal@rbox.co \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.