@@ -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,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 ( ( ) )
0 commit comments