Skip to content

Commit c0f549f

Browse files
committed
fix(guest): prefault exception handler counter
A guest exception handler runs on the IST1 stack. If the handler writes a copy-on-write page, the first write faults. The page fault also uses IST1, so the CPU resets RSP to the top of IST1 and writes the fault frame over the live handler frame. The handler returns to a bad address and the guest aborts. The test exception handler increments a counter that starts on a copy-on-write page. Write the counter once in install_handler so its page copies into scratch before the handler runs. The handler then increments a writable page and does not fault. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 8ba7725 commit c0f549f

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

  • src/tests/rust_guests/simpleguest/src

src/tests/rust_guests/simpleguest/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ fn test_exception_handler(
134134
/// Install handler for a specific vector
135135
#[guest_function("InstallHandler")]
136136
fn install_handler(vector: i32) {
137+
// The exception handler increments a counter that starts on a
138+
// copy-on-write page. Write the counter once here so its page copies
139+
// into scratch. The handler then increments a writable page and does
140+
// not fault while it runs on the exception stack.
141+
HANDLER_INVOCATION_COUNT.fetch_add(0, Ordering::SeqCst);
137142
hyperlight_guest_bin::exception::arch::HANDLERS[vector as usize].store(
138143
test_exception_handler as *const () as usize as u64,
139144
Ordering::Release,

0 commit comments

Comments
 (0)