Skip to contentSkip to conversation

USB: devio: Don't corrupt user memory

PATCH New Dan Carpenter 1 participant 1 message Sep 22, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 USB: devio: Don't corrupt user memory

The user buffer has "uurb->buffer_length" bytes. If the kernel has more information than that, we should truncate it instead of writing past the end of the user's buffer. I added a WARN_ONCE() to help the user debug the issue.

drivers/usb/core/devio.c +5 -1
index 318bb3b96687..4664e543cf2f 100644
@@ -1571,7 +1576,11 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
 			totlen += isopkt[u].length;
 		}
 		u *= sizeof(struct usb_iso_packet_descriptor);
-		uurb->buffer_length = totlen;
+		if (totlen <= uurb->buffer_length)
+			uurb->buffer_length = totlen;
+		else
+			WARN_ONCE(1, "uurb->buffer_length is too short %d vs %d",
+				  totlen, uurb->buffer_length);
 		break;
 
 	default: