net_util: queue_pair: Handle RX short read gracefully

When readv returns fewer bytes than vnet_hdr_len the frame is
truncated. Report the truncated length to the guest in the used
ring instead of returning a fatal InvalidVirtioNetHeader error.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-05 14:44:42 +02:00
committed by Rob Bradford
parent c71a8ea8dd
commit 945e1f2654

View File

@@ -293,7 +293,15 @@ impl RxVirtio {
return Err(NetQueuePairError::ReadTap(e));
}
} else if (result as usize) < vnet_hdr_len() {
return Err(NetQueuePairError::InvalidVirtioNetHeader);
error!(
"net: rx: buffer too short for virtio_net_hdr ({result} < {})",
vnet_hdr_len()
);
desc_chain
.memory()
.write_obj(0u16, num_buffers_addr)
.map_err(NetQueuePairError::GuestMemory)?;
0
} else {
// Write num_buffers to guest memory. Always 1 because the
// frame is never spread over more than one descriptor chain.