mbox series

[v2,0/4] USB: cdc-acm: handle broken union descriptors

Message ID 20200921135951.24045-1-johan@kernel.org
Headers show
Series USB: cdc-acm: handle broken union descriptors | expand

Message

Johan Hovold Sept. 21, 2020, 1:59 p.m. UTC
This series adds support for handling broken union descriptors by
falling back to "combined-interface" probing.

The first patch drops some bogus altsetting sanity checks which would
otherwise have had to be needlessly reproduced for consistency. The
third patch drops the driver specific data class define in favour of the
common one. The last one, cleans up the no-union-descriptor handling by
probing for a "combined-interface" before falling back to the
call-management descriptor.

Note that I changed my mind on the stable tag; we can't be overly
paranoid about a theoretical risk of breaking some quirky devices. And
if we do, we still want to know about it, right?

Daniel, would you mind giving these a spin as well?

Johan

v2
 - add stable tag to 2/2 as it enables a new class of devices
 - demote a broken-union warning to dev_dbg
 - replace the fourth RFC patch with a clean up of the
   no-union-descriptor case only


Johan Hovold (4):
  Revert "cdc-acm: hardening against malicious devices"
  USB: cdc-acm: handle broken union descriptors
  USB: cdc-acm: use common data-class define
  USB: cdc-acm: clean up no-union-descriptor handling

 drivers/usb/class/cdc-acm.c | 55 ++++++++++++++++---------------------
 drivers/usb/class/cdc-acm.h | 13 ++++-----
 2 files changed, 29 insertions(+), 39 deletions(-)

Comments

f1rmb.daniel@gmail.com Sept. 21, 2020, 2:21 p.m. UTC | #1
Hi Johan,


   Yes, sure. Patching....


Cheers.
---
Daniel
f1rmb.daniel@gmail.com Sept. 21, 2020, 4:19 p.m. UTC | #2
Hi Johan, Oliver,

   I just compiled and tested, everything still works.


Cheers.
---
Daniel
Oliver Neukum Sept. 21, 2020, 5:17 p.m. UTC | #3
Am Montag, den 21.09.2020, 17:16 +0200 schrieb Johan Hovold:
> > > interface? By hardcoding the data-interface number to be the one and
> > > only interface, you'd end up probing for a "combined" interface also
> > > with a broken call-management descriptor.
> > 
> > Well, by the changelog assuming a combined interface caused an oops.
> > Thence I am forced to conclude that the davices _has_ a separate
> > data interface, but no union descriptor.
> 
> No, the oops was probably due to the missing sanity check later added by
> 403dff4e2c94 ("USB: cdc-acm: check for valid interfaces").
> 
> With a broken call-management descriptor pointing to a non-existent
> interface we'd oops before that commit.

Hi,

maybe I am dense, but a patch that comes after a patch that is said to
fix something? Furthermore that patch would not come it work,
it would merely make probe() fail cleanly. If I read the changelog
correctly, the change makes the device work.

	Regards
		Oliver
Johan Hovold Sept. 22, 2020, 7:05 a.m. UTC | #4
On Mon, Sep 21, 2020 at 07:17:37PM +0200, Oliver Neukum wrote:
> Am Montag, den 21.09.2020, 17:16 +0200 schrieb Johan Hovold:
> > > > interface? By hardcoding the data-interface number to be the one and
> > > > only interface, you'd end up probing for a "combined" interface also
> > > > with a broken call-management descriptor.
> > > 
> > > Well, by the changelog assuming a combined interface caused an oops.
> > > Thence I am forced to conclude that the davices _has_ a separate
> > > data interface, but no union descriptor.
> > 
> > No, the oops was probably due to the missing sanity check later added by
> > 403dff4e2c94 ("USB: cdc-acm: check for valid interfaces").
> > 
> > With a broken call-management descriptor pointing to a non-existent
> > interface we'd oops before that commit.
> 
> Hi,
> 
> maybe I am dense, but a patch that comes after a patch that is said to
> fix something? Furthermore that patch would not come it work,
> it would merely make probe() fail cleanly. If I read the changelog
> correctly, the change makes the device work.

The relevant commits are

  a2bfb4a346d2 ("USB: support for cdc-acm of single interface devices")      (2009)
  fd5054c169d2 ("USB: cdc_acm: Fix oops when Droids MuIn LCD is connected")  (2011)
  403dff4e2c94 ("USB: cdc-acm: check for valid interfaces")                  (2014) 

Before Greg added the sanity checks in that last commit, a broken
call-management descriptor referring to a non-existent interface would
cause a NULL-pointer dereference.

The second commit, adding support for a specific device, didn't fix that
problem generally and only worked around it for one device by hardcoding
the data interface to match the control interface, thereby falling back
to the "combined-interface" probing you added in that first commit.

See? The second commit fixed the oops *and* made the device probe
successfully. If we'd had the sanity check in place by then it would
only have make it probe successfully.

Johan
Johan Hovold Sept. 22, 2020, 7:08 a.m. UTC | #5
On Mon, Sep 21, 2020 at 06:19:12PM +0200, <Daniel Caujolle-Bert> wrote:
> Hi Johan, Oliver,

> 

>    I just compiled and tested, everything still works.


Thanks for testing, Daniel.

If you want to you can reply to the second patch with a Tested-by tag so
that it gets added by Greg's tooling (or reply to the cover letter if
you want to have that tag added to all the patches in the series).

Johan
f1rmb.daniel@gmail.com Sept. 22, 2020, 9:56 a.m. UTC | #6
Hi Johan,

   Okay, I replied to the second patch, hope I didn't make any mistake.


Cheers.
---
Daniel
Johan Hovold Sept. 22, 2020, 10:07 a.m. UTC | #7
On Tue, Sep 22, 2020 at 11:56:02AM +0200, <Daniel Caujolle-Bert> wrote:
> Hi Johan,

> 

>    Okay, I replied to the second patch, hope I didn't make any mistake.


Looks good. Thanks again!

Johan
Oliver Neukum Sept. 22, 2020, 10:40 a.m. UTC | #8
Am Dienstag, den 22.09.2020, 09:05 +0200 schrieb Johan Hovold:

> The relevant commits are

> 

>   a2bfb4a346d2 ("USB: support for cdc-acm of single interface devices")      (2009)

>   fd5054c169d2 ("USB: cdc_acm: Fix oops when Droids MuIn LCD is connected")  (2011)

>   403dff4e2c94 ("USB: cdc-acm: check for valid interfaces")                  (2014) 

> 

> Before Greg added the sanity checks in that last commit, a broken

> call-management descriptor referring to a non-existent interface would

> cause a NULL-pointer dereference.


Yes.

> The second commit, adding support for a specific device, didn't fix that

> problem generally


Yes

>  and only worked around it for one device by hardcoding

> the data interface to match the control interface,


How do you know. It hardcoded the data interface. That it matches
the control interface is a guess.

>  thereby falling back

> to the "combined-interface" probing you added in that first commit.


How do you know? They may or may not match. 

	Regards
		Oliver
Johan Hovold Sept. 22, 2020, 10:54 a.m. UTC | #9
On Tue, Sep 22, 2020 at 12:40:42PM +0200, Oliver Neukum wrote:
> Am Dienstag, den 22.09.2020, 09:05 +0200 schrieb Johan Hovold:
> 
> > The relevant commits are
> > 
> >   a2bfb4a346d2 ("USB: support for cdc-acm of single interface devices")      (2009)
> >   fd5054c169d2 ("USB: cdc_acm: Fix oops when Droids MuIn LCD is connected")  (2011)
> >   403dff4e2c94 ("USB: cdc-acm: check for valid interfaces")                  (2014) 
> > 
> > Before Greg added the sanity checks in that last commit, a broken
> > call-management descriptor referring to a non-existent interface would
> > cause a NULL-pointer dereference.
> 
> Yes.
> 
> > The second commit, adding support for a specific device, didn't fix that
> > problem generally
> 
> Yes
> 
> >  and only worked around it for one device by hardcoding
> > the data interface to match the control interface,
> 
> How do you know. It hardcoded the data interface. That it matches
> the control interface is a guess.

No, see below.

> >  thereby falling back
> > to the "combined-interface" probing you added in that first commit.
> 
> How do you know? They may or may not match. 

Heh. Did you actually read the commit message?

	"Add NO_DATA_INTERFACE quirk to tell the driver that "control"
	 and "data" interfaces are not separated for this device, which
	 prevents dereferencing a null pointer in the device probe
	 code."

Convinced yet?

Johan
Oliver Neukum Sept. 22, 2020, 11:41 a.m. UTC | #10
Am Dienstag, den 22.09.2020, 12:54 +0200 schrieb Johan Hovold:

> Heh. Did you actually read the commit message?

> 

> 	"Add NO_DATA_INTERFACE quirk to tell the driver that "control"

> 	 and "data" interfaces are not separated for this device, which

> 	 prevents dereferencing a null pointer in the device probe

> 	 code."

> 

> Convinced yet?


This patch does not fully match its description. Very well. Proceed.
Could you resubmit and I'll ack?

	Regards
		Oliver
Johan Hovold Sept. 22, 2020, 11:47 a.m. UTC | #11
On Tue, Sep 22, 2020 at 01:41:06PM +0200, Oliver Neukum wrote:
> Am Dienstag, den 22.09.2020, 12:54 +0200 schrieb Johan Hovold:

> 

> > Heh. Did you actually read the commit message?

> > 

> > 	"Add NO_DATA_INTERFACE quirk to tell the driver that "control"

> > 	 and "data" interfaces are not separated for this device, which

> > 	 prevents dereferencing a null pointer in the device probe

> > 	 code."

> > 

> > Convinced yet?

> 

> This patch does not fully match its description. Very well. Proceed.

> Could you resubmit and I'll ack?


I think you can just ack whole series by replying to 0/4. If Greg wants
it resubmitted I'll include that ack when resending. Works for you?

Johan
Oliver Neukum Sept. 22, 2020, 12:10 p.m. UTC | #12
Am Montag, den 21.09.2020, 15:59 +0200 schrieb Johan Hovold:
> This series adds support for handling broken union descriptors by
> falling back to "combined-interface" probing.
> 
> The first patch drops some bogus altsetting sanity checks which would
> otherwise have had to be needlessly reproduced for consistency. The
> third patch drops the driver specific data class define in favour of the
> common one. The last one, cleans up the no-union-descriptor handling by
> probing for a "combined-interface" before falling back to the
> call-management descriptor.
> 
> Note that I changed my mind on the stable tag; we can't be overly
> paranoid about a theoretical risk of breaking some quirky devices. And
> if we do, we still want to know about it, right?

Acked-by: Oliver Neukum <oneukum@suse.com>