Skip to contentSkip to conversation

wireless: fix division by zero in USB drivers

PATCH In review Johan Hovold 3 participants 8 messages Oct 27, 2021 – Oct 28, 2021

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v2 cover wireless: fix division by zero in USB drivers

This series adds the missing endpoint sanity checks to the wireless USB drivers that were doing packet-size calculations without first making sure that the USB descriptors were sane.

Johan

Changes in v2:
- tighten the sanity checks for the mwifiex firmware-download mode to handle also a missing bulk-out endpoint (noticed by Brian Norris)

Johan Hovold (3):
ath10k: fix division by zero in send path
ath6kl: fix division by zero in send path
mwifiex: fix division by zero in fw download path

 drivers/net/wireless/ath/ath10k/usb.c      |  5 +++++
 drivers/net/wireless/ath/ath6kl/usb.c      |  5 +++++
 drivers/net/wireless/marvell/mwifiex/usb.c | 16 ++++++++++++++++
 3 files changed, 26 insertions(+)
Signature · 1 line
2.32.0
#1 lore raw

PATCH v2 1/3 ath10k: fix division by zero in send path

Add the missing endpoint max-packet sanity check to probe() to avoid division by zero in ath10k_usb_hif_tx_sg() in case a malicious device has broken descriptors (or when doing descriptor fuzz testing).

Note that USB core will reject URBs submitted for endpoints with zero wMaxPacketSize but that drivers doing packet-size calculations still need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip endpoint descriptors with maxpacket=0")).

Fixes 4db66499df91 ("ath10k: add initial USB support")
Cc Erik Stromdahl <[email protected]>
---
 drivers/net/wireless/ath/ath10k/usb.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/ath/ath10k/usb.c +5 -0
index 6d831b098cbb..3d98f19c6ec8 100644
@@ -853,6 +853,11 @@ static int ath10k_usb_setup_pipe_resources(struct ath10k *ar,
 				   le16_to_cpu(endpoint->wMaxPacketSize),
 				   endpoint->bInterval);
 		}
+
+		/* Ignore broken descriptors. */
+		if (usb_endpoint_maxp(endpoint) == 0)
+			continue;
+
 		urbcount = 0;
 
 		pipe_num =
Signature · 1 line
2.32.0
#2 lore raw

Re: [PATCH v2 1/3] ath10k: fix division by zero in send path

Quoted 9 lines · Johan Hovold

Add the missing endpoint max-packet sanity check to probe() to avoid division by zero in ath10k_usb_hif_tx_sg() in case a malicious device has broken descriptors (or when doing descriptor fuzz testing).

Note that USB core will reject URBs submitted for endpoints with zero wMaxPacketSize but that drivers doing packet-size calculations still need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip endpoint descriptors with maxpacket=0")).

Quoted 5 lines
Fixes 4db66499df91 ("ath10k: add initial USB support")
Cc Erik Stromdahl <[email protected]>

2 patches applied to ath-next branch of ath.git, thanks.

a006acb93131 ath10k: fix division by zero in send path c1b9ca365dea ath6kl: fix division by zero in send path

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw

PATCH v2 2/3 ath6kl: fix division by zero in send path

In reply to Johan Hovold

Add the missing endpoint max-packet sanity check to probe() to avoid division by zero in ath10k_usb_hif_tx_sg() in case a malicious device has broken descriptors (or when doing descriptor fuzz testing).

Note that USB core will reject URBs submitted for endpoints with zero wMaxPacketSize but that drivers doing packet-size calculations still need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip endpoint descriptors with maxpacket=0")).

Fixes 9cbee358687e ("ath6kl: add full USB support")
---
 drivers/net/wireless/ath/ath6kl/usb.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/ath/ath6kl/usb.c +5 -0
index bd367b79a4d3..aba70f35e574 100644
@@ -340,6 +340,11 @@ static int ath6kl_usb_setup_pipe_resources(struct ath6kl_usb *ar_usb)
 				   le16_to_cpu(endpoint->wMaxPacketSize),
 				   endpoint->bInterval);
 		}
+
+		/* Ignore broken descriptors. */
+		if (usb_endpoint_maxp(endpoint) == 0)
+			continue;
+
 		urbcount = 0;
 
 		pipe_num =
Signature · 1 line
2.32.0
#4 lore raw

PATCH v2 3/3 mwifiex: fix division by zero in fw download path

In reply to Johan Hovold

Add the missing endpoint sanity checks to probe() to avoid division by zero in mwifiex_write_data_sync() in case a malicious device has broken descriptors (or when doing descriptor fuzz testing).

Only add checks for the firmware-download boot stage, which require both command endpoints, for now. The driver looks like it will handle a missing endpoint during normal operation without oopsing, albeit not very gracefully as it will try to submit URBs to the default pipe and fail.

Note that USB core will reject URBs submitted for endpoints with zero wMaxPacketSize but that drivers doing packet-size calculations still need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip endpoint descriptors with maxpacket=0")).

Fixes 4daffe354366 ("mwifiex: add support for Marvell USB8797 chipset")
Cc Amitkumar Karwar <[email protected]>
---
 drivers/net/wireless/marvell/mwifiex/usb.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/wireless/marvell/mwifiex/usb.c +16 -0
index 426e39d4ccf0..9736aa0ab7fd 100644
@@ -505,6 +505,22 @@ static int mwifiex_usb_probe(struct usb_interface *intf,
 		}
 	}
 
+	switch (card->usb_boot_state) {
+	case USB8XXX_FW_DNLD:
+		/* Reject broken descriptors. */
+		if (!card->rx_cmd_ep || !card->tx_cmd_ep)
+			return -ENODEV;
+		if (card->bulk_out_maxpktsize == 0)
+			return -ENODEV;
+		break;
+	case USB8XXX_FW_READY:
+		/* Assume the driver can handle missing endpoints for now. */
+		break;
+	default:
+		WARN_ON(1);
+		return -ENODEV;
+	}
+
 	usb_set_intfdata(intf, card);
 
 	ret = mwifiex_add_card(card, &card->fw_done, &usb_ops,
Signature · 1 line
2.32.0
maintainer Reviewed-by on v2 3/3
#5 lore raw

Re: [PATCH v2 3/3] mwifiex: fix division by zero in fw download path

drivers/net/wireless/marvell/mwifiex/usb.c static int mwifiex_usb_probe(struct usb_interface *intf, · line 512

Quoted 11 lines · Johan Hovold
drivers/net/wireless/marvell/mwifiex/usb.c +5 -0
@@ -505,6 +505,22 @@ static int mwifiex_usb_probe(struct usb_interface *intf,
                }
        }
 
+       switch (card->usb_boot_state) {
+       case USB8XXX_FW_DNLD:
+               /* Reject broken descriptors. */
+               if (!card->rx_cmd_ep || !card->tx_cmd_ep)
+                       return -ENODEV;

^^ These two conditions are applicable to USB8XXX_FW_READY too, right?

drivers/net/wireless/marvell/mwifiex/usb.c static int mwifiex_usb_probe(struct usb_interface *intf, · line 523

Quoted 11 lines
drivers/net/wireless/marvell/mwifiex/usb.c +11 -0
+               if (card->bulk_out_maxpktsize == 0)
+                       return -ENODEV;
+               break;
+       case USB8XXX_FW_READY:
+               /* Assume the driver can handle missing endpoints for now. */
+               break;
+       default:
+               WARN_ON(1);
+               return -ENODEV;
+       }
+

Anyway, looks pretty good, thanks:

#6 lore raw

Re: [PATCH v2 3/3] mwifiex: fix division by zero in fw download path

Quoted 7 lines · Brian Norris
Quoted 6 lines · Johan Hovold
drivers/net/wireless/marvell/mwifiex/usb.c +0 -0
@@ -505,6 +505,22 @@ static int mwifiex_usb_probe(struct usb_interface *intf,
                }
        }
 
Quoted 7 lines

drivers/net/wireless/marvell/mwifiex/usb.c static int mwifiex_usb_probe(struct usb_interface *intf, · line 512

Quoted 5 lines
drivers/net/wireless/marvell/mwifiex/usb.c +5 -0
+       switch (card->usb_boot_state) {
+       case USB8XXX_FW_DNLD:
+               /* Reject broken descriptors. */
+               if (!card->rx_cmd_ep || !card->tx_cmd_ep)
+                       return -ENODEV;

^^ These two conditions are applicable to USB8XXX_FW_READY too, right?

Right, but I didn't want to add an incomplete set of constraints.

I couldn't find any documentation (e.g. lsusb -v) for what the descriptors are supposed to look like, but judging from the code, something like

	if (!card->rx_cmd_ep || !card->tx_cmd_ep)
		return -ENODEV;
	if (!card->rx_data_ep || !card->port[0].tx_data_ep)
		return -ENODEV;

should do. But I'm not sure about the second tx endpoint, card->port[1].tx_data_ep, for which support was added later and which the driver appears to be able to manage without.

Either way it has nothing to do with the division-by-zero and should be added separately.

Quoted 10 lines

drivers/net/wireless/marvell/mwifiex/usb.c static int mwifiex_usb_probe(struct usb_interface *intf, · line 522

Quoted 10 lines
drivers/net/wireless/marvell/mwifiex/usb.c +10 -0
+               if (card->bulk_out_maxpktsize == 0)
+                       return -ENODEV;
+               break;
+       case USB8XXX_FW_READY:
+               /* Assume the driver can handle missing endpoints for now. */
+               break;
+       default:
+               WARN_ON(1);
+               return -ENODEV;
+       }

Johan

#7 lore raw

Re: [PATCH v2 3/3] mwifiex: fix division by zero in fw download path

In reply to Johan Hovold
Quoted 15 lines · Johan Hovold

Add the missing endpoint sanity checks to probe() to avoid division by zero in mwifiex_write_data_sync() in case a malicious device has broken descriptors (or when doing descriptor fuzz testing).

Only add checks for the firmware-download boot stage, which require both command endpoints, for now. The driver looks like it will handle a missing endpoint during normal operation without oopsing, albeit not very gracefully as it will try to submit URBs to the default pipe and fail.

Note that USB core will reject URBs submitted for endpoints with zero wMaxPacketSize but that drivers doing packet-size calculations still need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip endpoint descriptors with maxpacket=0")).

Quoted 5 lines
Fixes 4daffe354366 ("mwifiex: add support for Marvell USB8797 chipset")
Cc Amitkumar Karwar <[email protected]>

Patch applied to wireless-drivers-next.git, thanks.

89f8765a11d8 mwifiex: fix division by zero in fw download path

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches