All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hyunjung Ko" <hj351016@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: usbtmc: reject a short READ_STATUS_BYTE control transfer
Date: Thu, 19 Nov 2026 08:45:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-222705@kernel.org> (raw)
In-Reply-To: <20261119083959.1599898-1-hj351016@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: usbtmc: missing Fixes trailer and wrong ioctl name in
  commit message
--

commit 65820c8baf3e3185b7eb9f2281ee331492c9b001
Author: Hyunjung Ko <hj351016@gmail.com>

> usb: usbtmc: reject a short READ_STATUS_BYTE control transfer
>
> usbtmc_get_stb() asks the device for three bytes of the READ_STATUS_BYTE
> response into a kmalloc()'d buffer and only checks that usb_control_msg()
> did not fail:
>
>         buffer = kmalloc(8, GFP_KERNEL);
>         ...
>         rv = usb_control_msg(..., buffer, 0x03, USB_CTRL_GET_TIMEOUT);
>         if (rv < 0)
>                 goto exit;
>
> usb_control_msg() returns the number of bytes actually transferred,
> which a device is free to make shorter than the three that were
> requested.  When the interface has no interrupt-in endpoint the status
> byte is then taken straight from the third byte:
>
>         *stb = buffer[2];
>
> and the caller hands it to user space with put_user() from
> USBTMC488_IOCTL_READ_STB and USBTMC_IOCTL_GET_SRQ_STB.  A device that
> answers with one or two bytes - with the first byte set to
> USBTMC_STATUS_SUCCESS so the status check passes - therefore leaks one
> byte of uninitialised kmalloc memory to user space.  Both conditions are
> under the device's control, since it also decides whether to expose an
> interrupt-in endpoint.
>
> The same leak was fixed once before in this driver: usbtmc_ioctl_request()
> bounds its copy_to_user() to the number of bytes usb_control_msg() reported
> instead of the number requested.  usbtmc_get_stb() cannot be fixed that way
> because it reads a fixed offset, so reject the transfer unless all three
> bytes arrived, matching what usbtmc488_ioctl_simple() already does for its
> own one-byte request.
>
> The check is not limited to the branch that reads buffer[2]: buffer[0] is
> consumed on both paths, so a short response leaves the status check itself
> reading uninitialised memory.  USBTMC-USB488 4.3.1 requires the three-byte
> response, so a device that sends fewer is not conforming either way.
>
> Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
> Cc: stable@vger.kernel.org

[Severity: Low]
Should this bug fix include a Fixes tag for the commit that introduced the
unchecked three-byte READ_STATUS_BYTE control transfer:

  Fixes: dbf3e7f654c0 ("Implement an ioctl to support the USMTMC-USB488 READ_STATUS_BYTE operation.")

Also, the commit message mentions USBTMC_IOCTL_GET_SRQ_STB as the second
caller of usbtmc_get_stb(), but in usbtmc_ioctl() the second caller is
USBTMC_IOCTL_GET_STB (USBTMC_IOCTL_GET_SRQ_STB calls
usbtmc_ioctl_get_srq_stb() instead).

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

  reply	other threads:[~2026-11-19  8:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  8:39 [PATCH] usb: usbtmc: reject a short READ_STATUS_BYTE control transfer Hyunjung Ko
2026-11-19  8:45 ` sashiko-bot [this message]
2026-11-19 13:13 ` Greg Kroah-Hartman
2026-11-19 13:25   ` khj

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=sashiko-outbox-222705@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hj351016@gmail.com \
    --cc=linux-usb@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.