Skip to content

Commit 127a080

Browse files
committed
Add poision state to sandbox
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 28394fd commit 127a080

File tree

5 files changed

+421
-4
lines changed

5 files changed

+421
-4
lines changed

src/hyperlight_host/src/error.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ pub enum HyperlightError {
8383
ExecutionAccessViolation(u64),
8484

8585
/// Guest execution was cancelled by the host
86+
///
87+
/// **This error poisons the sandbox.** See [`crate::MultiUseSandbox::clear_poison()`] for recovery options.
8688
#[error("Execution was cancelled by the host.")]
8789
ExecutionCanceledByHost(),
8890

@@ -95,6 +97,8 @@ pub enum HyperlightError {
9597
FieldIsMissingInGuestLogData(String),
9698

9799
/// Guest aborted during outb
100+
///
101+
/// **This error poisons the sandbox.** See [`crate::MultiUseSandbox::clear_poison()`] for recovery options.
98102
#[error("Guest aborted: {0} {1}")]
99103
GuestAborted(u8, String),
100104

@@ -196,6 +200,36 @@ pub enum HyperlightError {
196200
#[error("Failure processing PE File {0:?}")]
197201
PEFileProcessingFailure(#[from] goblin::error::Error),
198202

203+
/// The sandbox is poisoned due to an inconsistent internal state that could lead to
204+
/// undefined behavior, memory corruption, or security vulnerabilities.
205+
///
206+
/// ## What causes poisoning?
207+
///
208+
/// Sandbox poisoning occurs when operations leave the sandbox in an inconsistent state:
209+
///
210+
/// ### Guest Function Panics/Aborts
211+
/// - **Heap Memory Leaks**: When a guest function panics or aborts, the call stack is not
212+
/// properly unwound, leaving heap allocations permanently leaked
213+
/// - **Resource Leaks**: File handles, network connections, or other resources may remain
214+
/// open and unreachable
215+
/// - **Partial State Updates**: Data structures may be left in an inconsistent state
216+
/// (e.g., half-updated linked lists, corrupted hash tables)
217+
///
218+
/// ### Interrupted Function Calls
219+
/// When you interrupt an in-progress guest function with [`InterruptHandle::kill()`]:
220+
/// - **Memory Allocations**: Heap memory allocated during the call remains leaked
221+
/// - **Mutex/Lock State**: Guest-side mutexes may remain locked, causing deadlocks
222+
/// - **I/O Buffers**: Partially written buffers may contain corrupted data
223+
/// - **Global State**: Static variables may be left in an inconsistent state
224+
///
225+
/// ## Recovery
226+
///
227+
/// - **Safe**: Restore from a non-poisoned snapshot using [`MultiUseSandbox::restore()`]
228+
/// - **Unsafe**: Clear poison manually with [`MultiUseSandbox::clear_poison()`] (only if you
229+
/// understand the inconsistent state and have manually resolved it)
230+
#[error("The sandbox was poisoned")]
231+
PoisonedSandbox,
232+
199233
/// Raw pointer is less than base address
200234
#[error("Raw pointer ({0:?}) was less than the base address ({1})")]
201235
RawPointerLessThanBaseAddress(RawPtr, u64),

src/hyperlight_host/src/mem/shared_mem_snapshot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::Result;
2222

2323
/// A wrapper around a `SharedMemory` reference and a snapshot
2424
/// of the memory therein
25-
#[derive(Clone)]
25+
#[derive(Clone, Debug)]
2626
pub(crate) struct SharedMemorySnapshot {
2727
// Unique ID of the sandbox this snapshot was taken from
2828
sandbox_id: u64,

0 commit comments

Comments
 (0)