Skip to contentSkip to conversation

usb:host: fix divide-by-zero in function fhci_queue_urb

PATCH zhuyan (M) 2 participants 2 messages Apr 17, 2019 USB

lore
Share & tools
lore

zhuyan (M)

author
#0 lore raw
Quoted 16 lines · Alan Stern
Quoted 15 lines · zhuyan (M)
Quoted 14 lines · Greg KH
Quoted 3 lines · zhuyan

In function fhci_queue_urb, the divisor of expression (urb->transfer_buffer_length % usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe))) may be zero.

How can you hit that?

Quoted 4 lines

When it is zero, unexpected results may occur, so it is necessary to ensure that the divisor is not zero.

I need a "Full" name here, not just a single name. Whatever you use to sign documents is good.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

thanks,

greg k-h

In function usb_maxpacket, when ep is NULL, its return value is 0.

fhci_queue_urb() shouldn't use urb->pipe to compute the maxpacket size anyway. It should use usb_endpoint_maxp(&urb->ep->desc).

Currently, fhci_queue_urb(), call usb_maxpacket() multiple times to calculate
the maxpacket size. The usb_maxpacket() will call usb_endpoint_maxp() to
compute the maxpacket size.

zhuyan

Quoted 3 lines
Quoted 3 lines

Then, in function fhci_queue_urb, the divisor of expression (urb->transfer_buffer_length % usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe))) is zero. It will lead to unpredictable results.

#1 lore raw
Quoted 22 lines · zhuyan (M)
Quoted 20 lines · Alan Stern
Quoted 19 lines · zhuyan (M)
Quoted 17 lines · Greg KH
Quoted 3 lines · zhuyan

In function fhci_queue_urb, the divisor of expression (urb->transfer_buffer_length % usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe))) may be zero.

How can you hit that?

Quoted 4 lines

When it is zero, unexpected results may occur, so it is necessary to ensure that the divisor is not zero.

I need a "Full" name here, not just a single name. Whatever you use to sign documents is good.

thanks,

greg k-h

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

In function usb_maxpacket, when ep is NULL, its return value is 0.

fhci_queue_urb() shouldn't use urb->pipe to compute the maxpacket size anyway. It should use usb_endpoint_maxp(&urb->ep->desc).

Currently, fhci_queue_urb(), call usb_maxpacket() multiple times to calculate
the maxpacket size. The usb_maxpacket() will call usb_endpoint_maxp() to
compute the maxpacket size.

I know that. What fhci_queue_urb() is doing is wrong. You should change it: Make it call usb_endpoint_maxp directly instead of calling usb_maxpacket.

Alan Stern