Skip to content

Commit 36918e4

Browse files
zongmin.gutatetian
authored andcommitted
Check the buffer address before copy the data from the buffer
This commit fixed an Occlum security issue. The researchers from KU Leuven (Belgium) and the University of Birmingham (UK) found it and reported it to Occlum team. Thank you, Jo Van Bulck, Frank Piessens, Fritz Alder, David Oswald, Jesse Spielman and Sam Thomas.
1 parent 580a981 commit 36918e4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libos/src/util/mem_util.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ pub mod from_user {
4848
return_errno!(EINVAL, "NULL address is invalid");
4949
}
5050

51+
// confirm that at least the fisrt byte of the string is from user
52+
check_ptr(out_ptr)?;
53+
5154
let cstr = unsafe { CStr::from_ptr(out_ptr) };
5255
let cstring = CString::from(cstr);
53-
if !is_inside_user_space(out_ptr as *const u8, cstring.as_bytes().len()) {
56+
if !is_inside_user_space(out_ptr as *const u8, cstring.as_bytes_with_nul().len()) {
5457
return_errno!(EFAULT, "the whole buffer is not in the user space");
5558
}
5659
Ok(cstring)
@@ -127,11 +130,14 @@ pub mod from_untrusted {
127130
return_errno!(EINVAL, "NULL address is invalid");
128131
}
129132

133+
// confirm that at least the fisrt byte of the string is out side of enclave
134+
check_ptr(out_ptr)?;
135+
130136
let cstr = unsafe { CStr::from_ptr(out_ptr) };
131137
let cstring = CString::from(cstr);
132138
if !sgx_trts::trts::rsgx_raw_is_outside_enclave(
133139
out_ptr as *const u8,
134-
cstring.as_bytes().len(),
140+
cstring.as_bytes_with_nul().len(),
135141
) {
136142
return_errno!(EFAULT, "the string is not outside enclave");
137143
}

0 commit comments

Comments
 (0)