Skip to contentSkip to conversation

usbback: correct copy length for partial transfers

PATCH New Juergen Gross 1 participant 1 message Sep 28, 2015 Xen hypervisor interface

lore
Share & tools
lore

Juergen Gross

author maintainer
#0 lore raw

PATCH 1/1 usbback: correct copy length for partial transfers

Commit 72387b3c2252 ("usbback: copy only filled buffers to guest") has introduced an error leading to copying the wrong amount of data to the guest in case of read I/Os with not the complete buffer filled.

Depending on the amount of data read either too much or not enough data was copied: if a buffer segment was filled less than half still some data of the backend kernel could leak into the guest, while a buffer segment filled more than half of it's size wouldn't be copied completely.

Correct this by limiting the to be copied data amount to the rest length of the read data.

drivers/xen/usbback/usbback.c +1 -1
diff -r b4bb467e5c07 drivers/xen/usbback/usbback.c
@@ -213,7 +213,7 @@ static void copy_buff_to_pages(void *buf
 				buf_off += offset - buf_off;
 			}
 			if (buf_off + len > offset + length)
-				len -= offset + length - buf_off;
+				len = offset + length - buf_off;
 			memcpy((void *)vaddr(pending_req, i) + off,
 			       buff + buf_off, len);
 		}