Skip to content

Commit

Permalink
Merge pull request #124 from datachainlab/audit-202409-s-1
Browse files Browse the repository at this point in the history
S-1: Fix to remove redundant check with `rsgx_raw_is_outside_enclave()`

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Nov 19, 2024
2 parents ec6b459 + 3cacd40 commit 18c1d6d
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 18c1d6d

Please sign in to comment.