Skip to content

Commit

Permalink
fix to remove redundant check with rsgx_raw_is_outside_enclave()
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Nov 19, 2024
1 parent ec6b459 commit 3cacd40
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions enclave-modules/utils/src/pointers.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use log::*;
use sgx_trts::trts::{rsgx_lfence, rsgx_raw_is_outside_enclave, rsgx_sfence};
use sgx_trts::trts::{rsgx_lfence, rsgx_sfence};
use sgx_types::*;

/// Validates a mutable pointer and its length.
///
/// Assumes that the `ptr` is a valid pointer of enclave outside memory.
pub fn validate_mut_ptr(ptr: *mut u8, ptr_len: usize) -> SgxResult<()> {
if rsgx_raw_is_outside_enclave(ptr, ptr_len) {
warn!("Tried to access memory outside enclave -- rsgx_slice_is_outside_enclave");
if ptr.is_null() || ptr_len == 0 {
warn!("Tried to access an empty pointer - ptr.is_null() || ptr_len == 0");
return Err(sgx_status_t::SGX_ERROR_UNEXPECTED);
}
rsgx_sfence();
Ok(())
}

/// Validates a constant pointer and its length.
///
/// Assumes that the `ptr` is a valid pointer of enclave outside memory.
pub fn validate_const_ptr(ptr: *const u8, ptr_len: usize) -> SgxResult<()> {
if ptr.is_null() || ptr_len == 0 {
warn!("Tried to access an empty pointer - ptr.is_null()");
warn!("Tried to access an empty pointer - ptr.is_null() || ptr_len == 0");
return Err(sgx_status_t::SGX_ERROR_UNEXPECTED);
}
rsgx_lfence();
Expand Down

0 comments on commit 3cacd40

Please sign in to comment.