can: fix USB altsetting bugs
Subsystems (5)
cover can: fix USB altsetting bugs
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(-)
Signature · 1 line
2.24.0
PATCH 1/2 can: kvaser_usb: fix interface sanity check
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.
--- 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(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +1 -1
@@ -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;
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +1 -1
@@ -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;
Signature · 1 line
2.24.0
PATCH 2/2 can: gs_usb: use descriptors of current altsetting
In reply to Johan HovoldMake sure to always use the descriptors of the current alternate setting to avoid future issues when accessing fields that may differ between settings.
--- drivers/net/can/usb/gs_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/gs_usb.c +2 -2
@@ -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);
Signature · 1 line
2.24.0
Quoted 7 lines · 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_warnset due to aWARN()inusb_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
Signature · 4 lines
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 |