diff --git a/Cargo.lock b/Cargo.lock index ee6c1fecf..ec831c736 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2472,6 +2472,7 @@ dependencies = [ "uuid", "vfio-ioctls", "vfio_user", + "virtio-bindings", "virtio-devices", "virtio-queue", "vm-allocator", diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index 55d104d62..40d286f1b 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -71,6 +71,7 @@ tracer = { path = "../tracer" } uuid = "1.12.1" vfio-ioctls = { workspace = true, default-features = false } vfio_user = { workspace = true } +virtio-bindings = { workspace = true } virtio-devices = { path = "../virtio-devices" } virtio-queue = { workspace = true } vm-allocator = { path = "../vm-allocator" } diff --git a/vmm/src/config.rs b/vmm/src/config.rs index d7c0f41e7..89f86ab71 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -14,6 +14,7 @@ use option_parser::{ }; use serde::{Deserialize, Serialize}; use thiserror::Error; +use virtio_bindings::virtio_blk::VIRTIO_BLK_ID_BYTES; use virtio_devices::block::MINIMUM_BLOCK_QUEUE_SIZE; use virtio_devices::{RateLimiterConfig, TokenBucketConfig}; @@ -221,6 +222,8 @@ pub enum ValidationError { LandlockPathDoesNotExist(PathBuf), /// Access provided in landlock-rules in invalid InvalidLandlockAccess(String), + /// Invalid block device serial length + InvalidSerialLength(usize, usize), } type ValidationResult = std::result::Result; @@ -391,6 +394,12 @@ impl fmt::Display for ValidationError { InvalidLandlockAccess(s) => { write!(f, "{s}") } + InvalidSerialLength(actual, max) => { + write!( + f, + "Block device serial length ({actual}) exceeds maximum allowed length ({max})" + ) + } } } } @@ -1358,6 +1367,16 @@ impl DiskConfig { return Err(ValidationError::InvalidRateLimiterGroup); } + // Check Block device serial length + if let Some(ref serial) = self.serial { + if serial.len() > VIRTIO_BLK_ID_BYTES as usize { + return Err(ValidationError::InvalidSerialLength( + serial.len(), + VIRTIO_BLK_ID_BYTES as usize, + )); + } + } + Ok(()) } }