Skip to content

Commit

Permalink
fw_meta: check that firmware memory regions do not overlap with kernel
Browse files Browse the repository at this point in the history
Check that the memory regions provided by the SEV firmware metadata do
not overlap with kernel memory before validating them. Not doing this
could lead to the SVSM doubly validating its own memory, which allows
for remapping attacks.

Fixes: #114
Signed-off-by: Carlos López <[email protected]>
  • Loading branch information
00xc committed Oct 30, 2023
1 parent ea64321 commit b6d1f2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/fw_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -414,7 +415,10 @@ fn validate_fw_memory_vec(regions: Vec<MemoryRegion<PhysAddr>>) -> 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();

Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit b6d1f2c

Please sign in to comment.