Skip to content

Commit 23e1055

Browse files
committed
Add poison state to sandbox to prevent inconsistent state
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 3063e4a commit 23e1055

File tree

8 files changed

+403
-15
lines changed

8 files changed

+403
-15
lines changed

Cargo.lock

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hyperlight_host/src/error.rs

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

8080
/// Guest execution was cancelled by the host
81+
///
82+
/// **This error poisons the sandbox.** See [`crate::MultiUseSandbox::clear_poison()`] for recovery options.
8183
#[error("Execution was cancelled by the host.")]
8284
ExecutionCanceledByHost(),
8385

@@ -90,6 +92,8 @@ pub enum HyperlightError {
9092
FieldIsMissingInGuestLogData(String),
9193

9294
/// Guest aborted during outb
95+
///
96+
/// **This error poisons the sandbox.** See [`crate::MultiUseSandbox::clear_poison()`] for recovery options.
9397
#[error("Guest aborted: {0} {1}")]
9498
GuestAborted(u8, String),
9599

@@ -191,6 +195,36 @@ pub enum HyperlightError {
191195
#[error("Failure processing PE File {0:?}")]
192196
PEFileProcessingFailure(#[from] goblin::error::Error),
193197

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