mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: Hu Xinyao <huxinyao@kylinsec.com.cn>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	 Bobby Eshleman <bobbyeshleman@meta.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	 Jason Wang <jasowangio@gmail.com>,
	Eugenio Perez <eperezma@redhat.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	virtualization@lists.linux.dev,  kvm@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close
Date: Wed, 2 Dec 2026 09:29:48 +0100	[thread overview]
Message-ID: <aw_Th2YmVo7pmZsU@sgarzare-redhat> (raw)
In-Reply-To: <4F56BD84AD04C29B+1796182154.53519-reply-vsock-huxinyao@kylinsec.com.cn>

On Wed, Dec 02, 2026 at 12:29:14PM +0900, Hu Xinyao wrote:
>On Tue, Dec 01, 2026 at 06:05:30PM +0100, Stefano Garzarella wrote:
>> >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>> >index 1e762a4..9dade6e 100644
>> >--- a/net/vmw_vsock/virtio_transport_common.c
>> >+++ b/net/vmw_vsock/virtio_transport_common.c
>> >@@ -1411,10 +1411,10 @@ static void virtio_transport_close_timeout(struct work_struct *work)
>> > 		(void)virtio_transport_reset(vsk, NULL);
>> >
>> > 		virtio_transport_do_close(vsk, false);
>> >+	} else {
>> >+		virtio_transport_cancel_close_work(vsk, false);
>> > 	}
>> >
>> >-	vsk->close_work_scheduled = false;
>>
>> Why we are removing this?
>
>Hi Stefano,
>
>With the else branch added, both branches now call
>virtio_transport_cancel_close_work(vsk, false) (the !SOCK_DONE branch
>via virtio_transport_do_close(vsk, false), and the SOCK_DONE branch
>directly).

Okay, I see now.

>
>In virtio_transport_cancel_close_work(vsk, false), !cancel_timeout is
>unconditionally true, so whenever vsk->close_work_scheduled is set it
>already clears vsk->close_work_scheduled = false (along with calling
>virtio_transport_remove_sock(vsk) and sock_put(sk)), and if it was
>already false it remains false. Previously, the trailing assignment only
>had an effect when SOCK_DONE was already set and do_close() was skipped,
>clearing the flag without releasing the socket reference or removing the
>socket.
>
>Sorry for not spelling that out in the commit message (since
>virtio_transport_cancel_close_work() is outside the diff context).
>Alternatively, we could avoid the else branch and just replace
>"vsk->close_work_scheduled = false;" with an unconditional
>"virtio_transport_cancel_close_work(vsk, false);" after the if
>(!sock_flag(sk, SOCK_DONE)) block, which is a no-op if do_close()
>already ran. Happy to send a v2 whichever way you prefer.

Just mention this in the commit message. Without too many words, 
including only the necessary information. The commit message is already 
hard enough to understand...

This is just how I'd have wrote it (just a suggestion, feel free to 
write as you prefer):

   virtio_transport_close() takes a socket reference and schedules
   vsk->close_work, which runs virtio_transport_close_timeout(). If the
   peer resets the connection after the work started running but before
   it takes the socket lock, nobody drops that reference:
   
     CPU0 (close_work)                 CPU1 (rx: OP_RST)
     close_timeout()
                                       lock_sock()
       lock_sock() /* waits */         do_close(vsk, true)
				        SOCK_DONE = 1
				        cancel_delayed_work() == false
				        /* ref not dropped */
				      release_sock()
       SOCK_DONE set, skip do_close()
       close_work_scheduled = false /* ref leaked */
   
   Fix it by letting virtio_transport_close_timeout() complete the cleanup
   when SOCK_DONE is already set. The explicit "close_work_scheduled =
   false" is no longer needed, since virtio_transport_cancel_close_work()
   clears it in both branches.

   ...


Thanks,
Stefano

      reply	other threads:[~2026-12-02  8:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  4:59 Hu Xinyao
2026-11-30 13:23 ` Michal Luczaj
2026-12-01  9:10   ` Hu Xinyao
2026-12-01 17:05 ` Stefano Garzarella
2026-12-02  3:29   ` Hu Xinyao
2026-12-02  8:29     ` Stefano Garzarella [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=aw_Th2YmVo7pmZsU@sgarzare-redhat \
    --to=sgarzare@redhat.com \
    --cc=bobbyeshleman@meta.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=huxinyao@kylinsec.com.cn \
    --cc=jasowangio@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@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

all inboxes | Powered by JetHome®