From 4d9a2b17a76ad261bfe45b1656d28acb97e0d8e3 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Mon, 21 Nov 2022 16:43:45 -0800 Subject: [PATCH] net_util: queue_pair: Avoid panic and handle error properly This panic was triggered with fuzzing on the virtio-net device. This commits handles the error explicitly to avoid the panic, which also makes the fuzzer happy (as panic is treated as bugs). Signed-off-by: Bo Chen --- net_util/src/queue_pair.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net_util/src/queue_pair.rs b/net_util/src/queue_pair.rs index 0f97ec512..0476868f2 100644 --- a/net_util/src/queue_pair.rs +++ b/net_util/src/queue_pair.rs @@ -186,7 +186,7 @@ impl RxVirtio { .translate_gva(access_platform, desc.len() as usize), 10, ) - .unwrap(); + .ok_or(NetQueuePairError::DescriptorInvalidHeader)?; let mut next_desc = Some(desc); let mut iovecs = Vec::new(); @@ -314,6 +314,8 @@ pub enum NetQueuePairError { QueueEnableNotification(virtio_queue::Error), #[error("Failed to add used index to the queue: {0}")] QueueAddUsed(virtio_queue::Error), + #[error("Descriptor with invalid virtio-net header")] + DescriptorInvalidHeader, } pub struct NetQueuePair {