Linux virtualization list
 help / color / mirror / Atom feed
From: Michal Luczaj <mhal@rbox.co>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: Hyunwoo Kim <imv4bel@gmail.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
Subject: Re: [PATCH net] vsock: do not reset a socket in connect() once it has connected
Date: Thu, 10 Sep 2026 00:06:15 +0200	[thread overview]
Message-ID: <7cd32cc3-8acd-4048-9008-b5795e43d871@rbox.co> (raw)
In-Reply-To: <aoVnp0w9jlyFDPj7@sgarzare-redhat>

On 8/19/26 10:54, Stefano Garzarella wrote:
>>>> 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.
>>
>> Great, thanks.
>>
>>> If you don't mind, would you take the patch from here?
>>
>> Sure, no problem.
>>
>> Stefano, does this look good to you?
> 
> Yep, thanks for helping here!
> 
> My only doubt is if it makes sense to leave the `break` there, and add a 
> similar check before resetting the socket, I mean something like this:
> 
> 	err = sock_error(sk);
> 	if (err && sk->sk_state != TCP_ESTABLISHED &&
> 		   sk->sk_state != TCP_CLOSING)) {
> 		sk->sk_state = TCP_CLOSE;
> 		sock->state = SS_UNCONNECTED;
> 	}
> 
> Just to be a bit more defensive, but I don't have a strong opinion, your 
> version is also fine.
> 
>> And should any sk_err be consumed
>> here, too? (`err = sock_error(sk)` instead of `err = -sk->sk_err`)
> 
> I'd stay with sock_error() to consume the error if it makes sense also 
> for you.

Sure, one note: perhaps it's better to always return 0 on
TCP_ESTABLISHED/TCP_CLOSING? From connect()'s PoV these two states mean "we
did good, we connected to something for some time". Currently, even if the
connection was established, virtio_transport_recv_connected()'s
VIRTIO_VSOCK_OP_RW error handling may set sk_err = ENOBUFS, and connect()
would return that. Even though connect() itself was a success.

Anyway, here's a fix for the uaf:
https://lore.kernel.org/netdev/20260909-vsock-connect-reset-closing-v1-1-50298b9ccfbf@rbox.co/
It's incomplete, but I'm not sure how to follow up. Please see the
below---comment.

thanks,
Michal


      parent reply	other threads:[~2026-09-09 22:06 UTC|newest]

Thread overview: 8+ 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
2026-08-16 22:29     ` Michal Luczaj
2026-08-19  8:54       ` Stefano Garzarella
2026-09-07 18:35         ` Hyunwoo Kim
2026-09-08 15:17           ` Michal Luczaj
2026-09-09 22:06         ` Michal Luczaj [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=7cd32cc3-8acd-4048-9008-b5795e43d871@rbox.co \
    --to=mhal@rbox.co \
    --cc=bobbyeshleman@meta.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=imv4bel@gmail.com \
    --cc=kuba@kernel.org \
    --cc=leonardi@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox