usb:host: fix divide-by-zero in function fhci_queue_urb
PATCH v2 1/1 usb:host: fix divide-by-zero in function fhci_queue_urb
Quoted 30 lines · Alan Stern
Quoted 28 lines · zhuyan (M)
Quoted 25 lines · Alan Stern
Quoted 14 lines · zhuyan (M)
Quoted 13 lines · Greg KH
Quoted 4 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.
Signed-off-by zhuyan <[email protected]>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 useurb->pipeto compute the maxpacket size anyway. It should useusb_endpoint_maxp(&urb->ep->desc).
Quoted 7 lines
Quoted 3 lines
Currently,
fhci_queue_urb(), callusb_maxpacket()multiple times to calculate the maxpacket size. Theusb_maxpacket()will callusb_endpoint_maxp()to compute the maxpacket size.I know that. What
fhci_queue_urb()is doing is wrong. You should change it:
Make it callusb_endpoint_maxpdirectly instead of callingusb_maxpacket.
From 1996456d0cc17b5ff7746a598ff355b25d13db3e Mon Sep 17 00:00:00 2001
From: zhuyan <[email protected]>
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.
--- drivers/usb/host/fhci-sched.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/usb/host/fhci-sched.c +7 -6
@@ -704,6 +704,7 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb)struct td *td;u8 *data;u16 cnt =0 ; +u16 max_pkt_size =0 ;if (ed ==NULL ) { ed =fhci_get_empty_ed (fhci);
@@ -727,8 +728,7 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb) } ed->speed = (urb->dev->speed ==USB_SPEED_LOW ) ?FHCI_LOW_SPEED :FHCI_FULL_SPEED ; - ed->max_pkt_size =usb_maxpacket (urb->dev, - urb->pipe,usb_pipeout (urb->pipe)); + ed->max_pkt_size =usb_endpoint_maxp (&urb->ep->desc); urb->ep->hcpriv = ed;fhci_dbg (fhci,"new ep speed=%d max_pkt_size=%d\n" , ed->speed, ed->max_pkt_size);
@@ -765,11 +765,12 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb)switch (ed->mode) {case FHCI_TF_BULK : + max_pkt_size =usb_endpoint_maxp (&urb->ep->desc);if (urb->transfer_flags &URB_ZERO_PACKET && urb->transfer_buffer_length >0 && + (max_pkt_size !=0 ) && ((urb->transfer_buffer_length % -usb_maxpacket (urb->dev, urb->pipe, -usb_pipeout (urb->pipe))) ==0 )) + max_pkt_size) ==0 )) urb_state =US_BULK0 ;while (data_len >4096 ) { td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt,
@@ -807,8 +808,8 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb)break ;case FHCI_TF_CTRL : ed->dev_addr =usb_pipedevice (urb->pipe); - ed->max_pkt_size =usb_maxpacket (urb->dev, urb->pipe, -usb_pipeout (urb->pipe)); + ed->max_pkt_size =usb_endpoint_maxp (&urb->ep->desc); +/* setup stage */ td =fhci_td_fill (fhci, urb, urb_priv, ed, cnt++,FHCI_TA_SETUP ,USB_TD_TOGGLE_DATA0 , urb->setup_packet,8 ,0 ,0 , true);
Quoted 81 lines · zhuyan (M)
Quoted 30 lines · Alan Stern
Quoted 28 lines · zhuyan (M)
Quoted 25 lines · Alan Stern
Quoted 14 lines · zhuyan (M)
Quoted 13 lines · Greg KH
Quoted 4 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.
Signed-off-by zhuyan <[email protected]>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 useurb->pipeto compute the maxpacket size anyway. It should useusb_endpoint_maxp(&urb->ep->desc).Quoted 7 lines
Quoted 3 lines
Currently,
fhci_queue_urb(), callusb_maxpacket()multiple times to calculate the maxpacket size. Theusb_maxpacket()will callusb_endpoint_maxp()to compute the maxpacket size.I know that. What
fhci_queue_urb()is doing is wrong. You should change it:
Make it callusb_endpoint_maxpdirectly instead of callingusb_maxpacket.From
1996456d0cc17b5ff7746a598ff355b25d13db3eMon Sep 17 00:00:00 2001
From: zhuyan <[email protected]>
Date: Thu, 18 Apr 2019 00:53:03 +0800
Subject: [PATCH] usb: host: fix divide-by-zero in functionfhci_queue_urb
fhci_queue_urb()shouldn't useurb->pipeto compute the maxpacket size anyway.It should useusb_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 <[email protected]>--- drivers/usb/host/fhci-sched.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/usb/host/fhci-sched.c +2
-2@@ -704,6 +704,7 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb)struct td *td;u8 *data;u16 cnt =0 ; +u16 max_pkt_size =0 ;if (ed ==NULL ) { ed =fhci_get_empty_ed (fhci);@@ -727,8 +728,7 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb) } ed->speed = (urb->dev->speed ==USB_SPEED_LOW ) ?FHCI_LOW_SPEED :FHCI_FULL_SPEED ; - ed->max_pkt_size =usb_maxpacket (urb->dev, - urb->pipe,usb_pipeout (urb->pipe)); + ed->max_pkt_size =usb_endpoint_maxp (&urb->ep->desc); urb->ep->hcpriv = ed;fhci_dbg (fhci,"new ep speed=%d max_pkt_size=%d\n" , ed->speed, ed->max_pkt_size);
drivers/usb/host/fhci-sched.c void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb) · line 771
Quoted 7 lines
drivers/usb/host/fhci-sched.c +2
-0@@ -765,11 +765,12 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb)switch (ed->mode) {case FHCI_TF_BULK : + max_pkt_size =usb_endpoint_maxp (&urb->ep->desc); if (urb->transfer_flags & URB_ZERO_PACKET && urb->transfer_buffer_length > 0 && + (max_pkt_size != 0) &&
Now you shouldn't need to add this extra test.
Alan Stern
Quoted 18 lines
drivers/usb/host/fhci-sched.c +3
-4((urb->transfer_buffer_length % -usb_maxpacket (urb->dev, urb->pipe, - usb_pipeout(urb->pipe))) == 0)) + max_pkt_size) == 0)) urb_state =US_BULK0 ;while (data_len >4096 ) { td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt,@@ -807,8 +808,8 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb)break ;case FHCI_TF_CTRL : ed->dev_addr =usb_pipedevice (urb->pipe); - ed->max_pkt_size =usb_maxpacket (urb->dev, urb->pipe, -usb_pipeout (urb->pipe)); + ed->max_pkt_size =usb_endpoint_maxp (&urb->ep->desc); +/* setup stage */ td =fhci_td_fill (fhci, urb, urb_priv, ed, cnt++,FHCI_TA_SETUP ,USB_TD_TOGGLE_DATA0 , urb->setup_packet,8 ,0 ,0 , true);
Greg KH
maintainerQuoted 48 lines · zhuyan (M)
Quoted 34 lines · Alan Stern
Quoted 23 lines · zhuyan (M)
Quoted 21 lines · Alan Stern
Quoted 20 lines · zhuyan (M)
Quoted 18 lines · Greg KH
Quoted 4 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.
Signed-off-by zhuyan <[email protected]>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 useurb->pipeto compute the maxpacket size anyway. It should useusb_endpoint_maxp(&urb->ep->desc).Currently,
fhci_queue_urb(), callusb_maxpacket()multiple times to calculate the maxpacket size. Theusb_maxpacket()will callusb_endpoint_maxp()to compute the maxpacket size.Quoted 5 lines
I know that. What
fhci_queue_urb()is doing is wrong. You should change it:
Make it callusb_endpoint_maxpdirectly instead of callingusb_maxpacket.From
1996456d0cc17b5ff7746a598ff355b25d13db3eMon Sep 17 00:00:00 2001From: zhuyan <[email protected]>
Date: Thu, 18 Apr 2019 00:53:03 +0800
Subject: [PATCH] usb: host: fix divide-by-zero in functionfhci_queue_urb
fhci_queue_urb()shouldn't useurb->pipeto compute the maxpacket size anyway.It should useusb_endpoint_maxp(&urb->ep->desc).
Quoted 6 lines
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 <[email protected]>
I still need a full name here and on the From: line :(
thanks,
greg k-h