diff --git a/src/fw_meta.rs b/src/fw_meta.rs index acb69b3ef..39482fe1f 100644 --- a/src/fw_meta.rs +++ b/src/fw_meta.rs @@ -9,6 +9,7 @@ extern crate alloc; use crate::address::PhysAddr; use crate::cpu::percpu::this_cpu_mut; use crate::error::SvsmError; +use crate::kernel_launch::KernelLaunchInfo; use crate::mm::PerCPUPageMappingGuard; use crate::mm::SIZE_1G; use crate::sev::ghcb::PageStateChangeOp; @@ -414,7 +415,10 @@ fn validate_fw_memory_vec(regions: Vec>) -> Result<(), Sv validate_fw_memory_vec(next_vec) } -pub fn validate_fw_memory(fw_meta: &SevFWMetaData) -> Result<(), SvsmError> { +pub fn validate_fw_memory( + fw_meta: &SevFWMetaData, + launch_info: &KernelLaunchInfo, +) -> Result<(), SvsmError> { // Initalize vector with regions from the FW let mut regions = fw_meta.valid_mem.clone(); @@ -436,6 +440,13 @@ pub fn validate_fw_memory(fw_meta: &SevFWMetaData) -> Result<(), SvsmError> { // Sort regions by base address regions.sort_unstable_by_key(|a| a.start()); + let kernel_region = launch_info.kernel_region(); + for region in regions.iter() { + if region.overlap(&kernel_region) { + panic!("FwMeta region ovelaps with kernel"); + } + } + validate_fw_memory_vec(regions) } diff --git a/src/svsm.rs b/src/svsm.rs index 3d7b163e9..138658f13 100644 --- a/src/svsm.rs +++ b/src/svsm.rs @@ -442,7 +442,7 @@ pub extern "C" fn svsm_main() { print_fw_meta(&fw_meta); - if let Err(e) = validate_fw_memory(&fw_meta) { + if let Err(e) = validate_fw_memory(&fw_meta, &LAUNCH_INFO) { panic!("Failed to validate firmware memory: {:#?}", e); }