From: Greg KH <greg@kroah.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Johan Hovold <johan@kernel.org>,
USB mailing list <linux-usb@vger.kernel.org>
Subject: Re: [PATCH] USB: core: Check buffer length matches wLength for control transfers
Date: Thu, 27 May 2021 13:46:58 +0200 [thread overview]
Message-ID: <YK+GsvCVDrA40GIc@kroah.com> (raw)
In-Reply-To: <20210526153244.GA1400430@rowland.harvard.edu>
On Wed, May 26, 2021 at 11:32:44AM -0400, Alan Stern wrote:
> A type of inconsistency that can show up in control URBs is when the
> setup packet's wLength value does not match the URB's
> transfer_buffer_length field. The two should always be equal;
> differences could lead to information leaks or undefined behavior for
> OUT transfers or overruns for IN transfers.
>
> This patch adds a test for such mismatches during URB submission. If
> the test fails, the submission is rejected with a -EBADR error code
> (which is not used elsewhere in the USB core), and a debugging message
> is logged for people interested in tracking down these errors.
>
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> CC: Johan Hovold <johan@kernel.org>
>
> ---
>
>
> [as1961]
>
>
> Documentation/driver-api/usb/error-codes.rst | 3 +++
> drivers/usb/core/urb.c | 6 ++++++
> 2 files changed, 9 insertions(+)
>
> Index: usb-devel/drivers/usb/core/urb.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/core/urb.c
> +++ usb-devel/drivers/usb/core/urb.c
> @@ -410,6 +410,12 @@ int usb_submit_urb(struct urb *urb, gfp_
> dev_WARN_ONCE(&dev->dev, (usb_pipeout(urb->pipe) != is_out),
> "BOGUS control dir, pipe %x doesn't match bRequestType %x\n",
> urb->pipe, setup->bRequestType);
> + if (le16_to_cpu(setup->wLength) != urb->transfer_buffer_length) {
> + dev_dbg(&dev->dev, "BOGUS control len %d doesn't match transfer length %d\n",
> + le16_to_cpu(setup->wLength),
> + urb->transfer_buffer_length);
> + return -EBADR;
> + }
Looks good, let's see if this catches anything :)
now queued up, thanks.
greg k-h
prev parent reply other threads:[~2021-05-27 11:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 15:32 [PATCH] USB: core: Check buffer length matches wLength for control transfers Alan Stern
2021-05-27 8:23 ` Johan Hovold
2021-05-27 11:46 ` 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=YK+GsvCVDrA40GIc@kroah.com \
--to=greg@kroah.com \
--cc=johan@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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;
as well as URLs for NNTP newsgroup(s).