mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Introduce landlock cmdline parameter
Users can use this cmdline option to enable/disable Landlock based sandboxing while running cloud-hypervisor. Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
This commit is contained in:
committed by
Liu Wei
parent
c50ea2c708
commit
287dbd4fc9
@@ -190,6 +190,7 @@ impl RequestHandler for StubApiRequestHandler {
|
|||||||
platform: None,
|
platform: None,
|
||||||
tpm: None,
|
tpm: None,
|
||||||
preserved_fds: None,
|
preserved_fds: None,
|
||||||
|
landlock_enable: false,
|
||||||
})),
|
})),
|
||||||
state: VmState::Running,
|
state: VmState::Running,
|
||||||
memory_actual_size: 0,
|
memory_actual_size: 0,
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@@ -271,6 +271,17 @@ fn create_app(default_vcpus: String, default_memory: String, default_rng: String
|
|||||||
.num_args(1..)
|
.num_args(1..)
|
||||||
.group("vm-config"),
|
.group("vm-config"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("landlock")
|
||||||
|
.long("landlock")
|
||||||
|
.num_args(0)
|
||||||
|
.help(
|
||||||
|
"enable/disable Landlock.",
|
||||||
|
)
|
||||||
|
.action(ArgAction::SetTrue)
|
||||||
|
.default_value("false")
|
||||||
|
.group("vm-config"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("net")
|
Arg::new("net")
|
||||||
.long("net")
|
.long("net")
|
||||||
@@ -1032,6 +1043,7 @@ mod unit_tests {
|
|||||||
platform: None,
|
platform: None,
|
||||||
tpm: None,
|
tpm: None,
|
||||||
preserved_fds: None,
|
preserved_fds: None,
|
||||||
|
landlock_enable: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(expected_vm_config, result_vm_config);
|
assert_eq!(expected_vm_config, result_vm_config);
|
||||||
|
|||||||
@@ -472,6 +472,7 @@ pub struct VmParams<'a> {
|
|||||||
pub igvm: Option<&'a str>,
|
pub igvm: Option<&'a str>,
|
||||||
#[cfg(feature = "sev_snp")]
|
#[cfg(feature = "sev_snp")]
|
||||||
pub host_data: Option<&'a str>,
|
pub host_data: Option<&'a str>,
|
||||||
|
pub landlock_enable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VmParams<'a> {
|
impl<'a> VmParams<'a> {
|
||||||
@@ -537,6 +538,7 @@ impl<'a> VmParams<'a> {
|
|||||||
let igvm = args.get_one::<String>("igvm").map(|x| x as &str);
|
let igvm = args.get_one::<String>("igvm").map(|x| x as &str);
|
||||||
#[cfg(feature = "sev_snp")]
|
#[cfg(feature = "sev_snp")]
|
||||||
let host_data = args.get_one::<String>("host-data").map(|x| x as &str);
|
let host_data = args.get_one::<String>("host-data").map(|x| x as &str);
|
||||||
|
let landlock_enable = args.get_flag("landlock");
|
||||||
VmParams {
|
VmParams {
|
||||||
cpus,
|
cpus,
|
||||||
memory,
|
memory,
|
||||||
@@ -574,6 +576,7 @@ impl<'a> VmParams<'a> {
|
|||||||
igvm,
|
igvm,
|
||||||
#[cfg(feature = "sev_snp")]
|
#[cfg(feature = "sev_snp")]
|
||||||
host_data,
|
host_data,
|
||||||
|
landlock_enable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2854,6 +2857,7 @@ impl VmConfig {
|
|||||||
platform,
|
platform,
|
||||||
tpm,
|
tpm,
|
||||||
preserved_fds: None,
|
preserved_fds: None,
|
||||||
|
landlock_enable: vm_params.landlock_enable,
|
||||||
};
|
};
|
||||||
config.validate().map_err(Error::Validation)?;
|
config.validate().map_err(Error::Validation)?;
|
||||||
Ok(config)
|
Ok(config)
|
||||||
@@ -3778,6 +3782,7 @@ mod tests {
|
|||||||
..net_fixture()
|
..net_fixture()
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
|
landlock_enable: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let valid_config = RestoreConfig {
|
let valid_config = RestoreConfig {
|
||||||
@@ -3966,6 +3971,7 @@ mod tests {
|
|||||||
platform: None,
|
platform: None,
|
||||||
tpm: None,
|
tpm: None,
|
||||||
preserved_fds: None,
|
preserved_fds: None,
|
||||||
|
landlock_enable: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(valid_config.validate().is_ok());
|
assert!(valid_config.validate().is_ok());
|
||||||
|
|||||||
@@ -2189,6 +2189,7 @@ mod unit_tests {
|
|||||||
platform: None,
|
platform: None,
|
||||||
tpm: None,
|
tpm: None,
|
||||||
preserved_fds: None,
|
preserved_fds: None,
|
||||||
|
landlock_enable: false,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -645,4 +645,6 @@ pub struct VmConfig {
|
|||||||
// valid, and will be closed when the holding VmConfig instance is destroyed.
|
// valid, and will be closed when the holding VmConfig instance is destroyed.
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub preserved_fds: Option<Vec<i32>>,
|
pub preserved_fds: Option<Vec<i32>>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub landlock_enable: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user