Skip to content

Commit 3517c0c

Browse files
authored
Clear abort buffer on each function call (#1335)
* Clear abort buffer on each function call Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * Add artificial test Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> --------- Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 9d0c3f7 commit 3517c0c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ impl MultiUseSandbox {
733733
}
734734
})();
735735

736+
// Clear partial abort bytes so they don't leak across calls.
737+
self.mem_mgr.abort_buffer.clear();
738+
736739
// In the happy path we do not need to clear io-buffers from the host because:
737740
// - the serialized guest function call is zeroed out by the guest during deserialization, see call to `try_pop_shared_input_data_into::<FunctionCall>()`
738741
// - the serialized guest function result is zeroed out by us (the host) during deserialization, see `get_guest_function_call_result`
@@ -1464,6 +1467,33 @@ mod tests {
14641467
);
14651468
}
14661469

1470+
/// Test that stale abort buffer bytes from a previous call don't
1471+
/// leak into the next call.
1472+
#[test]
1473+
fn stale_abort_buffer_does_not_leak_across_calls() {
1474+
let mut sbox: MultiUseSandbox = {
1475+
let path = simple_guest_as_string().unwrap();
1476+
let u_sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap();
1477+
u_sbox.evolve().unwrap()
1478+
};
1479+
1480+
// Simulate a partial abort
1481+
sbox.mem_mgr.abort_buffer.extend_from_slice(&[0xAA; 1020]);
1482+
1483+
let res = sbox.call::<String>("Echo", "hello".to_string());
1484+
assert!(
1485+
res.is_ok(),
1486+
"Expected Ok after stale abort buffer, got: {:?}",
1487+
res.unwrap_err()
1488+
);
1489+
1490+
// The buffer should be empty after the call.
1491+
assert!(
1492+
sbox.mem_mgr.abort_buffer.is_empty(),
1493+
"abort_buffer should be empty after a guest call"
1494+
);
1495+
}
1496+
14671497
/// Test that sandboxes can be created and evolved with different heap sizes
14681498
#[test]
14691499
fn test_sandbox_creation_various_sizes() {

0 commit comments

Comments
 (0)