Skip to contentSkip to conversation

cdc_ncm: fix divide-by-zero caused by invalid wMaxPacketSize

PATCH Applied Bjørn Mork 3 participants 3 messages Sep 18, 2019 – Sep 21, 2019

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

PATCH 1/1 cdc_ncm: fix divide-by-zero caused by invalid wMaxPacketSize

Endpoints with zero wMaxPacketSize are not usable for transferring data. Ignore such endpoints when looking for valid in, out and status pipes, to make the driver more robust against invalid and meaningless descriptors.

The wMaxPacketSize of the out pipe is used as divisor. So this change fixes a divide-by-zero bug.

---
#syz test: https://github.com/google/kasan.git f0df5c1b

 drivers/net/usb/cdc_ncm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/usb/cdc_ncm.c +5 -1
index 50c05d0f44cb..00cab3f43a4c 100644
@@ -681,8 +681,12 @@ cdc_ncm_find_endpoints(struct usbnet *dev, struct usb_interface *intf)
 	u8 ep;
 
 	for (ep = 0; ep < intf->cur_altsetting->desc.bNumEndpoints; ep++) {
-
 		e = intf->cur_altsetting->endpoint + ep;
+
+		/* ignore endpoints which cannot transfer data */
+		if (!usb_endpoint_maxp(&e->desc))
+			continue;
+
 		switch (e->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
 		case USB_ENDPOINT_XFER_INT:
 			if (usb_endpoint_dir_in(&e->desc)) {
Signature · 1 line
2.20.1
syzbot
#1 lore raw

Re: divide error in cdc_ncm_update_rxtx_max

syzbot has tested the proposed patch and the reproducer did not trigger crash:

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger crash:

Reported-and-tested-by [email protected]

Tested on:

commit:         f0df5c1b usb-fuzzer: main usb gadget fuzzer driver
git tree:       https://github.com/google/kasan.git
kernel config:  https://syzkaller.appspot.com/x/.config?x=5c6633fa4ed00be5
dashboard link: https://syzkaller.appspot.com/bug?extid=ce366e2b8296e25d84f5
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
patch:          https://syzkaller.appspot.com/x/patch.diff?x=114971b5600000

Note: testing is done by a robot and is best-effort only.

#2 lore raw
In reply to Bjørn Mork
Quoted 10 lines · Bjørn Mork

Endpoints with zero wMaxPacketSize are not usable for transferring data. Ignore such endpoints when looking for valid in, out and status pipes, to make the driver more robust against invalid and meaningless descriptors.

The wMaxPacketSize of the out pipe is used as divisor. So this change fixes a divide-by-zero bug.

Applied, queued, thank you!