From 6c06420a11b35ea0186df129ffae63781111685b Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 12 Aug 2019 15:12:56 +0100 Subject: [PATCH] vm-virtio: net: Fix out-of-range slice panic when under load The numbr of bytes read was being incorrectly increased by the potential length of the end of the sliced data rather than the number of bytes that was in the range. This caused a panic when the the network was under load by using iperf. It's important to note that in the Firecracker code base the function that read_slice() returns the number of bytes read which is used to increment this counter. The VM memory version however only returns the empty unit "()". Fixes: #166 Signed-off-by: Rob Bradford --- vm-virtio/src/net.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vm-virtio/src/net.rs b/vm-virtio/src/net.rs index a4e8ef76f..9182207cd 100644 --- a/vm-virtio/src/net.rs +++ b/vm-virtio/src/net.rs @@ -268,7 +268,8 @@ impl NetEpollHandler { ); match read_result { Ok(_) => { - read_count += limit; + // Increment by number of bytes actually read + read_count += limit - read_count; } Err(e) => { error!("Failed to read slice: {:?}", e);