From nobody Tue Oct 7 03:48:52 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 37BD425B2E3; Tue, 15 Jul 2025 03:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752550475; cv=none; b=XsCbozQrzK9woSVHwp/PsLGw8yxxi6PpDRqiaOCfklk8K0xbhzy2S43Wgp0LMzvN01wlR9rbfCfqPUvUNmbQCsyWsa+x4wcmzlBcpnEc+TH+Yv1lrWYGn4wcsPRPIdXCBLcK7V8DUkBvxtXX5AKRyF4SUOoWr7EGuoU8qCkQMSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752550475; c=relaxed/simple; bh=iGIynGgZcN+Tky8z+74hs/M6AuLP5AAfdj32j/amb0Q=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AJvdAYfd1PUhWzYA9BRtYk/zt9mhO9W0Qlc8Y3VnHYRA35I7KZZRHyDJKpOczPx+A54Vnyma71k0erVFA7XfnNKIkX6GRTI5NzpWtmMSjK3DukSrnhQJMIiObjsIjQCy08R7BA2MqOm+lsJ2pZvtoFUlgQ3KxliHuJ7AwzBjt/c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4bh4WJ74gLz2FbPL; Tue, 15 Jul 2025 11:32:28 +0800 (CST) Received: from kwepemo200008.china.huawei.com (unknown [7.202.195.61]) by mail.maildlp.com (Postfix) with ESMTPS id 34F83140156; Tue, 15 Jul 2025 11:34:31 +0800 (CST) Received: from huawei.com (10.67.175.28) by kwepemo200008.china.huawei.com (7.202.195.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 15 Jul 2025 11:34:30 +0800 From: Xinyu Zheng To: , , , , , , , , , CC: Subject: [PATCH v6.1] vhost-scsi: protect vq->log_used with vq->mutex Date: Tue, 15 Jul 2025 03:22:55 +0000 Message-ID: <20250715032255.1624137-1-zhengxinyu6@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemo200008.china.huawei.com (7.202.195.61) Content-Type: text/plain; charset="utf-8" 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 =3D 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. Cc: stable@vger.kernel.org#6.1.x Cc: gregkh@linuxfoundation.org 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 [ Conflicts in drivers/vhost/scsi.c bacause vhost_scsi_complete_cmd_work() has been refactored. ] Signed-off-by: Xinyu Zheng --- drivers/vhost/scsi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 3077cb9d58d6..87f2f56fd20a 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -568,8 +568,10 @@ static void vhost_scsi_complete_cmd_work(struct vhost_= work *work) ret =3D copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter); if (likely(ret =3D=3D sizeof(v_rsp))) { struct vhost_scsi_virtqueue *q; - vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0); q =3D container_of(cmd->tvc_vq, struct vhost_scsi_virtqueue, vq); + mutex_lock(&q->vq.mutex); + vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0); + mutex_unlock(&q->vq.mutex); vq =3D q - vs->vqs; __set_bit(vq, vs->compl_bitmap); } else @@ -1173,8 +1175,11 @@ static void vhost_scsi_tmf_resp_work(struct vhost_wo= rk *work) else resp_code =3D VIRTIO_SCSI_S_FUNCTION_REJECTED; =20 + 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); } =20 --=20 2.34.1