diff --git a/net_util/src/queue_pair.rs b/net_util/src/queue_pair.rs index 1dbf58b26..d9bd19db3 100644 --- a/net_util/src/queue_pair.rs +++ b/net_util/src/queue_pair.rs @@ -104,6 +104,10 @@ impl TxVirtio { return Err(NetQueuePairError::WriteTap(e)); } + if (result as usize) < vnet_hdr_len() { + return Err(NetQueuePairError::InvalidVirtioNetHeader); + } + self.counter_bytes += Wrapping(result as u64 - vnet_hdr_len() as u64); self.counter_frames += Wrapping(1); @@ -238,6 +242,10 @@ impl RxVirtio { return Err(NetQueuePairError::ReadTap(e)); } + if (result as usize) < vnet_hdr_len() { + return Err(NetQueuePairError::InvalidVirtioNetHeader); + } + // Write num_buffers to guest memory. We simply write 1 as we // never spread the frame over more than one descriptor chain. desc_chain @@ -314,6 +322,8 @@ pub enum NetQueuePairError { QueueAddUsed(virtio_queue::Error), #[error("Descriptor with invalid virtio-net header")] DescriptorInvalidHeader, + #[error("Invalid virtio-net header")] + InvalidVirtioNetHeader, } pub struct NetQueuePair {