mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: config: Add DiskConfig check for device serial length
Signed-off-by: Jinrong Liang <cloudliang@tencent.com>
This commit is contained in:
committed by
Rob Bradford
parent
a336533389
commit
bb6ca56fb0
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2472,6 +2472,7 @@ dependencies = [
|
|||||||
"uuid",
|
"uuid",
|
||||||
"vfio-ioctls",
|
"vfio-ioctls",
|
||||||
"vfio_user",
|
"vfio_user",
|
||||||
|
"virtio-bindings",
|
||||||
"virtio-devices",
|
"virtio-devices",
|
||||||
"virtio-queue",
|
"virtio-queue",
|
||||||
"vm-allocator",
|
"vm-allocator",
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ tracer = { path = "../tracer" }
|
|||||||
uuid = "1.12.1"
|
uuid = "1.12.1"
|
||||||
vfio-ioctls = { workspace = true, default-features = false }
|
vfio-ioctls = { workspace = true, default-features = false }
|
||||||
vfio_user = { workspace = true }
|
vfio_user = { workspace = true }
|
||||||
|
virtio-bindings = { workspace = true }
|
||||||
virtio-devices = { path = "../virtio-devices" }
|
virtio-devices = { path = "../virtio-devices" }
|
||||||
virtio-queue = { workspace = true }
|
virtio-queue = { workspace = true }
|
||||||
vm-allocator = { path = "../vm-allocator" }
|
vm-allocator = { path = "../vm-allocator" }
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use option_parser::{
|
|||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use virtio_bindings::virtio_blk::VIRTIO_BLK_ID_BYTES;
|
||||||
use virtio_devices::block::MINIMUM_BLOCK_QUEUE_SIZE;
|
use virtio_devices::block::MINIMUM_BLOCK_QUEUE_SIZE;
|
||||||
use virtio_devices::{RateLimiterConfig, TokenBucketConfig};
|
use virtio_devices::{RateLimiterConfig, TokenBucketConfig};
|
||||||
|
|
||||||
@@ -221,6 +222,8 @@ pub enum ValidationError {
|
|||||||
LandlockPathDoesNotExist(PathBuf),
|
LandlockPathDoesNotExist(PathBuf),
|
||||||
/// Access provided in landlock-rules in invalid
|
/// Access provided in landlock-rules in invalid
|
||||||
InvalidLandlockAccess(String),
|
InvalidLandlockAccess(String),
|
||||||
|
/// Invalid block device serial length
|
||||||
|
InvalidSerialLength(usize, usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValidationResult<T> = std::result::Result<T, ValidationError>;
|
type ValidationResult<T> = std::result::Result<T, ValidationError>;
|
||||||
@@ -391,6 +394,12 @@ impl fmt::Display for ValidationError {
|
|||||||
InvalidLandlockAccess(s) => {
|
InvalidLandlockAccess(s) => {
|
||||||
write!(f, "{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);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user