Skip to contentSkip to conversation

USB: usbip: fix potential out-of-bounds write

PATCH New Paul Gortmaker 1 participant 1 message May 2, 2016 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: usbip: fix potential out-of-bounds write

From: Ignat Korchagin <[email protected]>

commit b348d7dddb6c4fbfc810b7a0626e8ec9e29f7cbb upstream.

Fix potential out-of-bounds write to urb->transfer_buffer
usbip handles network communication directly in the kernel. When receiving a packet from its peer, usbip code parses headers according to protocol. As part of this parsing urb->actual_length is filled. Since the input for urb->actual_length comes from the network, it should be treated as untrusted. Any entity controlling the network may put any value in the input and the preallocated urb->transfer_buffer may not be large enough to hold the data. Thus, the malicious entity is able to write arbitrary data to kernel memory.

---

[Patch appears in 4.6-rc3 and has been picked up by a couple of the older
3.x releases, but not (yet?) in any of the maintained 4.x kernels. Was not originally tagged with Cc stable ; Fixes CVE-2016-3955 issue.]

 drivers/usb/usbip/usbip_common.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/usb/usbip/usbip_common.c +11 -0
index facaaf003f19..e40da7759a0e 100644
@@ -741,6 +741,17 @@ int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb)
 	if (!(size > 0))
 		return 0;
 
+	if (size > urb->transfer_buffer_length) {
+		/* should not happen, probably malicious packet */
+		if (ud->side == USBIP_STUB) {
+			usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
+			return 0;
+		} else {
+			usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
+			return -EPIPE;
+		}
+	}
+
 	ret = usbip_recv(ud->tcp_socket, urb->transfer_buffer, size);
 	if (ret != size) {
 		dev_err(&urb->dev->dev, "recv xbuf, %d\n", ret);
Signature · 1 line
2.5.0