Skip to contentSkip to conversation

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

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

lore
Share & tools
lore

zhuyan (M)

author
#0 lore raw
Quoted 10 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 3 lines

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

Quoted 7 lines
Quoted 1 line

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

thanks,

greg k-h

In function usb_maxpacket, when ep is NULL, its return value is 0.
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.

Thanks!

Yan Zhu

#1 lore raw
Quoted 13 lines · zhuyan (M)
Quoted 12 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.

Quoted 7 lines
Quoted 5 lines

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

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

Alan Stern

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.