Skip to content

Commit 14857ab

Browse files
committed
fix: use descriptor types for proper alignment
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
1 parent 9bd786c commit 14857ab

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/hyperlight_host/src/sandbox/file_mapping.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ pub(crate) fn prepare_file_cow(
295295
use std::os::windows::io::AsRawHandle;
296296

297297
use windows::Win32::Foundation::HANDLE;
298-
use windows::Win32::Security::{PSECURITY_DESCRIPTOR, SECURITY_ATTRIBUTES};
298+
use windows::Win32::Security::{
299+
PSECURITY_DESCRIPTOR, SECURITY_ATTRIBUTES, SECURITY_DESCRIPTOR,
300+
SECURITY_DESCRIPTOR_REVISION1,
301+
};
299302
use windows::Win32::System::Memory::{
300303
CreateFileMappingW, FILE_MAP_READ, MapViewOfFile, PAGE_READONLY,
301304
};
@@ -319,11 +322,14 @@ pub(crate) fn prepare_file_cow(
319322
// MapViewOfFileNuma2. File-backed sections created with the
320323
// default DACL fail with ERROR_ACCESS_DENIED when mapped
321324
// cross-process on modern Windows.
322-
let mut sd_bytes = [0u8; 40]; // SECURITY_DESCRIPTOR_MIN_LENGTH
325+
// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Security/struct.SECURITY_DESCRIPTOR.html
326+
// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/SystemServices/constant.SECURITY_DESCRIPTOR_REVISION1.html
327+
let mut sd = SECURITY_DESCRIPTOR::default();
328+
let psd = PSECURITY_DESCRIPTOR(&mut sd as *mut _ as *mut _);
323329
unsafe {
324-
let psd = PSECURITY_DESCRIPTOR(sd_bytes.as_mut_ptr() as *mut _);
325330
windows::Win32::Security::InitializeSecurityDescriptor(
326-
psd, 1, // SECURITY_DESCRIPTOR_REVISION
331+
psd,
332+
SECURITY_DESCRIPTOR_REVISION1,
327333
)
328334
.map_err(|e| {
329335
HyperlightError::Error(format!("InitializeSecurityDescriptor failed: {e}"))
@@ -334,7 +340,7 @@ pub(crate) fn prepare_file_cow(
334340
}
335341
let sa = SECURITY_ATTRIBUTES {
336342
nLength: std::mem::size_of::<SECURITY_ATTRIBUTES>() as u32,
337-
lpSecurityDescriptor: sd_bytes.as_mut_ptr() as *mut _,
343+
lpSecurityDescriptor: psd.0,
338344
bInheritHandle: false.into(),
339345
};
340346

0 commit comments

Comments
 (0)