From: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
To: Takashi Iwai <tiwai-l3A5Bk7waGM@public.gmane.org>
Cc: Alan Stern
<stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>,
Andrey Konovalov
<andreyknvl-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
Arvind Yadav
<arvind.yadav.cs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Jaroslav Kysela <perex-/Fr2/VpizcU@public.gmane.org>,
Takashi Sakamoto
<o-takashi-sodqOivclbsO3cATojSK5Q@public.gmane.org>,
LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Dmitry Vyukov <dvyukov-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
Kostya Serebryany <kcc-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
syzkaller <syzkaller-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>,
linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: usb/sound/bcd2000: warning in bcd2000_init_device
Date: Wed, 4 Oct 2017 10:26:07 +0200 [thread overview]
Message-ID: <20171004082607.GA18449@kroah.com> (raw)
In-Reply-To: <s5htvzftjwn.wl-tiwai-l3A5Bk7waGM@public.gmane.org>
On Wed, Oct 04, 2017 at 10:08:24AM +0200, Takashi Iwai wrote:
> On Wed, 04 Oct 2017 09:52:36 +0200,
> Greg Kroah-Hartman wrote:
> >
> > On Wed, Oct 04, 2017 at 08:10:59AM +0200, Takashi Iwai wrote:
> > > On Tue, 03 Oct 2017 19:42:21 +0200,
> > > Greg Kroah-Hartman wrote:
> > > >
> > > > On Tue, Oct 03, 2017 at 12:50:08PM -0400, Alan Stern wrote:
> > > > > On Tue, 3 Oct 2017, Takashi Iwai wrote:
> > > > >
> > > > > > > It's a dev_WARN because it indicates a potentially serious error in the
> > > > > > > driver: The driver has submitted an interrupt URB to a bulk endpoint.
> > > > > > > That may not sound bad, but the same check gets triggered if a driver
> > > > > > > submits a bulk URB to an isochronous endpoint, or any other invalid
> > > > > > > combination.
> > > > > > >
> > > > > > > Most likely the explanation here is that the driver doesn't bother to
> > > > > > > check the endpoint type because it expects the endpoint will always be
> > > > > > > interrupt. But that is not a safe strategy. USB devices and their
> > > > > > > firmware should not be trusted unnecessarily.
> > > > > > >
> > > > > > > The best fix is, like you said, to add a sanity check in the caller.
> > > > > >
> > > > > > OK, but then do we have some handy helper for the check?
> > > > > > As other bug reports by syzkaller suggest, there are a few other
> > > > > > drivers that do the same, submitting a urb with naive assumption of
> > > > > > the fixed EP for specific devices. In the end we'll need to put the
> > > > > > very same checks there in multiple places.
> > > > >
> > > > > Perhaps we could add a helper routine that would take a list of
> > > > > expected endpoint types and check that the actual endpoints match the
> > > > > types. But of course, all the drivers you're talking about would have
> > > > > to add a call to this helper routine.
> > > >
> > > > We have almost this type of function, usb_find_common_endpoints(),
> > > > what's wrong with using that? Johan has already swept the tree and
> > > > added a lot of these checks, odds are no one looked at the sound/
> > > > subdir...
> > >
> > > Well, what I had in my mind is just a snippet from usb_submit_urb(),
> > > something like:
> > >
> > > bool usb_sanity_check_urb_pipe(struct urb *urb)
> > > {
> > > struct usb_host_endpoint *ep;
> > > int xfertype;
> > > static const int pipetypes[4] = {
> > > PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
> > > };
> > >
> > > ep = usb_pipe_endpoint(urb->dev, urb->pipe);
> > > xfertype = usb_endpoint_type(&ep->desc);
> > > return usb_pipetype(urb->pipe) != pipetypes[xfertype];
> > > }
> > >
> > > And calling this before usb_submit_urb() in each place that assigns
> > > the fixed EP as device-specific quirks.
> > > Does it make sense?
> >
> > Yes, kind of, but checking the endpoint type/direction is what you are
> > expecting it to be as you "know" what the type should be for each
> > driver as it is unique.
>
> Yes, it can be simplified, but if we want a common helper function,
> this style would have an advantage that it can be used generically for
> all drivers.
>
> > Anyway, a "real" patch might make more sense to me.
>
> I can cook up a patch if you find it a good idea to add such a common
> function to usb core side. OTOH, if each driver should open-code this
> in each place, I can work on that, too. Which would you prefer?
A common function is good, open-coding is bad :)
Try it with a driver or two to see what it looks like?
thanks,
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-10-04 8:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-25 12:39 usb/sound/bcd2000: warning in bcd2000_init_device Andrey Konovalov
2017-10-03 7:52 ` Takashi Iwai
2017-10-03 14:21 ` Alan Stern
2017-10-03 15:48 ` Takashi Iwai
2017-10-03 16:50 ` Alan Stern
2017-10-03 17:42 ` Greg Kroah-Hartman
2017-10-04 6:10 ` Takashi Iwai
2017-10-04 7:52 ` Greg Kroah-Hartman
2017-10-04 8:08 ` Takashi Iwai
[not found] ` <s5htvzftjwn.wl-tiwai-l3A5Bk7waGM@public.gmane.org>
2017-10-04 8:26 ` Greg Kroah-Hartman [this message]
2017-10-04 9:24 ` Johan Hovold
2017-10-04 10:04 ` Takashi Iwai
2017-10-04 10:23 ` Johan Hovold
2017-10-04 10:41 ` Takashi Iwai
2017-10-04 12:03 ` Johan Hovold
2017-10-04 13:02 ` Takashi Iwai
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=20171004082607.GA18449@kroah.com \
--to=gregkh-hqyy1w1ycw8ekmwlsbkhg0b+6bgklq7r@public.gmane.org \
--cc=alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org \
--cc=andreyknvl-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=arvind.yadav.cs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=dvyukov-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=kcc-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=o-takashi-sodqOivclbsO3cATojSK5Q@public.gmane.org \
--cc=perex-/Fr2/VpizcU@public.gmane.org \
--cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org \
--cc=syzkaller-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
--cc=tiwai-l3A5Bk7waGM@public.gmane.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