Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc: initialize alloced memeory #542

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion standalone/pruntime/enclave/src/libc_hacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub extern "C" fn posix_memalign(memptr: *mut *mut c_void, align: size_t, size:
if ptr.is_null() && size > 0 {
libc::ENOMEM
} else {
unsafe {
// Initialize the alloced memory to avoid non-deterministic behaivor as much as possible.
sgx_libc::memset(ptr, 0, size);
}
*memptr = ptr;
0
}
Expand Down Expand Up @@ -364,7 +368,14 @@ pub extern "C" fn mmap(
lazy_static::lazy_static! {
static ref PAGE_SIZE: size_t = unsafe { ocall::sysconf(libc::_SC_PAGESIZE) } as _;
}
return unsafe { sgx_libc::memalign(*PAGE_SIZE, len) };
let addr = unsafe { sgx_libc::memalign(*PAGE_SIZE, len) };
if !addr.is_null() {
unsafe {
// Initialize the alloced memory to avoid non-deterministic behaivor as much as possible.
sgx_libc::memset(addr, 0, len);
}
}
return addr;
}
info!(
"mmap(addr={:?}, len={}, prot={}, flags={}, fd={}, offset={})",
Expand Down