Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migtd: copy GHCI data to stack memory instead of heap #159

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/migtd/src/migration/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use a global data section instead of stack.

private_mem.copy_from_slice(rsp_mem.as_bytes());

// Parse the response data
// Check the GUID of the reponse
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -394,10 +398,4 @@ impl MigrationSession {

Some(mig_info)
}

fn copy_from_shared_memory(shared: &[u8]) -> Vec<u8> {
let mut private = Vec::new();
private.extend_from_slice(shared);
private
}
}
Loading