From: Dongli Zhang <dongli.zhang@oracle.com>
To: virtualization@lists.linux.dev, netdev@vger.kernel.org,
kvm@vger.kernel.org
Cc: mst@redhat.com, jasowang@redhat.com, eperezma@redhat.com,
michael.christie@oracle.com, pbonzini@redhat.com,
stefanha@redhat.com, joao.m.martins@oracle.com,
joe.jin@oracle.com, si-wei.liu@oracle.com,
linux-kernel@vger.kernel.org
Subject: [PATCH 8/9] vhost-scsi: protect vq->log_used with vq->mutex
Date: Fri, 7 Feb 2025 10:41:52 -0800 [thread overview]
Message-ID: <20250207184212.20831-9-dongli.zhang@oracle.com> (raw)
In-Reply-To: <20250207184212.20831-1-dongli.zhang@oracle.com>
The vhost-scsi completion path may access vq->log_base when vq->log_used is
already set to false.
vhost-thread QEMU-thread
vhost_scsi_complete_cmd_work()
-> vhost_add_used()
-> vhost_add_used_n()
if (unlikely(vq->log_used))
QEMU disables vq->log_used
via VHOST_SET_VRING_ADDR.
mutex_lock(&vq->mutex);
vq->log_used = false now!
mutex_unlock(&vq->mutex);
QEMU gfree(vq->log_base)
log_used()
-> log_write(vq->log_base)
Assuming the VMM is QEMU. The vq->log_base is from QEMU userpace and can be
reclaimed via gfree(). As a result, this causes invalid memory writes to
QEMU userspace.
The control queue path has the same issue.
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
drivers/vhost/scsi.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 40268b88f470..3b87d698adaf 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -645,7 +645,9 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
if (likely(ret == sizeof(v_rsp))) {
signal = true;
+ mutex_lock(&cmd->tvc_vq->mutex);
vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0);
+ mutex_unlock(&cmd->tvc_vq->mutex);
} else
pr_err("Faulted on virtio_scsi_cmd_resp\n");
@@ -1371,8 +1373,10 @@ static void vhost_scsi_tmf_resp_work(struct vhost_work *work)
else
resp_code = VIRTIO_SCSI_S_FUNCTION_REJECTED;
+ mutex_lock(&tmf->svq->vq.mutex);
vhost_scsi_send_tmf_resp(tmf->vhost, &tmf->svq->vq, tmf->in_iovs,
tmf->vq_desc, &tmf->resp_iov, resp_code);
+ mutex_unlock(&tmf->svq->vq.mutex);
if (unlikely(tmf->tmf_log_num)) {
mutex_lock(&tmf->svq->vq.mutex);
--
2.39.3
next prev parent reply other threads:[~2025-02-07 18:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 18:41 [PATCH 0/9] vhost-scsi: log write descriptors for live migration (and two bugfix) Dongli Zhang
2025-02-07 18:41 ` [PATCH 1/9] vhost: modify vhost_log_write() for broader users Dongli Zhang
2025-02-07 18:41 ` [PATCH 2/9] vhost-scsi: adjust vhost_scsi_get_desc() to log vring descriptors Dongli Zhang
2025-02-07 18:41 ` [PATCH 3/9] vhost-scsi: cache log buffer in I/O queue vhost_scsi_cmd Dongli Zhang
2025-02-10 20:11 ` Mike Christie
2025-02-07 18:41 ` [PATCH 4/9] vhost-scsi: log I/O queue write descriptors Dongli Zhang
2025-02-07 18:41 ` [PATCH 5/9] vhost-scsi: log control " Dongli Zhang
2025-02-12 1:08 ` Mike Christie
2025-02-07 18:41 ` [PATCH 6/9] vhost-scsi: log event " Dongli Zhang
2025-02-07 18:41 ` [PATCH 7/9] vhost: add WARNING if log_num is more than limit Dongli Zhang
2025-02-07 18:41 ` Dongli Zhang [this message]
2025-02-07 18:41 ` [PATCH 9/9] vhost-scsi: Fix vhost_scsi_send_bad_target() Dongli Zhang
2025-02-21 18:03 ` [PATCH 0/9] vhost-scsi: log write descriptors for live migration (and two bugfix) dongli.zhang
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=20250207184212.20831-9-dongli.zhang@oracle.com \
--to=dongli.zhang@oracle.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=joao.m.martins@oracle.com \
--cc=joe.jin@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.christie@oracle.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=si-wei.liu@oracle.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;
as well as URLs for NNTP newsgroup(s).