From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 718AE271464; Tue, 27 May 2025 17:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748366305; cv=none; b=pO+/4Gik8uVvrVtet0ubSE1fD2gg8owpIK6VDwXWinB0MqHldwzoeBOuwBYI0u5MHeo9FAkBYr3kjGlOqZFL6u3PfCdpMITCxogdodkKzTSEJkqiXN1xP3hDaV5x7Ri2GcxfBwdce2kb7PkWw+qNO/xFYjDWzvPnxIYevT0+B6k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748366305; c=relaxed/simple; bh=s1KEof6ZxRxaVM0IqyJDMp8yBzfZABuCiBP+sdcLYHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QMX5WYSChbHb7YcHqpTW7gMf1oChqdbdkTOTjuFVs/3ucAhtUcDoIaPR3L76oH1atZTwtEeEkblMNwbYLIdTLY3tBktdvt6ZK6AkajXmIHu5IsaO+CTC3eSQUc0xq6hybUc7cGSCQNsJvfr7/NRlPIumMk1Mzrc+CL3ycasHE9Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=N4b/nS5p; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="N4b/nS5p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB09AC4CEE9; Tue, 27 May 2025 17:18:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748366305; bh=s1KEof6ZxRxaVM0IqyJDMp8yBzfZABuCiBP+sdcLYHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N4b/nS5pnGCt0+BO3KKkuF/J4ZV6ZpL+QTemBQ7YkWwNdv08686k3cCQWbod9G/+U zGGzMQgHA7hgItmTaSMcYexL6kLW4CYhioal8m22b7uaeNkeC/KzUSD9AY1Ne1KZjL sXPTGEEq0ygyjqni4/jfQ57H8DIYeAvl1QutvGm0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dongli Zhang , Jason Wang , Mike Christie , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 6.14 026/783] vhost-scsi: protect vq->log_used with vq->mutex Date: Tue, 27 May 2025 18:17:03 +0200 Message-ID: <20250527162514.171413039@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527162513.035720581@linuxfoundation.org> References: <20250527162513.035720581@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dongli Zhang [ Upstream commit f591cf9fce724e5075cc67488c43c6e39e8cbe27 ] 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 Acked-by: Jason Wang Reviewed-by: Mike Christie Message-Id: <20250403063028.16045-2-dongli.zhang@oracle.com> Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/vhost/scsi.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 35a03306d1345..ecad2f53b7635 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -571,6 +571,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; @@ -604,6 +607,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); } @@ -1346,8 +1351,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.5