Linux USB
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Syed Labeeq Sajid Bukhari <syedlabeeq@gmail.com>
Cc: linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net,
	stern@rowland.harvard.edu, stable@vger.kernel.org
Subject: Re: [PATCH] usb: storage: sierra_ms: reject short SWoC info transfers
Date: Fri, 4 Sep 2026 17:44:59 +0200	[thread overview]
Message-ID: <2026090423-trifle-employee-129d@gregkh> (raw)
In-Reply-To: <CAF4-o1fTYbxEb95NVsvcJ7=jdJB+vXpzspqcgwhNn=+FBsOsNg@mail.gmail.com>

On Fri, Sep 04, 2026 at 08:27:46PM +0500, Syed Labeeq Sajid Bukhari wrote:
> Hi Greg,
> 
> Thanks for the quick look, and apologies for the corrupted patch -- I sent
> sent it via a web mail client, which messed up with the whitespaces. I will
> resend it properly with git send-email, with the patch also attached.
> 
> On the short-transfer concern:
> 
> The SWoC query explicitly asks the device for exactly
> sizeof(struct swoc_info) (wLength = 60). This vendor command has a
> fixed-size response, and the driver already implicitly assumes a full
> answer today: containsFullLinuxPackage() and truinst_show()
> unconditionally read fields at fixed offsets (bytes 9-12) that a short
> transfer would never have written. So with a short answer the current code
> already makes its mode-switch decision on uninitialized garbage. The
> patch only makes that failure explicit instead of silent.

Ok, that's a good "proof" that this should be ok.

> Two further points:
> 
> * sierra_ms_init() retries the query up to 3 times on failure, so a
>   transient short transfer during probe is tolerated, not fatal.
> 
> * There is core precedent: usb_control_msg_recv() in usb/core/message.c
>   rejects short transfers with -EREMOTEIO, i.e. the USB core itself
>   treats a short control-IN as an error.

usb_control_msg_recv() is designed to work that way, it's not any sort
of "proof" that this is ok for this device :)

> To answer the testing question directly and honestly: no, I do not have
> the physical hardware, so this was not tested against a real Sierra
> TRU-Install device. It was tested with a fully controllable emulated
> device (raw_gadget on dummy_hcd, VID 0x1199 PID 0x0fff) against a
> self-built 6.12.108 kernel:
> 
> * full 60-byte response: enumeration and truinst reads behave exactly as
>   before (attribute created, values printed);
> * short response: the query now fails with -EIO instead of exposing
>   uninitialized heap through the world-readable truinst attribute.


That's a fake device, real devices are what really matters for testing,
you know this :)

> If you would rather avoid any risk on some devices you mentioned, I
> can respin this the other way: allocate the swoc_info buffer with
> kzalloc() in truinst_show()/sierra_ms_init() instead of rejecting short
> transfers. That closes the uninitialized-data exposure without changing
> behavior for short answers (the unwritten tail becomes deterministic
> zeros). Happy to send whichever variant you prefer.

kzalloc() is good, and is what we have done for other types of issues
like this:
	https://lore.kernel.org/r/20260819-usb_misc_random-v1-1-43a0dcee3a32@kroah.com
but as the data is being accessed, this should be ok.  Worst case, we
get a bug report and fix it afterward like we have for other times we
have messed up.

thanks,

greg k-h

      reply	other threads:[~2026-09-04 15:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 14:52 [PATCH] usb: storage: sierra_ms: reject short SWoC info transfers Syed Labeeq Sajid Bukhari
2026-09-04 15:07 ` Greg KH
2026-09-04 15:27   ` Syed Labeeq Sajid Bukhari
2026-09-04 15:44     ` Greg KH [this message]

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=2026090423-trifle-employee-129d@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=syedlabeeq@gmail.com \
    --cc=usb-storage@lists.one-eyed-alien.net \
    /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