Skip to content

Commit 5f485de

Browse files
committed
fix(virtq): we gonna need a bigger boat
Move FXSAVE buffer to the middle of scratch to avoid overwriting live page tables that are copied to the beginning of scratch when update_scratch_bookkeeping is called
1 parent daf681f commit 5f485de

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

fuzz/fuzz_targets/guest_trace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ impl<'a> Arbitrary<'a> for FuzzInput {
6969
fuzz_target!(
7070
init: {
7171
let mut cfg = SandboxConfiguration::default();
72-
// In local tests, 256 KiB seemed sufficient for deep recursion
73-
cfg.set_scratch_size(256 * 1024);
72+
// In local tests, 512 KiB seemed sufficient for deep recursion
73+
cfg.set_scratch_size(512 * 1024);
7474
let path = simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing");
7575
let u_sbox = UninitializedSandbox::new(
7676
GuestBinary::FilePath(path),

src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,18 +2125,20 @@ mod tests {
21252125
}
21262126

21272127
/// Creates VM with guest code that: dirtys FPU (if flag==0), does FXSAVE to buffer, sets flag=1.
2128-
/// Uses scratch region after rings for FXSAVE buffer.
2128+
/// Uses a scratch region area for the FXSAVE buffer.
21292129
fn hyperlight_vm_with_mem_mgr_fxsave() -> FxsaveTestContext {
21302130
use iced_x86::code_asm::*;
21312131

21322132
// Compute fixed addresses for FXSAVE buffer and flag.
2133-
// We use the page-table area in scratch after rings as a
2134-
// convenient 512-byte aligned buffer for FXSAVE.
2133+
// Place the buffer at halfway through scratch: well past
2134+
// the rings and page tables at the start, and well below
2135+
// the stack and scratch-top metadata at the end.
21352136
let config: SandboxConfiguration = Default::default();
21362137
let layout = SandboxMemoryLayout::new(config, 512, 4096, None).unwrap();
2137-
let fxsave_offset = layout.get_pt_base_scratch_offset();
2138-
let fxsave_gva = hyperlight_common::layout::scratch_base_gva(config.get_scratch_size())
2139-
+ fxsave_offset as u64;
2138+
let scratch_size = config.get_scratch_size();
2139+
let fxsave_offset = (scratch_size / 2) & !0xFFF; // page-aligned
2140+
let fxsave_gva =
2141+
hyperlight_common::layout::scratch_base_gva(scratch_size) + fxsave_offset as u64;
21402142
let flag_gva = fxsave_gva + 512;
21412143

21422144
let mut a = CodeAssembler::new(64).unwrap();

0 commit comments

Comments
 (0)