From: Dongli Zhang <dongli.zhang@oracle.com>
To: virtualization@lists.linux.dev, kvm@vger.kernel.org,
netdev@vger.kernel.org
Cc: mst@redhat.com, jasowang@redhat.com, michael.christie@oracle.com,
pbonzini@redhat.com, stefanha@redhat.com, eperezma@redhat.com,
joao.m.martins@oracle.com, joe.jin@oracle.com,
si-wei.liu@oracle.com, linux-kernel@vger.kernel.org
Subject: [PATCH v2 01/10] vhost-scsi: protect vq->log_used with vq->mutex
Date: Mon, 17 Mar 2025 16:55:09 -0700 [thread overview]
Message-ID: <20250317235546.4546-2-dongli.zhang@oracle.com> (raw)
In-Reply-To: <20250317235546.4546-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>
---
Changed since v1:
- Move lock to the begin and end of vhost_scsi_complete_cmd_work() as it
is per-vq now. This reduces the number of mutex_lock().
- Move this bugfix patch to before dirty log tracking patches.
drivers/vhost/scsi.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index f6f5a7ac7894..f846f2aa7c87 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -627,6 +627,9 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
int ret;
llnode = llist_del_all(&svq->completion_list);
+
+ mutex_lock(&svq->vq.mutex);
+
llist_for_each_entry_safe(cmd, t, llnode, tvc_completion_list) {
se_cmd = &cmd->tvc_se_cmd;
@@ -660,6 +663,8 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
vhost_scsi_release_cmd_res(se_cmd);
}
+ mutex_unlock(&svq->vq.mutex);
+
if (signal)
vhost_signal(&svq->vs->dev, &svq->vq);
}
@@ -1432,8 +1437,11 @@ 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);
+
vhost_scsi_release_tmf_res(tmf);
}
--
2.39.3
next prev parent reply other threads:[~2025-03-17 23:51 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-17 23:55 [PATCH v2 00/10] vhost-scsi: log write descriptors for live migration (and three bugfix) Dongli Zhang
2025-03-17 23:55 ` Dongli Zhang [this message]
2025-03-18 0:47 ` [PATCH v2 01/10] vhost-scsi: protect vq->log_used with vq->mutex Jason Wang
2025-03-26 22:22 ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 02/10] vhost-scsi: Fix vhost_scsi_send_bad_target() Dongli Zhang
2025-03-18 0:48 ` Jason Wang
2025-03-26 22:25 ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 03/10] vhost-scsi: Fix vhost_scsi_send_status() Dongli Zhang
2025-03-18 0:48 ` Jason Wang
2025-03-19 17:54 ` Dongli Zhang
2025-03-20 1:42 ` Jason Wang
2025-03-26 22:27 ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 04/10] vhost: modify vhost_log_write() for broader users Dongli Zhang
2025-03-18 1:12 ` Jason Wang
2025-03-19 16:38 ` Dongli Zhang
2025-03-20 1:41 ` Jason Wang
2025-03-17 23:55 ` [PATCH v2 05/10] vhost-scsi: adjust vhost_scsi_get_desc() to log vring descriptors Dongli Zhang
2025-03-26 23:21 ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 06/10] vhost-scsi: cache log buffer in I/O queue vhost_scsi_cmd Dongli Zhang
2025-03-18 0:04 ` Dongli Zhang
2025-03-26 23:37 ` Mike Christie
2025-03-27 20:27 ` Dongli Zhang
2025-03-17 23:55 ` [PATCH v2 07/10] vhost-scsi: log I/O queue write descriptors Dongli Zhang
2025-03-17 23:55 ` [PATCH v2 08/10] vhost-scsi: log control " Dongli Zhang
2025-03-17 23:55 ` [PATCH v2 09/10] vhost-scsi: log event " Dongli Zhang
2025-03-26 23:50 ` Mike Christie
2025-03-26 23:51 ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 10/10] vhost: add WARNING if log_num is more than limit 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=20250317235546.4546-2-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