USB: core: replace memdup_user with memdup_array_user in proc_do_submiturb
PATCH 1/1 USB: core: replace memdup_user with memdup_array_user in proc_do_submiturb
Use memdup_array_user() instead of memdup_user() in proc_do_submiturb(). Compared to memdup_user(), memdup_array_user() automatically checks for multiplication overflow. Remove the obsolete local variable 'isofrmlen'.
Return early if an error occurs instead of manually setting 'ret' and using 'goto error'.
No functional changes intended.
--- drivers/usb/core/devio.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/usb/core/devio.c +5 -9
@@ -1624,7 +1624,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurbstruct usb_host_endpoint *ep;struct async *as =NULL ;struct usb_ctrlrequest *dr =NULL ; -unsigned int u, totlen, isofrmlen; +unsigned int u, totlen;int i, ret, num_sgs =0 , ifnum =-1 ;int number_of_packets =0 ;unsigned int stream_id =0 ;
@@ -1745,14 +1745,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurbif (!usb_endpoint_xfer_isoc (&ep->desc))return -EINVAL ; number_of_packets = uurb->number_of_packets; - isofrmlen =sizeof (struct usbdevfs_iso_packet_desc ) * - number_of_packets; - isopkt =memdup_user (iso_frame_desc, isofrmlen); -if (IS_ERR (isopkt)) { - ret =PTR_ERR (isopkt); - isopkt =NULL ; - goto error; - } + isopkt =memdup_array_user (iso_frame_desc, number_of_packets, +sizeof (struct usbdevfs_iso_packet_desc )); +if (IS_ERR (isopkt)) +return PTR_ERR (isopkt);for (totlen = u =0 ; u < number_of_packets; u++) {/* * arbitrary limit need for USB 3.1 Gen2
Signature · 1 line
2.51.0
Greg Kroah-Hartman
maintainerQuoted 3 lines · Thorsten Blum
Use
memdup_array_user()instead ofmemdup_user()inproc_do_submiturb(). Compared tomemdup_user(),memdup_array_user()automatically checks for multiplication overflow. Remove the obsolete local variable 'isofrmlen'.
But there is no chance for overflow here, right?
I'm all for using "proper" functions, but there is no need to go and rewrite existing code for them if you can't test the results. Did you test this?
Quoted 2 lines
Return early if an error occurs instead of manually setting 'ret' and using 'goto error'.
There is no need to do that, please leave the code flow alone as we "know" it works properly as-is.
Quoted 1 line
No functional changes intended.
"intended", but did you succeed? :)
Testing is good, please do that.
thanks,
greg k-h