🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Yuho Choi Fri, 06 Nov 2026 05:48
[PATCH v1] vhost-scsi: do not validate vrings during endpoint teardown
#12017
Author: Yuho Choi
Date: Fri, 06 Nov 2026 05:48
46 lines
12287 bytes
vhost_scsi_clear_endpoint() checks every virtqueue with
vhost_vq_access_ok() before disabling the backends and waiting for
in-flight SCSI commands.  If that check fails, endpoint teardown is
skipped.

vhost_scsi_release() ignores the error and frees the vhost-scsi state.
vhost_dev_stop() drains vhost work, but it does not wait for commands
owned by the target core.  A later command or TMF completion can therefore
dereference its saved virtqueue pointer after the virtqueue has been freed.

Vring access is not a prerequisite for tearing an endpoint down.  Remove
the check so teardown always disables the backends and waits for in-flight
commands before releasing their state.

Fixes: 057cbf49a1f0 ("tcm_vhost: Initial merge for vhost level target fabric driver")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
 drivers/vhost/scsi.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index e44044449cef..f0966f25b09a 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -2194,17 +2194,10 @@ vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
 	struct vhost_scsi_tpg *tpg;
 	struct vhost_virtqueue *vq;
 	bool match = false;
-	int index, ret, i;
+	int ret, i;
 	u8 target;
 
 	mutex_lock(&vs->dev.mutex);
-	/* Verify that ring has been setup correctly. */
-	for (index = 0; index < vs->dev.nvqs; ++index) {
-		if (!vhost_vq_access_ok(&vs->vqs[index].vq)) {
-			ret = -EFAULT;
-			goto err_dev;
-		}
-	}
 
 	if (!vs->vs_tpg) {
 		ret = 0;
-- 
2.43.0
Re: [PATCH v1] vhost-scsi: do not validate vrings during endpoint teardown
#20731
Author: Yuho Choi
Date: Mon, 23 Nov 2026 05:22
54 lines
13953 bytes
Thanks for the review!

On Sun, 8 Nov 2026 at 14:05, Mike Christie <michael.christie@oracle.com> wrote:
>
> Can you describe the bug a little more?
>
> If we have done vhost_scsi_set_endpoint successfully, are you saying a later
> call to vhost_scsi_clear_endpoint could fail the. vhost_vq_access_ok check
> and not teardown the endpoint?

Yes, the first case is what I meant. Sorry for not explaining the
failure path in the commit message.

Since a543346b96a1 ("vhost-scsi: reject delayed virtqueue setup"), I/O
virtqueues that are not configured when SET_ENDPOINT is called remain
without a backend.

VHOST_SET_LOG_BASE validates the new log base only for virtqueues with
a backend. Therefore, an invalid log base can be stored in an inactive
virtqueue even when the ioctl returns -EFAULT. A subsequent
CLEAR_ENDPOINT then fails vhost_vq_access_ok() and skips teardown.

I reproduced this on current mainline (8dac6df92a2e) with KASAN, with
the following sequence:

  VHOST_SET_OWNER
  VHOST_SET_FEATURES(VHOST_F_LOG_ALL)
  VHOST_SET_MEM_TABLE
  Set up vq 0, 1, and 2 only
  VHOST_SCSI_SET_ENDPOINT             -> 0
  VHOST_SET_LOG_BASE(kernel address)  -> -EFAULT
  VHOST_SCSI_CLEAR_ENDPOINT           -> -EFAULT
  close()

After close(), tpg->vhost_scsi still points to the freed vs. Linking
another LUN triggers a KASAN use-after-free in vhost_scsi_do_plug().

I also reproduced the in-flight command UAF described in the commit
message. A delayed READ completion after close() triggers KASAN in
vhost_scsi_release_cmd(). The READ has to be queued after the
VHOST_SET_LOG_BASE call, because device ioctls flush in-flight
commands.

With the patch applied, both reproductions complete without KASAN
reports, and endpoint teardown succeeds.

Without a successful SET_ENDPOINT, no command can start, so the second
scenario you mentioned is not what I meant.

I can share the reproducer and full KASAN reports if useful. I'll
include the failure sequence in v2.

Thanks
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads