Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nguyen Ngoc Thang" <ngocthang2710.1999@gmail.com>
Cc: virtualization@lists.linux.dev, linux-scsi@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [RFC PATCH] scsi: virtio_scsi: bound EH timer resets to avoid unkillable hang
Date: Fri, 11 Sep 2026 16:35:08 +0000	[thread overview]
Message-ID: <20260911163509.684191F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911162118.32414-1-ngocthang2710.1999@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Missing eh_host_reset_handler causes SCSI EH to free commands while the host is active, resulting in DMA memory corruption and Use-After-Free.
--

commit c1b61825f071ba8c8020eead463039fdb142c7b0
Author: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>

scsi: virtio_scsi: bound EH timer resets to avoid unkillable hang

This commit limits the number of times virtscsi_eh_timed_out() can reset
the command timer to 5, returning SCSI_EH_NOT_HANDLED afterward. It also
bounds the wait time in virtscsi_tmf() when handling aborts and resets to
prevent infinite hangs if the transport breaks.

Closes: https://syzkaller.appspot.com/bug?extid=53706c567afab5131044

> diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> index 35731b18c519e..b4f20c4877182 100644
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c

[ ... ]

> @@ -783,13 +818,19 @@ static void virtscsi_commit_rqs(struct Scsi_Host *shost, u16 hwq)
>  }
>  
>  /*
> - * The host guarantees to respond to each command, although I/O
> - * latencies might be higher than on bare metal.  Reset the timer
> - * unconditionally to give the host a chance to perform EH.
> + * The host normally answers every command, so reset the timer and keep
> + * waiting. But if the transport is broken (e.g. bus mastering was turned
> + * off), no completion can ever arrive: give up after a few resets so SCSI
> + * EH fails the command instead of blocking its submitter forever.
>   */
>  static enum scsi_timeout_action virtscsi_eh_timed_out(struct scsi_cmnd *scmnd)
>  {
> -	return SCSI_EH_RESET_TIMER;
> +	struct virtio_scsi_cmd *cmd = scsi_cmd_priv(scmnd);
> +
> +	if (++cmd->eh_resets < VIRTSCSI_EH_RESET_LIMIT)
> +		return SCSI_EH_RESET_TIMER;
> +
> +	return SCSI_EH_NOT_HANDLED;

[Severity: Critical]
Does returning SCSI_EH_NOT_HANDLED here allow SCSI EH to run and eventually
free the command without ensuring the host has dropped its DMA references?

If the virtio host experiences a severe delay and eventually completes the
timed-out commands, could it DMA the response directly into memory that has
already been freed by SCSI EH and potentially reallocated to new requests?

If this happens, wouldn't it result in a use-after-free and DMA memory
corruption when virtscsi_complete_cmd() runs?

For example:

virtscsi_complete_cmd() {
	struct virtio_scsi_cmd *cmd = buf;
	struct scsi_cmnd *sc = cmd->sc;
	struct virtio_scsi_cmd_resp *resp = &cmd->resp.cmd;
	...
	scsi_done(sc);
}

Here the dangling pointer from the virtqueue would be dereferenced after
the command has been freed by SCSI EH, potentially followed by a kernel
panic when scsi_done() is called on the corrupted scsi_cmnd pointer.

>  }
>  
>  static const struct scsi_host_template virtscsi_host_template = {

[Severity: Critical]
Does the host template lack an eh_host_reset_handler?

Without this, SCSI EH cannot safely stop the virtio device before freeing
the timed-out commands. If SCSI EH attempts aborts and device resets which
also time out, it will give up, offline the device, and flush (free) the
commands. When the host later resumes and processes the virtqueue, could it
overwrite the freed memory?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260911162118.32414-1-ngocthang2710.1999@gmail.com?part=1

  reply	other threads:[~2026-09-11 16:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 16:21 [RFC PATCH] scsi: virtio_scsi: bound EH timer resets to avoid unkillable hang Nguyen Ngoc Thang
2026-09-11 16:35 ` sashiko-bot [this message]
2026-09-11 16:44   ` Nguyen Ngoc Thang

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=20260911163509.684191F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=ngocthang2710.1999@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --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