@@ -13,6 +13,7 @@ use async_io::{AsyncRead, AsyncWrite};
1313use core:: sync:: atomic:: AtomicBool ;
1414#[ cfg( any( feature = "vmcall-interrupt" , feature = "vmcall-raw" ) ) ]
1515use core:: sync:: atomic:: Ordering ;
16+ use core:: time:: Duration ;
1617use core:: { future:: poll_fn, mem:: size_of, task:: Poll } ;
1718#[ cfg( any( feature = "vmcall-interrupt" , feature = "vmcall-raw" ) ) ]
1819use 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 ( ( ) )
0 commit comments