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 <chen.bo@intel.com>
(cherry picked from commit 4d9a2b17a76ad261bfe45b1656d28acb97e0d8e3)
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Bo Chen 2022-11-21 16:43:45 -08:00 committed by Rob Bradford
parent 8e3b351038
commit 59bd682b1f

View File

@ -185,7 +185,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();
@ -312,6 +312,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 {