vmm: limit VSOCK CIDs to 32 bits

The VIRTIO specification[1] says:

> The upper 32 bits of the CID are reserved and zeroed.

We should therefore not allow the user to supply a VSOCK CID with
those bits set.  To accomplish this, limit the public API of the
virtio-vsock device to only accept 32-bit CIDs, while still using
64-bit CIDs internally since that's how virtio-vsock works.

[1]: https://docs.oasis-open.org/virtio/virtio/v1.2/csd01/virtio-v1.2-csd01.html#x1-4400004

Signed-off-by: Alyssa Ross <hi@alyssa.is>
(cherry picked from commit 451d3fb2f0)
This commit is contained in:
Alyssa Ross
2024-01-10 16:00:54 +01:00
committed by Bo Chen
parent f58f9cf16a
commit 71708c9794
5 changed files with 15 additions and 15 deletions
+2 -2
View File
@@ -154,7 +154,7 @@ pub enum ValidationError {
/// Need shared memory for vfio-user
UserDevicesRequireSharedMemory,
/// VSOCK Context Identifier has a special meaning, unsuitable for a VM.
VsockSpecialCid(u64),
VsockSpecialCid(u32),
/// Memory zone is reused across NUMA nodes
MemoryZoneReused(String, u32, u32),
/// Invalid number of PCI segments
@@ -2071,7 +2071,7 @@ impl VmConfig {
}
if let Some(vsock) = &self.vsock {
if [u32::MAX as u64, 0, 1, 2].contains(&vsock.cid) {
if [!0, 0, 1, 2].contains(&vsock.cid) {
return Err(ValidationError::VsockSpecialCid(vsock.cid));
}
}
+1 -1
View File
@@ -501,7 +501,7 @@ pub fn default_vdpaconfig_num_queues() -> usize {
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
pub struct VsockConfig {
pub cid: u64,
pub cid: u32,
pub socket: PathBuf,
#[serde(default)]
pub iommu: bool,