Skip to content

Commit 38d9ba6

Browse files
committed
Wrap the pre-session v2 policy change with timeout
Wrap the pre-session v2 policy change with a timeout to prevent potential hang during pre migration.
1 parent b212d2b commit 38d9ba6

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

src/migtd/src/migration/session.rs

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use async_io::{AsyncRead, AsyncWrite};
1313
use core::sync::atomic::AtomicBool;
1414
#[cfg(any(feature = "vmcall-interrupt", feature = "vmcall-raw"))]
1515
use core::sync::atomic::Ordering;
16+
use core::time::Duration;
1617
use core::{future::poll_fn, mem::size_of, task::Poll};
1718
#[cfg(any(feature = "vmcall-interrupt", feature = "vmcall-raw"))]
1819
use event::VMCALL_SERVICE_FLAG;
@@ -847,12 +848,16 @@ pub async fn exchange_msk(info: &MigrationInformation, data: &mut Vec<u8>) -> Re
847848

848849
// Exchange policy firstly because of the message size limitation of TLS protocol
849850
#[cfg(feature = "policy_v2")]
850-
let remote_policy = Box::pin(pre_session_data_exchange(&mut transport)).await?;
851+
const PRE_SESSION_TIMEOUT: Duration = Duration::from_secs(60); // 60 seconds
852+
#[cfg(feature = "policy_v2")]
853+
let remote_policy = Box::pin(with_timeout(
854+
PRE_SESSION_TIMEOUT,
855+
pre_session_data_exchange(&mut transport),
856+
))
857+
.await??;
851858

852859
#[cfg(not(feature = "spdm_attestation"))]
853860
{
854-
use core::time::Duration;
855-
856861
const TLS_TIMEOUT: Duration = Duration::from_secs(60); // 60 seconds
857862

858863
let mut remote_information = ExchangeInformation::default();
@@ -987,35 +992,38 @@ pub async fn exchange_msk(info: &MigrationInformation, data: &mut Vec<u8>) -> Re
987992
}
988993

989994
#[cfg(feature = "spdm_attestation")]
990-
if info.is_src() {
991-
let mut spdm_requester =
992-
spdm::spdm_requester(transport).map_err(|_| MigrationResult::SecureSessionError)?;
993-
with_timeout(
994-
spdm::SPDM_TIMEOUT,
995-
spdm::spdm_requester_transfer_msk(
996-
&mut spdm_requester,
997-
&info.mig_info,
998-
#[cfg(feature = "policy_v2")]
999-
remote_policy,
1000-
),
1001-
)
1002-
.await??;
1003-
log::info!("MSK exchange completed\n");
1004-
} else {
1005-
let mut spdm_responder =
1006-
spdm::spdm_responder(transport).map_err(|_| MigrationResult::SecureSessionError)?;
1007-
1008-
with_timeout(
1009-
spdm::SPDM_TIMEOUT,
1010-
spdm::spdm_responder_transfer_msk(
1011-
&mut spdm_responder,
1012-
&info.mig_info,
1013-
#[cfg(feature = "policy_v2")]
1014-
remote_policy,
1015-
),
1016-
)
1017-
.await??;
1018-
log::info!("MSK exchange completed\n");
995+
{
996+
const SPDM_TIMEOUT: Duration = Duration::from_secs(60); // 60 seconds
997+
if info.is_src() {
998+
let mut spdm_requester =
999+
spdm::spdm_requester(transport).map_err(|_| MigrationResult::SecureSessionError)?;
1000+
with_timeout(
1001+
SPDM_TIMEOUT,
1002+
spdm::spdm_requester_transfer_msk(
1003+
&mut spdm_requester,
1004+
&info.mig_info,
1005+
#[cfg(feature = "policy_v2")]
1006+
remote_policy,
1007+
),
1008+
)
1009+
.await??;
1010+
log::info!("MSK exchange completed\n");
1011+
} else {
1012+
let mut spdm_responder =
1013+
spdm::spdm_responder(transport).map_err(|_| MigrationResult::SecureSessionError)?;
1014+
1015+
with_timeout(
1016+
SPDM_TIMEOUT,
1017+
spdm::spdm_responder_transfer_msk(
1018+
&mut spdm_responder,
1019+
&info.mig_info,
1020+
#[cfg(feature = "policy_v2")]
1021+
remote_policy,
1022+
),
1023+
)
1024+
.await??;
1025+
log::info!("MSK exchange completed\n");
1026+
}
10191027
}
10201028

10211029
Ok(())

src/migtd/src/spdm/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use async_trait::async_trait;
1616
use codec::Codec;
1717
use codec::Reader;
1818
use codec::Writer;
19-
use core::time::Duration;
2019
use spdmlib::common::SpdmDeviceIo;
2120
use spdmlib::error::*;
2221
use spin::Mutex;
@@ -37,8 +36,6 @@ use crate::migration::MigrationResult;
3736
use crate::migration::MigtdMigrationInformation;
3837
use crate::spdm::vmcall_msg::VMCALL_SPDM_MESSAGE_HEADER_SIZE;
3938

40-
pub const SPDM_TIMEOUT: Duration = Duration::from_secs(60); // 60 seconds
41-
4239
pub struct MigtdTransport<T: AsyncRead + AsyncWrite + Unpin> {
4340
pub transport: T,
4441
}

0 commit comments

Comments
 (0)