From 22a60c24761cdad6796f51905dbf9e2b9741b2d4 Mon Sep 17 00:00:00 2001 From: Jiaqi Gao Date: Wed, 21 Feb 2024 07:27:53 -0500 Subject: [PATCH] migtd: copy GHCI data to stack memory instead of heap Signed-off-by: Jiaqi Gao --- src/migtd/src/migration/session.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/migtd/src/migration/session.rs b/src/migtd/src/migration/session.rs index 31cf2809..8cb6d78c 100644 --- a/src/migtd/src/migration/session.rs +++ b/src/migtd/src/migration/session.rs @@ -18,6 +18,7 @@ use crate::ratls; const TDCS_FIELD_MIG_DEC_KEY: u64 = 0x9810_0003_0000_0010; const TDCS_FIELD_MIG_ENC_KEY: u64 = 0x9810_0003_0000_0018; const MSK_SIZE: usize = 32; +const GHCI_PAGE_SIZE: usize = 4096; pub struct MigrationInformation { pub mig_info: MigtdMigrationInformation, @@ -89,7 +90,8 @@ impl MigrationSession { #[cfg(not(feature = "vmcall-interrupt"))] tdx::tdvmcall_service(cmd_mem.as_bytes(), rsp_mem.as_mut_bytes(), 0, 0)?; - let private_mem = Self::copy_from_shared_memory(rsp_mem.as_bytes()); + let mut private_mem = [0u8; GHCI_PAGE_SIZE]; + private_mem.copy_from_slice(rsp_mem.as_bytes()); // Parse the response data // Check the GUID of the reponse @@ -148,7 +150,8 @@ impl MigrationSession { #[cfg(not(feature = "vmcall-interrupt"))] tdx::tdvmcall_service(cmd_mem.as_bytes(), rsp_mem.as_mut_bytes(), 0, 0)?; - let private_mem = Self::copy_from_shared_memory(rsp_mem.as_bytes()); + let mut private_mem = [0u8; GHCI_PAGE_SIZE]; + private_mem.copy_from_slice(rsp_mem.as_bytes()); // Parse out the response data let rsp = VmcallServiceResponse::try_read(private_mem.as_bytes()) @@ -255,7 +258,8 @@ impl MigrationSession { tdx::tdvmcall_service(cmd_mem.as_bytes(), rsp_mem.as_mut_bytes(), 0, 0)?; - let private_mem = Self::copy_from_shared_memory(rsp_mem.as_bytes()); + let mut private_mem = [0u8; GHCI_PAGE_SIZE]; + private_mem.copy_from_slice(rsp_mem.as_bytes()); // Parse the response data // Check the GUID of the reponse @@ -394,10 +398,4 @@ impl MigrationSession { Some(mig_info) } - - fn copy_from_shared_memory(shared: &[u8]) -> Vec { - let mut private = Vec::new(); - private.extend_from_slice(shared); - private - } }