Skip to content

Commit b778f36

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 b778f36

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/migtd/src/migration/session.rs

Lines changed: 13 additions & 5 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();
@@ -986,12 +991,15 @@ pub async fn exchange_msk(info: &MigrationInformation, data: &mut Vec<u8>) -> Re
986991
remote_information.key.clear();
987992
}
988993

994+
#[cfg(feature = "spdm_attestation")]
995+
const SPDM_TIMEOUT: Duration = Duration::from_secs(60); // 60 seconds
996+
989997
#[cfg(feature = "spdm_attestation")]
990998
if info.is_src() {
991999
let mut spdm_requester =
9921000
spdm::spdm_requester(transport).map_err(|_| MigrationResult::SecureSessionError)?;
9931001
with_timeout(
994-
spdm::SPDM_TIMEOUT,
1002+
SPDM_TIMEOUT,
9951003
spdm::spdm_requester_transfer_msk(
9961004
&mut spdm_requester,
9971005
&info.mig_info,
@@ -1006,7 +1014,7 @@ pub async fn exchange_msk(info: &MigrationInformation, data: &mut Vec<u8>) -> Re
10061014
spdm::spdm_responder(transport).map_err(|_| MigrationResult::SecureSessionError)?;
10071015

10081016
with_timeout(
1009-
spdm::SPDM_TIMEOUT,
1017+
SPDM_TIMEOUT,
10101018
spdm::spdm_responder_transfer_msk(
10111019
&mut spdm_responder,
10121020
&info.mig_info,

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)