Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrey Drobyshev" <andrey.drobyshev@virtuozzo.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 4/4] vhost/vsock: add VHOST_RESET_OWNER ioctl
Date: Tue, 23 Jun 2026 17:58:55 +0000	[thread overview]
Message-ID: <20260623175855.7A6231F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260622175808.508084-5-andrey.drobyshev@virtuozzo.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing backend check in `vhost_transport_cancel_pkt()` leads to a Use-After-Free of `vq->worker` and/or a permanently stuck `VHOST_WORK_QUEUED` flag during `VHOST_RESET_OWNER`.
--

commit 1246364b7bca9df01b3f2315a384db215bb18763
Author: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

vhost/vsock: add VHOST_RESET_OWNER ioctl

This patch adds the VHOST_RESET_OWNER ioctl for QEMU CPR migration of a
guest with a vhost-vsock device. It fences the send path around the teardown
by adding a backend check in vhost_transport_send_pkt() to prevent using
the worker after it is freed.

> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index 81d4f72097191..7d0146cd38d26 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c

[ ... ]

> @@ -903,6 +910,36 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)
>  	return -EFAULT;
>  }
>  
> +static int vhost_vsock_reset_owner(struct vhost_vsock *vsock)
> +{
> +	struct vhost_iotlb *umem;
> +	long err;
> +
> +	mutex_lock(&vsock->dev.mutex);
> +	err = vhost_dev_check_owner(&vsock->dev);
> +	if (err)
> +		goto done;
> +	umem = vhost_dev_reset_owner_prepare();
> +	if (!umem) {
> +		err = -ENOMEM;
> +		goto done;
> +	}
> +	vhost_vsock_drop_backends(vsock);
> +
> +	/* Let in-flight send_pkt() callers stop touching the worker before the
> +	 * flush + free below. Pairs with the backend check in
> +	 * vhost_transport_send_pkt().
> +	 */
> +	synchronize_rcu();

[Severity: High]
Does vhost_transport_cancel_pkt() also need a backend check similar to the
one added in vhost_transport_send_pkt()?

Since VHOST_RESET_OWNER leaves the vsock hashed so connections survive,
a concurrent socket close can still look up the vsock and call
vhost_transport_cancel_pkt().

If this happens after the synchronize_rcu() call finishes,
vhost_transport_cancel_pkt() can conditionally call
vhost_poll_queue(&tx_vq->poll). This unconditionally queues work without
checking if the backend is alive, which dereferences vq->worker.

Because vhost_workers_free() frees the worker synchronously via kfree()
during teardown, could this lead to a use-after-free of the worker
or a permanently stuck VHOST_WORK_QUEUED flag?

> +
> +	vhost_vsock_flush(vsock);
> +	vhost_dev_stop(&vsock->dev);
> +	vhost_dev_reset_owner(&vsock->dev, umem);
> +done:
> +	mutex_unlock(&vsock->dev.mutex);
> +	return err;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260622175808.508084-1-andrey.drobyshev@virtuozzo.com?part=4

      reply	other threads:[~2026-06-23 17:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22 17:58 [PATCH v2 0/4] vhost/vsock: add support for VHOST_RESET_OWNER and CPR migration Andrey Drobyshev
2026-06-22 17:58 ` [PATCH v2 1/4] vhost/vsock: split out vhost_vsock_drop_backends helper Andrey Drobyshev
2026-06-22 17:58 ` [PATCH v2 2/4] vhost/vsock: suppress EHOSTUNREACH fast-fail during CPR pause Andrey Drobyshev
2026-06-23 17:58   ` sashiko-bot
2026-06-22 17:58 ` [PATCH v2 3/4] vhost/vsock: re-scan TX virtqueue on device start Andrey Drobyshev
2026-06-22 17:58 ` [PATCH v2 4/4] vhost/vsock: add VHOST_RESET_OWNER ioctl Andrey Drobyshev
2026-06-23 17:58   ` sashiko-bot [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=20260623175855.7A6231F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@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