Skip to content

Commit c856bb5

Browse files
author
Jethro Beekman
committed
Align source_buffer in enclave_load_data
See intel/confidential-computing.sgx#844
1 parent 0dcf1cf commit c856bb5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

intel-sgx/sgxs-loaders/src/sgx_enclave_common/defs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub const LIBRARY: &str = "libsgx_enclave_common.so.1";
5656
#[cfg(windows)]
5757
pub const LIBRARY: &str = "sgx_enclave_common.dll";
5858

59+
#[repr(align(4096))]
60+
pub struct Align4096<T>(pub T);
61+
5962
pub const SYM_ENCLAVE_CREATE: &[u8] = b"enclave_create\0";
6063
pub type EnclaveCreateFn = unsafe extern "C" fn(
6164
base_address: *mut c_void,
@@ -71,7 +74,7 @@ pub const SYM_ENCLAVE_LOAD_DATA: &[u8] = b"enclave_load_data\0";
7174
pub type EnclaveLoadDataFn = unsafe extern "C" fn(
7275
target_address: *mut c_void,
7376
target_size: usize,
74-
source_buffer: *const u8,
77+
source_buffer: *const Align4096<[u8; 4096]>,
7578
data_properties: PageProperties,
7679
enclave_error: Option<&mut u32>,
7780
) -> usize;

intel-sgx/sgxs-loaders/src/sgx_enclave_common/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ impl EnclaveLoad for InnerLibrary {
173173
page: (MeasEAdd, PageChunks, [u8; 4096]),
174174
) -> Result<(), Self::Error> {
175175
let (eadd, chunks, data) = page;
176+
let data = Align4096(data);
176177

177178
let mut flags = PageProperties::empty();
178179
if eadd
@@ -207,7 +208,7 @@ impl EnclaveLoad for InnerLibrary {
207208
if (mapping.device.enclave_load_data)(
208209
(mapping.base + eadd.offset) as _,
209210
0x1000,
210-
data.as_ptr(),
211+
&data,
211212
flags,
212213
Some(&mut error),
213214
) != 0x1000

0 commit comments

Comments
 (0)