mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Enable Landlock on vmm thread
Add file/dir paths from landlock-rules arguments to ruleset. Invoke apply_landlock on VmConfig to apply config specific rules to ruleset. Once done, any threads spawned by vmm thread will be automatically sandboxed with the ruleset in vmm thread. Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
This commit is contained in:
committed by
Liu Wei
parent
b3e5738b40
commit
249e362c70
@@ -675,6 +675,7 @@ impl Vmm {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn new(
|
fn new(
|
||||||
vmm_version: VmmVersionInfo,
|
vmm_version: VmmVersionInfo,
|
||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
@@ -1250,6 +1251,11 @@ impl Vmm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn apply_landlock(vm_config: Arc<Mutex<VmConfig>>) -> result::Result<(), LandlockError> {
|
||||||
|
vm_config.lock().unwrap().apply_landlock()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
impl RequestHandler for Vmm {
|
impl RequestHandler for Vmm {
|
||||||
fn vm_create(&mut self, config: Arc<Mutex<VmConfig>>) -> result::Result<(), VmError> {
|
fn vm_create(&mut self, config: Arc<Mutex<VmConfig>>) -> result::Result<(), VmError> {
|
||||||
// We only store the passed VM config.
|
// We only store the passed VM config.
|
||||||
@@ -1258,6 +1264,18 @@ impl RequestHandler for Vmm {
|
|||||||
self.vm_config = Some(config);
|
self.vm_config = Some(config);
|
||||||
self.console_info =
|
self.console_info =
|
||||||
Some(pre_create_console_devices(self).map_err(VmError::CreateConsoleDevices)?);
|
Some(pre_create_console_devices(self).map_err(VmError::CreateConsoleDevices)?);
|
||||||
|
|
||||||
|
if self
|
||||||
|
.vm_config
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.landlock_enable
|
||||||
|
{
|
||||||
|
apply_landlock(self.vm_config.as_ref().unwrap().clone())
|
||||||
|
.map_err(VmError::ApplyLandlock)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(VmError::VmAlreadyCreated)
|
Err(VmError::VmAlreadyCreated)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use crate::device_tree::DeviceTree;
|
|||||||
use crate::gdb::{Debuggable, DebuggableError, GdbRequestPayload, GdbResponsePayload};
|
use crate::gdb::{Debuggable, DebuggableError, GdbRequestPayload, GdbResponsePayload};
|
||||||
#[cfg(feature = "igvm")]
|
#[cfg(feature = "igvm")]
|
||||||
use crate::igvm::igvm_loader;
|
use crate::igvm::igvm_loader;
|
||||||
|
use crate::landlock::LandlockError;
|
||||||
use crate::memory_manager::{
|
use crate::memory_manager::{
|
||||||
Error as MemoryManagerError, MemoryManager, MemoryManagerSnapshotData,
|
Error as MemoryManagerError, MemoryManager, MemoryManagerSnapshotData,
|
||||||
};
|
};
|
||||||
@@ -122,6 +123,9 @@ pub enum Error {
|
|||||||
#[error("Cannot load the kernel command line in memory: {0}")]
|
#[error("Cannot load the kernel command line in memory: {0}")]
|
||||||
LoadCmdLine(#[source] linux_loader::loader::Error),
|
LoadCmdLine(#[source] linux_loader::loader::Error),
|
||||||
|
|
||||||
|
#[error("Failed to apply landlock config during vm_create: {0}")]
|
||||||
|
ApplyLandlock(#[source] LandlockError),
|
||||||
|
|
||||||
#[error("Cannot modify the kernel command line: {0}")]
|
#[error("Cannot modify the kernel command line: {0}")]
|
||||||
CmdLineInsertStr(#[source] linux_loader::cmdline::Error),
|
CmdLineInsertStr(#[source] linux_loader::cmdline::Error),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user