Do not panic but return error for failed dcap ioctl
This commit is contained in:
		
							parent
							
								
									8e9f1fb933
								
							
						
					
					
						commit
						8efde3915c
					
				| @ -154,7 +154,11 @@ impl DevSgx { | ||||
|             #[cfg(feature = "dcap")] | ||||
|             SGX_CMD_NUM_GET_DCAP_QUOTE_SIZE => { | ||||
|                 let arg = nonbuiltin_cmd.arg_mut::<u32>()?; | ||||
|                 let quote_size = SGX_DCAP_QUOTE_GENERATOR.get_quote_size(); | ||||
|                 if SGX_DCAP_QUOTE_GENERATOR.is_none() { | ||||
|                     return_errno!(EIO, "DCAP device not ready"); | ||||
|                 } | ||||
| 
 | ||||
|                 let quote_size = SGX_DCAP_QUOTE_GENERATOR.unwrap().get_quote_size(); | ||||
|                 unsafe { | ||||
|                     *arg = quote_size; | ||||
|                 } | ||||
| @ -166,13 +170,18 @@ impl DevSgx { | ||||
|                 let input_len = unsafe { *arg.quote_size }; | ||||
|                 check_mut_array(arg.quote_buf, input_len as usize)?; | ||||
| 
 | ||||
|                 let quote_size = SGX_DCAP_QUOTE_GENERATOR.get_quote_size(); | ||||
|                 if SGX_DCAP_QUOTE_GENERATOR.is_none() { | ||||
|                     return_errno!(EIO, "DCAP device not ready"); | ||||
|                 } | ||||
| 
 | ||||
|                 let quote_size = SGX_DCAP_QUOTE_GENERATOR.unwrap().get_quote_size(); | ||||
|                 if input_len < quote_size { | ||||
|                     return_errno!(EINVAL, "provided quote is too small"); | ||||
|                 } | ||||
| 
 | ||||
|                 let quote = | ||||
|                     SGX_DCAP_QUOTE_GENERATOR.generate_quote(unsafe { &*arg.report_data })?; | ||||
|                 let quote = SGX_DCAP_QUOTE_GENERATOR | ||||
|                     .unwrap() | ||||
|                     .generate_quote(unsafe { &*arg.report_data })?; | ||||
|                 let mut input_quote_buf = | ||||
|                     unsafe { std::slice::from_raw_parts_mut(arg.quote_buf, quote_size as usize) }; | ||||
|                 input_quote_buf.copy_from_slice("e); | ||||
| @ -180,7 +189,14 @@ impl DevSgx { | ||||
|             #[cfg(feature = "dcap")] | ||||
|             SGX_CMD_NUM_GET_DCAP_SUPPLEMENTAL_SIZE => { | ||||
|                 let arg = nonbuiltin_cmd.arg_mut::<u32>()?; | ||||
|                 let supplemental_size = SGX_DCAP_QUOTE_VERIFIER.get_supplemental_data_size(); | ||||
| 
 | ||||
|                 if SGX_DCAP_QUOTE_VERIFIER.is_none() { | ||||
|                     return_errno!(EIO, "DCAP device not ready"); | ||||
|                 } | ||||
| 
 | ||||
|                 let supplemental_size = SGX_DCAP_QUOTE_VERIFIER | ||||
|                     .unwrap() | ||||
|                     .get_supplemental_data_size(); | ||||
|                 unsafe { | ||||
|                     *arg = supplemental_size; | ||||
|                 } | ||||
| @ -189,7 +205,14 @@ impl DevSgx { | ||||
|             SGX_CMD_NUM_VER_DCAP_QUOTE => { | ||||
|                 let arg = nonbuiltin_cmd.arg_mut::<IoctlVerDCAPQuoteArg>()?; | ||||
|                 let quote_size = arg.quote_size as usize; | ||||
|                 let supplemental_size = SGX_DCAP_QUOTE_VERIFIER.get_supplemental_data_size(); | ||||
| 
 | ||||
|                 if SGX_DCAP_QUOTE_VERIFIER.is_none() { | ||||
|                     return_errno!(EIO, "DCAP device not ready"); | ||||
|                 } | ||||
| 
 | ||||
|                 let supplemental_size = SGX_DCAP_QUOTE_VERIFIER | ||||
|                     .unwrap() | ||||
|                     .get_supplemental_data_size(); | ||||
|                 check_array(arg.quote_buf, quote_size)?; | ||||
|                 let supplemental_slice = if !arg.supplemental_data.is_null() { | ||||
|                     check_array(arg.supplemental_data, arg.supplemental_data_size as usize)?; | ||||
| @ -210,7 +233,9 @@ impl DevSgx { | ||||
|                 let input_quote_buf = | ||||
|                     unsafe { std::slice::from_raw_parts(arg.quote_buf, quote_size) }; | ||||
|                 let (collateral_expiration_status, quote_verification_result, supplemental_data) = | ||||
|                     SGX_DCAP_QUOTE_VERIFIER.verify_quote(input_quote_buf)?; | ||||
|                     SGX_DCAP_QUOTE_VERIFIER | ||||
|                         .unwrap() | ||||
|                         .verify_quote(input_quote_buf)?; | ||||
| 
 | ||||
|                 unsafe { | ||||
|                     *arg.collateral_expiration_status = collateral_expiration_status; | ||||
| @ -236,9 +261,10 @@ lazy_static! { | ||||
| 
 | ||||
| #[cfg(feature = "dcap")] | ||||
| lazy_static! { | ||||
|     pub static ref SGX_DCAP_QUOTE_GENERATOR: SgxDCAPQuoteGenerator = | ||||
|     pub static ref SGX_DCAP_QUOTE_GENERATOR: Option<SgxDCAPQuoteGenerator> = | ||||
|         { SgxDCAPQuoteGenerator::new() }; | ||||
|     pub static ref SGX_DCAP_QUOTE_VERIFIER: SgxDCAPQuoteVerifier = { SgxDCAPQuoteVerifier::new() }; | ||||
|     pub static ref SGX_DCAP_QUOTE_VERIFIER: Option<SgxDCAPQuoteVerifier> = | ||||
|         { SgxDCAPQuoteVerifier::new() }; | ||||
| } | ||||
| 
 | ||||
| #[repr(C)] | ||||
|  | ||||
| @ -1,34 +1,37 @@ | ||||
| use super::*; | ||||
| pub use sgx_types::{sgx_ql_qv_result_t, sgx_quote3_error_t, sgx_report_data_t, sgx_target_info_t}; | ||||
| 
 | ||||
| #[derive(Copy, Clone)] | ||||
| pub struct QuoteGenerator { | ||||
|     qe_target_info: sgx_target_info_t, | ||||
|     quote_size: u32, | ||||
| } | ||||
| 
 | ||||
| impl QuoteGenerator { | ||||
|     pub fn new() -> Self { | ||||
|     pub fn new() -> Option<Self> { | ||||
|         let mut qe_target_info = sgx_target_info_t::default(); | ||||
|         let mut quote_size: u32 = 0; | ||||
|         let mut sgx_status = sgx_status_t::SGX_SUCCESS; | ||||
|         let mut qe3_ret = sgx_quote3_error_t::SGX_QL_SUCCESS; | ||||
| 
 | ||||
|         unsafe { | ||||
|             let mut qe3_ret = sgx_quote3_error_t::SGX_QL_SUCCESS; | ||||
|             let sgx_status = occlum_ocall_init_dcap_quote_generator( | ||||
|             sgx_status = occlum_ocall_init_dcap_quote_generator( | ||||
|                 &mut qe3_ret, | ||||
|                 &mut qe_target_info, | ||||
|                 &mut quote_size, | ||||
|             ); | ||||
|             assert_eq!(sgx_status_t::SGX_SUCCESS, sgx_status); | ||||
|             assert_eq!( | ||||
|                 sgx_quote3_error_t::SGX_QL_SUCCESS, | ||||
|                 qe3_ret, | ||||
|                 "fail to launch QE" | ||||
|             ); | ||||
|         } | ||||
| 
 | ||||
|         Self { | ||||
|             qe_target_info, | ||||
|             quote_size, | ||||
|         if sgx_status != sgx_status_t::SGX_SUCCESS || qe3_ret != sgx_quote3_error_t::SGX_QL_SUCCESS | ||||
|         { | ||||
|             error!("Init dcap quote generator return {}", sgx_status); | ||||
|             error!("DCAP quote qe3_ret {}", qe3_ret); | ||||
|             None | ||||
|         } else { | ||||
|             Some(Self { | ||||
|                 qe_target_info, | ||||
|                 quote_size, | ||||
|             }) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| use super::*; | ||||
| 
 | ||||
| #[derive(Copy, Clone)] | ||||
| pub struct QuoteVerifier { | ||||
|     supplemental_data_size: u32, | ||||
| } | ||||
| @ -9,15 +10,20 @@ pub struct QuoteVerifier { | ||||
| const QVE_ISVSVN_THRESHOLD: sgx_isv_svn_t = 3; | ||||
| 
 | ||||
| impl QuoteVerifier { | ||||
|     pub fn new() -> Self { | ||||
|     pub fn new() -> Option<Self> { | ||||
|         let mut supplemental_data_size = 0; | ||||
|         let mut sgx_status = sgx_status_t::SGX_SUCCESS; | ||||
|         unsafe { | ||||
|             let sgx_status = occlum_ocall_get_supplement_size(&mut supplemental_data_size); | ||||
|             assert_eq!(sgx_status_t::SGX_SUCCESS, sgx_status); | ||||
|             assert_ne!(supplemental_data_size, 0); | ||||
|             sgx_status = occlum_ocall_get_supplement_size(&mut supplemental_data_size); | ||||
|         } | ||||
|         Self { | ||||
|             supplemental_data_size, | ||||
| 
 | ||||
|         if sgx_status != sgx_status_t::SGX_SUCCESS || supplemental_data_size == 0 { | ||||
|             error!("DCAP Quote Verifier new failed {}", sgx_status); | ||||
|             None | ||||
|         } else { | ||||
|             Some(Self { | ||||
|                 supplemental_data_size, | ||||
|             }) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user