Re: [PATCH v2] usb:host: fix divide-by-zero in function fhci_queue_urb

From: Greg KH
Date: Wed Apr 17 2019 - 15:49:08 EST


On Wed, Apr 17, 2019 at 05:05:33PM +0000, zhuyan (M) wrote:
> On Wed, 17 Apr 2019, Alan Stern wrote:
>
> > On Wed, 17 Apr 2019, zhuyan (M) wrote:
> >
> > > On Tue, 16 Apr 2019 11:07:56 -0400, Alan Stern wrote:
> > >
> > > > On Tue, 16 Apr 2019, zhuyan (M) wrote:
> > > > > On Tue, 16 Apr 2019 at 11:45:45 +0200, Greg KH wrote:
> > > > > > On Tue, Apr 09, 2019 at 10:37:12PM +0800, zhuyan wrote:
> > > > > > > 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?
> > > > > >
> > > > > > > When it is zero, unexpected results may occur, so it is
> > > > > > > necessary to ensure that the divisor is not zero.
> > > > > > >
> > > > > > > Signed-off-by: zhuyan <zhuyan34@xxxxxxxxxx>
> > > > > >
> > > > > > 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).
> > >
> > > 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.
> >
>
> >From 1996456d0cc17b5ff7746a598ff355b25d13db3e Mon Sep 17 00:00:00 2001
> From: zhuyan <zhuyan34@xxxxxxxxxx>
> Date: Thu, 18 Apr 2019 00:53:03 +0800
> Subject: [PATCH] usb: host: fix divide-by-zero in function fhci_queue_urb
>
> fhci_queue_urb() shouldn't use urb->pipe to compute the maxpacket
> size anyway.It should use usb_endpoint_maxp(&urb->ep->desc).
>
> 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. When it is zero, unexpected results
> may occur, so it is necessary to ensure that the divisor is not zero.
>
> Signed-off-by: zhuyan <zhuyan34@xxxxxxxxxx>

I still need a full name here and on the From: line :(

thanks,

greg k-h