From 17fefa1e4535001e7a98ad2105d79f514442412e Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 5 May 2026 14:42:49 +0200 Subject: [PATCH] net_util: queue_pair: Handle TX writev EINVAL gracefully When writev to the TAP returns EINVAL the guest submitted a malformed packet. Drop it and continue instead of killing the worker thread. Signed-off-by: Anatol Belski --- net_util/src/queue_pair.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/net_util/src/queue_pair.rs b/net_util/src/queue_pair.rs index 33b49a0c6..e7028b2f9 100644 --- a/net_util/src/queue_pair.rs +++ b/net_util/src/queue_pair.rs @@ -118,18 +118,22 @@ impl TxVirtio { retry_write = true; break; } - error!("net: tx: failed writing to tap: {e}"); - return Err(NetQueuePairError::WriteTap(e)); - } - if (result as usize) < vnet_hdr_len() { + if e.raw_os_error() == Some(libc::EINVAL) { + error!("net: tx: dropping malformed packet: {e}"); + 0 + } else { + error!("net: tx: failed writing to tap: {e}"); + return Err(NetQueuePairError::WriteTap(e)); + } + } else if (result as usize) < vnet_hdr_len() { return Err(NetQueuePairError::InvalidVirtioNetHeader); + } else { + self.counter_bytes += Wrapping(result as u64 - vnet_hdr_len() as u64); + self.counter_frames += Wrapping(1); + + result as u64 } - - self.counter_bytes += Wrapping(result as u64 - vnet_hdr_len() as u64); - self.counter_frames += Wrapping(1); - - result as u64 }; // For the sake of simplicity (similar to the RX rate limiting), we always