Skip to content

Commit 02d3f1a

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 02d3f1a

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

src/migtd/src/migration/session.rs

Lines changed: 41 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,17 @@ 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+
{
852+
const PRE_SESSION_TIMEOUT: Duration = Duration::from_secs(60); // 60 seconds
853+
let remote_policy = Box::pin(with_timeout(
854+
PRE_SESSION_TIMEOUT,
855+
pre_session_data_exchange(&mut transport),
856+
))
857+
.await??;
858+
}
851859

852860
#[cfg(not(feature = "spdm_attestation"))]
853861
{
854-
use core::time::Duration;
855-
856862
const TLS_TIMEOUT: Duration = Duration::from_secs(60); // 60 seconds
857863

858864
let mut remote_information = ExchangeInformation::default();
@@ -987,35 +993,38 @@ pub async fn exchange_msk(info: &MigrationInformation, data: &mut Vec<u8>) -> Re
987993
}
988994

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

10211030
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)