linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] can: fix USB altsetting bugs
@ 2019-12-10 11:32 Johan Hovold
  2019-12-10 11:32 ` [PATCH 1/2] can: kvaser_usb: fix interface sanity check Johan Hovold
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Johan Hovold @ 2019-12-10 11:32 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Wolfgang Grandegger, linux-can, netdev, linux-usb, linux-kernel,
	Johan Hovold

We had quite a few driver using the first alternate setting instead of
the current one when doing descriptor sanity checks. This is mostly an
issue on kernels with panic_on_warn set due to a WARN() in
usb_submit_urn(). Since we've started backporting such fixes (e.g. as
reported by syzbot), I've marked these for stable as well.

The second patch here is a related cleanup to prevent future issues.

Johan


Johan Hovold (2):
  can: kvaser_usb: fix interface sanity check
  can: gs_usb: use descriptors of current altsetting

 drivers/net/can/usb/gs_usb.c                      | 4 ++--
 drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 2 +-
 drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c  | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

-- 
2.24.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] can: kvaser_usb: fix interface sanity check
  2019-12-10 11:32 [PATCH 0/2] can: fix USB altsetting bugs Johan Hovold
@ 2019-12-10 11:32 ` Johan Hovold
  2019-12-10 11:32 ` [PATCH 2/2] can: gs_usb: use descriptors of current altsetting Johan Hovold
  2019-12-10 11:40 ` [PATCH 0/2] can: fix USB altsetting bugs Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2019-12-10 11:32 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Wolfgang Grandegger, linux-can, netdev, linux-usb, linux-kernel,
	Johan Hovold, stable, Jimmy Assarsson, Christer Beskow,
	Nicklas Johansson, Martin Henriksson

Make sure to use the current alternate setting when verifying the
interface descriptors to avoid binding to an invalid interface.

Failing to do so could cause the driver to misbehave or trigger a WARN()
in usb_submit_urb() that kernels with panic_on_warn set would choke on.

Fixes: aec5fb2268b7 ("can: kvaser_usb: Add support for Kvaser USB hydra family")
Cc: stable <stable@vger.kernel.org>     # 4.19
Cc: Jimmy Assarsson <extja@kvaser.com>
Cc: Christer Beskow <chbe@kvaser.com>
Cc: Nicklas Johansson <extnj@kvaser.com>
Cc: Martin Henriksson <mh@kvaser.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 2 +-
 drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
index 5fc0be564274..7ab87a758754 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
@@ -1590,7 +1590,7 @@ static int kvaser_usb_hydra_setup_endpoints(struct kvaser_usb *dev)
 	struct usb_endpoint_descriptor *ep;
 	int i;
 
-	iface_desc = &dev->intf->altsetting[0];
+	iface_desc = dev->intf->cur_altsetting;
 
 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
 		ep = &iface_desc->endpoint[i].desc;
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index 07d2f3aa2c02..1c794bb443e1 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -1310,7 +1310,7 @@ static int kvaser_usb_leaf_setup_endpoints(struct kvaser_usb *dev)
 	struct usb_endpoint_descriptor *endpoint;
 	int i;
 
-	iface_desc = &dev->intf->altsetting[0];
+	iface_desc = dev->intf->cur_altsetting;
 
 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
 		endpoint = &iface_desc->endpoint[i].desc;
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] can: gs_usb: use descriptors of current altsetting
  2019-12-10 11:32 [PATCH 0/2] can: fix USB altsetting bugs Johan Hovold
  2019-12-10 11:32 ` [PATCH 1/2] can: kvaser_usb: fix interface sanity check Johan Hovold
@ 2019-12-10 11:32 ` Johan Hovold
  2019-12-10 11:40 ` [PATCH 0/2] can: fix USB altsetting bugs Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2019-12-10 11:32 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Wolfgang Grandegger, linux-can, netdev, linux-usb, linux-kernel,
	Johan Hovold

Make sure to always use the descriptors of the current alternate setting
to avoid future issues when accessing fields that may differ between
settings.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/can/usb/gs_usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 2f74f6704c12..a4b4b742c80c 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -918,7 +918,7 @@ static int gs_usb_probe(struct usb_interface *intf,
 			     GS_USB_BREQ_HOST_FORMAT,
 			     USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
 			     1,
-			     intf->altsetting[0].desc.bInterfaceNumber,
+			     intf->cur_altsetting->desc.bInterfaceNumber,
 			     hconf,
 			     sizeof(*hconf),
 			     1000);
@@ -941,7 +941,7 @@ static int gs_usb_probe(struct usb_interface *intf,
 			     GS_USB_BREQ_DEVICE_CONFIG,
 			     USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
 			     1,
-			     intf->altsetting[0].desc.bInterfaceNumber,
+			     intf->cur_altsetting->desc.bInterfaceNumber,
 			     dconf,
 			     sizeof(*dconf),
 			     1000);
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] can: fix USB altsetting bugs
  2019-12-10 11:32 [PATCH 0/2] can: fix USB altsetting bugs Johan Hovold
  2019-12-10 11:32 ` [PATCH 1/2] can: kvaser_usb: fix interface sanity check Johan Hovold
  2019-12-10 11:32 ` [PATCH 2/2] can: gs_usb: use descriptors of current altsetting Johan Hovold
@ 2019-12-10 11:40 ` Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2019-12-10 11:40 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Wolfgang Grandegger, linux-can, netdev, linux-usb, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 781 bytes --]

On 12/10/19 12:32 PM, Johan Hovold wrote:
> We had quite a few driver using the first alternate setting instead of
> the current one when doing descriptor sanity checks. This is mostly an
> issue on kernels with panic_on_warn set due to a WARN() in
> usb_submit_urn(). Since we've started backporting such fixes (e.g. as
> reported by syzbot), I've marked these for stable as well.
> 
> The second patch here is a related cleanup to prevent future issues.

Applied both to linux-can.

Tnx,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-10 11:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10 11:32 [PATCH 0/2] can: fix USB altsetting bugs Johan Hovold
2019-12-10 11:32 ` [PATCH 1/2] can: kvaser_usb: fix interface sanity check Johan Hovold
2019-12-10 11:32 ` [PATCH 2/2] can: gs_usb: use descriptors of current altsetting Johan Hovold
2019-12-10 11:40 ` [PATCH 0/2] can: fix USB altsetting bugs Marc Kleine-Budde

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).