From 3cacd4020e2ce93f718c9f8430c43c64f26ee067 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Tue, 19 Nov 2024 17:06:55 +0900 Subject: [PATCH] fix to remove redundant check with `rsgx_raw_is_outside_enclave()` Signed-off-by: Jun Kimura --- enclave-modules/utils/src/pointers.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/enclave-modules/utils/src/pointers.rs b/enclave-modules/utils/src/pointers.rs index e8ca6a7c..24bdbd90 100644 --- a/enclave-modules/utils/src/pointers.rs +++ b/enclave-modules/utils/src/pointers.rs @@ -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();