Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/migtd/src/bin/migtd/cvmemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,23 +381,23 @@ fn parse_commandline_args() {
target_td_uuid[2] as u64,
target_td_uuid[3] as u64,
];
let rebinding_src = if is_source { 1u8 } else { 0u8 };
let migration_source = if is_source { 1u8 } else { 0u8 };

// Queue emulated requests based on selected operation
match operation {
"migration" => {
log::info!(
"Setting up migration flow (EnableLogArea → GetTDReport → StartMigration)\n"
);
set_emulated_start_migration(mig_request_id, rebinding_src, td_uuid, binding_handle);
set_emulated_start_migration(mig_request_id, migration_source, td_uuid, binding_handle);
}
"rebind-prepare" => {
log::info!(
"Setting up rebind-prepare flow (EnableLogArea → GetMigtdData → StartRebinding)\n"
);
set_emulated_start_rebinding(
mig_request_id,
rebinding_src,
migration_source,
0, // MIGTD_REBIND_OP_PREPARE
td_uuid,
binding_handle,
Expand All @@ -409,7 +409,7 @@ fn parse_commandline_args() {
);
set_emulated_start_rebinding(
mig_request_id,
rebinding_src,
migration_source,
1, // MIGTD_REBIND_OP_FINALIZE
td_uuid,
binding_handle,
Expand Down
7 changes: 4 additions & 3 deletions src/migtd/src/mig_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@ mod v2 {
/// Per GHCI 1.5: Verify initMigtdData.MROWNER matches own policy signer key hash
/// and initMigtdData.MROWNERCONFIG <= own policy SVN.
pub fn verify_init_migtd_data_policy_binding(
init_data: &crate::migration::init_data::InitData,
init_td_info: &[u8; crate::migration::TD_INFO_SIZE],
) -> Result<(), PolicyError> {
use crate::config::get_policy_issuer_chain;
use crate::migration::{td_info_mrowner, td_info_mrownerconfig};

let policy = get_verified_policy().ok_or(PolicyError::InvalidParameter)?;
let my_policy_svn = policy.policy_data.get_policy_svn();
Expand All @@ -698,12 +699,12 @@ mod v2 {
let policy_issuer_chain = get_policy_issuer_chain().ok_or(PolicyError::InvalidParameter)?;
let policy_key_hash = crypto::get_policy_signer_key_hash(policy_issuer_chain)
.map_err(|_| PolicyError::InvalidCollateral)?;
if init_data.mrowner() != policy_key_hash {
if td_info_mrowner(init_td_info) != &policy_key_hash {
return Err(PolicyError::PolicyHashMismatch);
}

// Check MROWNERCONFIG (init policy_svn) <= my policy_svn
let init_mrownerconfig = init_data.mrownerconfig();
let init_mrownerconfig = td_info_mrownerconfig(init_td_info);
let mut init_svn_bytes = [0u8; 4];
init_svn_bytes.copy_from_slice(&init_mrownerconfig[..4]);
let init_policy_svn = u32::from_le_bytes(init_svn_bytes);
Expand Down
53 changes: 28 additions & 25 deletions src/migtd/src/migration/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
//
// SPDX-License-Identifier: BSD-2-Clause-Patent

#[cfg(feature = "policy_v2")]
use crate::migration::init_data::InitData;
#[cfg(all(feature = "main", feature = "vmcall-raw", feature = "policy_v2"))]
use crate::migration::rebinding::RebindingInfo;

use super::*;
#[cfg(feature = "vmcall-raw")]
use bitfield_struct::bitfield;
Expand Down Expand Up @@ -260,7 +255,7 @@ pub struct RequestDataBuffer<'a> {
pub enum WaitForRequestResponse {
StartMigration(MigrationInformation),
#[cfg(all(feature = "main", feature = "policy_v2"))]
StartRebinding(RebindingInfo),
StartRebinding(MigtdMigrationInformation),
GetTdReport(ReportInfo),
EnableLogArea(EnableLogAreaInfo),
#[cfg(feature = "policy_v2")]
Expand All @@ -269,8 +264,6 @@ pub enum WaitForRequestResponse {

pub struct MigrationInformation {
pub mig_info: MigtdMigrationInformation,
#[cfg(feature = "policy_v2")]
pub init_migtd_data: Option<InitData>,
#[cfg(all(
not(feature = "vmcall-raw"),
any(feature = "vmcall-vsock", feature = "virtio-vsock")
Expand Down Expand Up @@ -361,16 +354,12 @@ fn create_migration_information(
policy_info_hob: Option<&[u8]>,
) -> Option<MigrationInformation> {
let mig_info_data = hob_lib::get_guid_data(mig_info_hob?)?;
let mig_info = mig_info_data.pread::<MigtdMigrationInformation>(0).ok()?;

// Per GHCI 1.5: if has_init_data == 1, InitData blob follows MigtdMigrationInformation
#[cfg(feature = "policy_v2")]
let init_migtd_data = if mig_info.has_init_data == 1 {
let offset = size_of::<MigtdMigrationInformation>();
InitData::read_from_bytes(mig_info_data.get(offset..)?)
} else {
None
};
let mig_info =
MigtdMigrationInformation::read_from_bytes(mig_info_data.len() as u32, mig_info_data)
.ok()?;
#[cfg(not(feature = "policy_v2"))]
let mig_info = mig_info_data.pread::<MigtdMigrationInformation>(0).ok()?;

#[cfg(any(feature = "vmcall-vsock", feature = "virtio-vsock"))]
let mig_socket_info = hob_lib::get_guid_data(mig_socket_hob?)?
Expand All @@ -392,8 +381,6 @@ fn create_migration_information(

Some(MigrationInformation {
mig_info,
#[cfg(feature = "policy_v2")]
init_migtd_data,
#[cfg(any(feature = "vmcall-vsock", feature = "virtio-vsock"))]
mig_socket_info,
mig_policy,
Expand Down Expand Up @@ -533,7 +520,7 @@ mod test {
#[test]
fn test_read_mig_info_duplicate_mig_info_hob() {
// Create mock HOB data
let mut hob_data = vec![0u8; 1024];
let mut hob_data = vec![0u8; 2048];
let mut offset = 0;

// Add Migration Information HOB
Expand Down Expand Up @@ -710,7 +697,7 @@ mod test {
#[test]
fn test_read_mig_info_invalid_hob_length() {
// Create mock HOB data
let mut hob_data = vec![0u8; 256];
let mut hob_data = vec![0u8; 1024];
let mut offset = 0;

// Add Migration Information HOB
Expand Down Expand Up @@ -738,9 +725,19 @@ mod test {
}

fn create_mig_info_hob(hob: &mut [u8], offset: &mut usize) {
// Under policy_v2, build a short-form HOB payload (header only,
// has_init_data = 0). The wire format also supports a full-size form
// carrying init_td_info when has_init_data == 1; that variant is
// exercised by the parser-level tests in `mod.rs`. Under non-policy_v2
// builds, MigtdMigrationInformation has no init_td_info field and the
// only valid form is the full struct.
#[cfg(feature = "policy_v2")]
let payload_size = MIGTD_MIGRATION_INFO_HEADER_SIZE;
#[cfg(not(feature = "policy_v2"))]
let payload_size = size_of::<MigtdMigrationInformation>();

let mig_info_hob_guid = MIGRATION_INFORMATION_HOB_GUID.as_bytes();
let mig_info_hob =
create_guid_hob(mig_info_hob_guid, size_of::<MigtdMigrationInformation>());
let mig_info_hob = create_guid_hob(mig_info_hob_guid, payload_size);
let mig_info = MigtdMigrationInformation {
mig_request_id: 0,
migration_source: 1,
Expand All @@ -750,11 +747,17 @@ mod test {
binding_handle: 0,
mig_policy_id: 0,
communication_id: 0,
#[cfg(feature = "policy_v2")]
init_td_info: [0u8; TD_INFO_SIZE],
};
hob.pwrite(mig_info_hob, *offset).unwrap();
*offset += size_of::<GuidExtension>();
hob.pwrite(mig_info, *offset).unwrap();
*offset += size_of::<MigtdMigrationInformation>();
// Serialize the full struct to a tmp buffer, then copy only the
// header bytes — the tail init_td_info is omitted in the short form.
let mut tmp = [0u8; size_of::<MigtdMigrationInformation>()];
tmp.pwrite(mig_info, 0).unwrap();
hob[*offset..*offset + payload_size].copy_from_slice(&tmp[..payload_size]);
*offset += payload_size;
}

fn create_socket_info_hob(hob: &mut [u8], offset: &mut usize) {
Expand Down
120 changes: 0 additions & 120 deletions src/migtd/src/migration/init_data.rs

This file was deleted.

Loading
Loading