Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: sashiko-reviews@lists.linux.dev
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	 linux-scsi@vger.kernel.org
Subject: Re: [RFC PATCH] usb: storage: uas: limit consecutive device resets in error handling
Date: Wed, 1 Jul 2026 13:31:12 +0900	[thread overview]
Message-ID: <akSXFydSPAQGi-4b@google.com> (raw)
In-Reply-To: <20260701041700.EB7971F000E9@smtp.kernel.org>

On (26/07/01 04:17), sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] Prematurely clearing `devinfo->resetting` and dropping the lock before calling `uas_zap_pending()` creates a race window with `uas_do_work()`, leading to a kernel warning and Use-After-Free.
> - [Medium] Time-of-Check to Time-of-Use (TOCTOU) race when reading the `uas_reset_limit` module parameter.

[..]

> > +	spin_lock_irqsave(&devinfo->lock, flags);
> > +	if (uas_reset_limit > 0 && devinfo->reset_cnt >= uas_reset_limit) {
> 
> [Severity: Medium]
> Can a concurrent sysfs write cause a Time-of-Check to Time-of-Use race here?
> 
> The module parameter uas_reset_limit has 0644 permissions. It is read twice
> in this condition without a READ_ONCE() wrapper. If it is modified from a
> positive value to zero or negative strictly between the two evaluations, the
> first check (uas_reset_limit > 0) could pass, while the second check could
> evaluate against the new zero or negative value, prematurely failing the reset
> and offlining the device.

Sounds reasonable.

> 
> > +		devinfo->resetting = 0;
> > +		spin_unlock_irqrestore(&devinfo->lock, flags);
> > +		uas_zap_pending(devinfo, DID_NO_CONNECT);
> 
> [Severity: High]
> Does clearing devinfo->resetting and dropping the lock before calling
> uas_zap_pending() introduce a race condition with uas_do_work()?

Yes, this looks wrong.  Let me take a look.

  reply	other threads:[~2026-07-01  4:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  4:03 [RFC PATCH] usb: storage: uas: limit consecutive device resets in error handling Sergey Senozhatsky
2026-07-01  4:17 ` sashiko-bot
2026-07-01  4:31   ` Sergey Senozhatsky [this message]
2026-07-01  5:38 ` Greg KH
2026-07-01  5:57   ` Sergey Senozhatsky
2026-07-01  6:01     ` Sergey Senozhatsky
2026-07-01  8:28 ` [usb-storage] " Oliver Neukum
2026-07-02  2:25   ` Sergey Senozhatsky
2026-07-02  8:08     ` Oliver Neukum
2026-07-02  8:21       ` Sergey Senozhatsky

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=akSXFydSPAQGi-4b@google.com \
    --to=senozhatsky@chromium.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@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