From 24998c1672001b479386825acf09319b89c650e3 Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Sat, 21 Jun 2025 20:18:37 -0400 Subject: [PATCH] vmm: do not treat libc::MAP_FAILED as a pointer It will likely be safely rejected by the kernel, but it's still wrong. Signed-off-by: Demi Marie Obenour --- vmm/src/memory_manager.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index a3bdea7db..a5ab29718 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -2046,7 +2046,15 @@ impl MemoryManager { file.as_raw_fd(), 0, ) - } as u64; + }; + + if host_addr == libc::MAP_FAILED { + error!( + "Could not add SGX EPC section (size 0x{:x})", + epc_section.size + ); + return Err(Error::SgxEpcRangeAllocation); + } info!( "Adding SGX EPC section: 0x{:x} (0x{:x})", @@ -2056,7 +2064,7 @@ impl MemoryManager { let _mem_slot = self.create_userspace_mapping( epc_section_start, epc_section.size, - host_addr, + host_addr as u64, false, false, false,