vmm: Introduce Landlock module

This module introduces methods to apply Landlock LSM to cloud-hypervisor
threads.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
This commit is contained in:
Praveen K Paladugu
2024-02-12 19:06:43 +00:00
committed by Liu Wei
parent 1d89f98edf
commit af5a9677c8
4 changed files with 169 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
//
use crate::landlock::LandlockAccess;
pub use crate::vm_config::*;
use clap::ArgMatches;
use option_parser::{
@@ -211,6 +212,8 @@ pub enum ValidationError {
RestoreNetFdCountMismatch(String, usize, usize),
/// Path provided in landlock-rules doesn't exist
LandlockPathDoesNotExist(PathBuf),
/// Access provided in landlock-rules in invalid
InvalidLandlockAccess(String),
}
type ValidationResult<T> = std::result::Result<T, ValidationError>;
@@ -369,6 +372,9 @@ impl fmt::Display for ValidationError {
s.as_path()
)
}
InvalidLandlockAccess(s) => {
write!(f, "{s}")
}
}
}
}
@@ -2361,6 +2367,8 @@ impl LandlockConfig {
if !self.path.exists() {
return Err(ValidationError::LandlockPathDoesNotExist(self.path.clone()));
}
LandlockAccess::try_from(self.access.as_str())
.map_err(|e| ValidationError::InvalidLandlockAccess(e.to_string()))?;
Ok(())
}
}