From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387014; b=yDpsyEwTXUK4GfCccxrszSCN8DUHqHkCqozPC33NKUIcVSzZHu2cZfW6GH1PNTeF819w flTQFl0woCLoGaG9NfKG6nfRTHVmW8YLy5LPCvIltef8pfh3LXy8hy8TaRdvcwVmAI57t s3SWwKnkAQS3ZVxf2AogaFfpgoclUyv8di5WM5Vtvdh5JpvNn/MW6kgaKZIArWaiv/JT+ duCrsUbvHaG0pu4DHuYUkv/hcEYvMZtrOVjwTryzdnGPzEG4ABe4pcLNUbvrTcikeT7os OiEFyih+okjJEEZzVvmYFc4hnHrysT4xI8KbFMhq7M3VQVu9I/GcdxdLCTty2zPW2qQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387014; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=1+cgTnsIcG/mAc94/NGowlImk0CgbKzII10AL3hTdJk=; b=PHvK2oVBPOYYLKWgbGVrEkyJjFDa08h8Tq/+J/n7KBLoAQhUCD8PGk7GuJKm+PwX7ZSz L6aXF/EvnR5CH96bRJG6KtpsijxFiodASG86kP841SJLOcLYX2yx5GWCHb7z/Hs2gVPk1 FpTTsOtkcdik6d57RxODCf57cut0wqcca30X8Z5OS70EYN3l6mYhSoRBg4o+V0ZVKB8Ai hRa/gW9TM+kxm9YVvrDqq3vD8fMkXAf/YAcaQn8lkv1vyKhjeVzKhItds/vddhEGG6EHu RlOJKh8Sthv3T5fvoloRMwtItPkjp54Btx8uA9xIl6rNWb8r25atXr+SdxPY0Omjt/Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=sbPg0jxz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82B55606A322; Fri, 4 Dec 2026 12:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=sbPg0jxz Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDAE81F000C2; Fri, 4 Dec 2026 12:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387014; bh=1+cgTnsIcG/mAc94/NGowlImk0CgbKzII10AL3hTdJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sbPg0jxzrSTDHLaLZtQTK63KHmEc5DSl4UVcHLpLMMonQFEXnVPhY6RDJn28A7enE Z0N6oRLG/QTmpWBt776hP+p6IrIIjdYjI765csvbRAS/+xJJueeNYkuFvrCi+5TZK8 MnaEaWGTL6jJw3ULUqawbLux4f9NR1yQDAbFKBpE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Linfeng Sun , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 6.1 0096/1059] vhost-scsi: reject delayed virtqueue setup Date: Fri, 4 Dec 2026 18:53:47 +0900 Message-ID: <20261204100646.602726124@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linfeng Sun [ Upstream commit a543346b96a174fcee6812ac2764acc8dc993358 ] vhost_scsi_set_endpoint() allocates command pools only for I/O virtqueues that are already set up, but publishes the backend for every virtqueue. Userspace can complete a skipped queue after attaching the endpoint, then kick it with scsi_tags uninitialized and trigger the alloc_hint warning in sbitmap_get(). Delayed virtqueue setup is not supported. Leave skipped I/O virtqueues inactive and reject changes to the vring size or addresses while an endpoint is attached. Userspace must clear the endpoint before changing the vring configuration. I found this bug myself, though the patch was written with AI assistance. Fixes: 25b98b64e284 ("vhost scsi: alloc cmds per vq instead of session") Assisted-by: OpenAI-Codex:GPT-5.6 Signed-off-by: Linfeng Sun Signed-off-by: Michael S. Tsirkin Message-ID: <20261010-fix-warning-in-sbitmap_get-v3-1-33de562d1359@gmail.com> Signed-off-by: Sasha Levin --- drivers/vhost/scsi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 8974bb13f8e18..516962d53169f 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -1646,6 +1646,9 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs, for (i = 0; i < vs->dev.nvqs; i++) { vq = &vs->vqs[i].vq; + if (i >= VHOST_SCSI_VQ_IO && !vs->vqs[i].scsi_cmds) + continue; + mutex_lock(&vq->mutex); vhost_vq_set_backend(vq, vs_tpg); vhost_vq_init_access(vq); @@ -1958,10 +1961,16 @@ vhost_scsi_ioctl(struct file *f, default: mutex_lock(&vs->dev.mutex); r = vhost_dev_ioctl(&vs->dev, ioctl, argp); - if (r == -ENOIOCTLCMD) - r = vhost_vring_ioctl(&vs->dev, ioctl, argp); - else + if (r == -ENOIOCTLCMD) { + if (vs->vs_tpg && + (ioctl == VHOST_SET_VRING_NUM || + ioctl == VHOST_SET_VRING_ADDR)) + r = -EBUSY; + else + r = vhost_vring_ioctl(&vs->dev, ioctl, argp); + } else { vhost_scsi_flush(vs); + } mutex_unlock(&vs->dev.mutex); return r; } -- 2.53.0