From: Alan Stern <stern@rowland.harvard.edu>
To: Khalid Masum <khalid.masum.92@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] usb: ehci: Prevent possible modulo by zero
Date: Wed, 24 Aug 2022 10:38:00 -0400 [thread overview]
Message-ID: <YwY3yHB/Ia+cPa1L@rowland.harvard.edu> (raw)
In-Reply-To: <CAABMjtH7q2evZ4R7FGC8m3a716ec9+e8+KdmrvnqB4_r6rF2Jg@mail.gmail.com>
On Wed, Aug 24, 2022 at 05:15:47PM +0600, Khalid Masum wrote:
> On Wed, Aug 24, 2022 at 2:21 AM Alan Stern <stern@rowland.harvard.edu> wrote:
> >
> > if (!ep) {
> > usb_free_urb(urb);
> > return NULL;
> > }
> >
> > Neither of these patches is needed.
> >
> > Alan Stern
>
> Thanks, I got you.
In fact, Coverity wasn't completely wrong; there is a possible bug here.
However the suggested fix is not the right approach.
The usb_maxpacket() routine does a two-step computation. First, it
looks up the endpoint number in the pipe to get a usb_host_endpoint
pointer, and then it uses the pointer to get the maxpacket value.
Coverity complained that the lookup in the first step can fail, and that
is in fact true: If there is an interface or configuration change before
usb_maxpacket() is called, the endpoint number table can change and the
lookup may fail.
But it turns out the first step isn't needed here at all, since the
endpoint pointer is already stored in the URB (by the code in
usb_submit_urb() that I pointed out earlier). So an appropriate way to
fix the problem is to carry out just the second step:
- maxpacket = usb_maxpacket(urb->dev, urb->pipe);
+ maxpacket = usb_endpoint_maxp(&urb->ep->desc);
This holds for both of your patches.
Alan Stern
next prev parent reply other threads:[~2022-08-24 14:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 18:27 [PATCH 0/2] usb: ehci: Prevent possible modulo by zero Khalid Masum
2022-08-23 18:27 ` [PATCH 1/2] " Khalid Masum
2022-08-23 20:21 ` Alan Stern
2022-08-24 11:15 ` Khalid Masum
2022-08-24 14:38 ` Alan Stern [this message]
2022-08-24 18:07 ` Khalid Masum
2022-08-23 18:27 ` [PATCH 2/2] " Khalid Masum
2022-08-24 5:56 ` Greg Kroah-Hartman
2022-08-24 11:22 ` Khalid Masum
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=YwY3yHB/Ia+cPa1L@rowland.harvard.edu \
--to=stern@rowland.harvard.edu \
--cc=gregkh@linuxfoundation.org \
--cc=khalid.masum.92@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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