Skip to content

Commit ef752ce

Browse files
committed
fixup! Allow the guest to manage its own stack
Remove dead code and fix fuzz harness Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent a4a7901 commit ef752ce

10 files changed

Lines changed: 24 additions & 122 deletions

File tree

fuzz/fuzz_targets/guest_trace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fuzz_target!(
7070
init: {
7171
let mut cfg = SandboxConfiguration::default();
7272
// In local tests, 256 KiB seemed sufficient for deep recursion
73-
cfg.set_stack_size(256 * 1024);
73+
cfg.set_scratch_size(256 * 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_common/src/flatbuffer_wrappers/guest_error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub enum ErrorCode {
3535
GispatchFunctionPointerNotSet = 6,
3636
OutbError = 7,
3737
UnknownError = 8,
38-
StackOverflow = 9,
3938
GsCheckFailed = 10,
4039
TooManyGuestFunctions = 11,
4140
FailureInDlmalloc = 12,
@@ -59,7 +58,6 @@ impl From<ErrorCode> for FbErrorCode {
5958
ErrorCode::GispatchFunctionPointerNotSet => Self::GispatchFunctionPointerNotSet,
6059
ErrorCode::OutbError => Self::OutbError,
6160
ErrorCode::UnknownError => Self::UnknownError,
62-
ErrorCode::StackOverflow => Self::StackOverflow,
6361
ErrorCode::GsCheckFailed => Self::GsCheckFailed,
6462
ErrorCode::TooManyGuestFunctions => Self::TooManyGuestFunctions,
6563
ErrorCode::FailureInDlmalloc => Self::FailureInDlmalloc,
@@ -86,7 +84,6 @@ impl From<FbErrorCode> for ErrorCode {
8684
}
8785
FbErrorCode::GispatchFunctionPointerNotSet => Self::GispatchFunctionPointerNotSet,
8886
FbErrorCode::OutbError => Self::OutbError,
89-
FbErrorCode::StackOverflow => Self::StackOverflow,
9087
FbErrorCode::GsCheckFailed => Self::GsCheckFailed,
9188
FbErrorCode::TooManyGuestFunctions => Self::TooManyGuestFunctions,
9289
FbErrorCode::FailureInDlmalloc => Self::FailureInDlmalloc,
@@ -113,7 +110,6 @@ impl From<u64> for ErrorCode {
113110
6 => Self::GispatchFunctionPointerNotSet,
114111
7 => Self::OutbError,
115112
8 => Self::UnknownError,
116-
9 => Self::StackOverflow,
117113
10 => Self::GsCheckFailed,
118114
11 => Self::TooManyGuestFunctions,
119115
12 => Self::FailureInDlmalloc,
@@ -138,7 +134,6 @@ impl From<ErrorCode> for u64 {
138134
ErrorCode::GispatchFunctionPointerNotSet => 6,
139135
ErrorCode::OutbError => 7,
140136
ErrorCode::UnknownError => 8,
141-
ErrorCode::StackOverflow => 9,
142137
ErrorCode::GsCheckFailed => 10,
143138
ErrorCode::TooManyGuestFunctions => 11,
144139
ErrorCode::FailureInDlmalloc => 12,
@@ -164,7 +159,6 @@ impl From<ErrorCode> for String {
164159
ErrorCode::GispatchFunctionPointerNotSet => "GispatchFunctionPointerNotSet".to_string(),
165160
ErrorCode::OutbError => "OutbError".to_string(),
166161
ErrorCode::UnknownError => "UnknownError".to_string(),
167-
ErrorCode::StackOverflow => "StackOverflow".to_string(),
168162
ErrorCode::GsCheckFailed => "GsCheckFailed".to_string(),
169163
ErrorCode::TooManyGuestFunctions => "TooManyGuestFunctions".to_string(),
170164
ErrorCode::FailureInDlmalloc => "FailureInDlmalloc".to_string(),

src/hyperlight_common/src/flatbuffers/hyperlight/generated/error_code_generated.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub const ENUM_MAX_ERROR_CODE: u64 = 17;
2525
note = "Use associated constants instead. This will no longer be generated in 2021."
2626
)]
2727
#[allow(non_camel_case_types)]
28-
pub const ENUM_VALUES_ERROR_CODE: [ErrorCode; 17] = [
28+
pub const ENUM_VALUES_ERROR_CODE: [ErrorCode; 16] = [
2929
ErrorCode::NoError,
3030
ErrorCode::UnsupportedParameterType,
3131
ErrorCode::GuestFunctionNameNotProvided,
@@ -34,7 +34,6 @@ pub const ENUM_VALUES_ERROR_CODE: [ErrorCode; 17] = [
3434
ErrorCode::GispatchFunctionPointerNotSet,
3535
ErrorCode::OutbError,
3636
ErrorCode::UnknownError,
37-
ErrorCode::StackOverflow,
3837
ErrorCode::GsCheckFailed,
3938
ErrorCode::TooManyGuestFunctions,
4039
ErrorCode::FailureInDlmalloc,
@@ -58,7 +57,6 @@ impl ErrorCode {
5857
pub const GispatchFunctionPointerNotSet: Self = Self(6);
5958
pub const OutbError: Self = Self(7);
6059
pub const UnknownError: Self = Self(8);
61-
pub const StackOverflow: Self = Self(9);
6260
pub const GsCheckFailed: Self = Self(10);
6361
pub const TooManyGuestFunctions: Self = Self(11);
6462
pub const FailureInDlmalloc: Self = Self(12);
@@ -79,7 +77,6 @@ impl ErrorCode {
7977
Self::GispatchFunctionPointerNotSet,
8078
Self::OutbError,
8179
Self::UnknownError,
82-
Self::StackOverflow,
8380
Self::GsCheckFailed,
8481
Self::TooManyGuestFunctions,
8582
Self::FailureInDlmalloc,
@@ -102,7 +99,6 @@ impl ErrorCode {
10299
Self::GispatchFunctionPointerNotSet => Some("GispatchFunctionPointerNotSet"),
103100
Self::OutbError => Some("OutbError"),
104101
Self::UnknownError => Some("UnknownError"),
105-
Self::StackOverflow => Some("StackOverflow"),
106102
Self::GsCheckFailed => Some("GsCheckFailed"),
107103
Self::TooManyGuestFunctions => Some("TooManyGuestFunctions"),
108104
Self::FailureInDlmalloc => Some("FailureInDlmalloc"),

src/hyperlight_common/src/mem.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ pub struct GuestMemoryRegion {
2828
pub ptr: u64,
2929
}
3030

31-
/// A memory region in the guest address space that is used for the stack
32-
#[derive(Debug, Clone, Copy)]
33-
#[repr(C)]
34-
pub struct GuestStack {
35-
/// The top of the user stack
36-
pub min_user_stack_address: u64,
37-
/// The user stack pointer
38-
pub user_stack_address: u64,
39-
}
40-
4131
#[derive(Debug, Clone, Copy)]
4232
#[repr(C)]
4333
pub struct HyperlightPEB {

src/hyperlight_host/src/error.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -422,36 +422,6 @@ mod tests {
422422
};
423423
use crate::sandbox::outb::HandleOutbError;
424424

425-
/// Test that StackOverflow from RunVmError promotes to HyperlightError::StackOverflow
426-
#[test]
427-
fn test_promote_stack_overflow_from_run_vm() {
428-
let err = DispatchGuestCallError::Run(RunVmError::StackOverflow);
429-
let (promoted, should_poison) = err.promote();
430-
431-
assert!(should_poison, "StackOverflow should poison the sandbox");
432-
assert!(
433-
matches!(promoted, HyperlightError::StackOverflow()),
434-
"Expected HyperlightError::StackOverflow, got {:?}",
435-
promoted
436-
);
437-
}
438-
439-
/// Test that StackOverflow from HandleOutbError promotes to HyperlightError::StackOverflow
440-
#[test]
441-
fn test_promote_stack_overflow_from_outb() {
442-
let err = DispatchGuestCallError::Run(RunVmError::HandleIo(HandleIoError::Outb(
443-
HandleOutbError::StackOverflow,
444-
)));
445-
let (promoted, should_poison) = err.promote();
446-
447-
assert!(should_poison, "StackOverflow should poison the sandbox");
448-
assert!(
449-
matches!(promoted, HyperlightError::StackOverflow()),
450-
"Expected HyperlightError::StackOverflow, got {:?}",
451-
promoted
452-
);
453-
}
454-
455425
/// Test that ExecutionCancelledByHost promotes to HyperlightError::ExecutionCanceledByHost
456426
#[test]
457427
fn test_promote_execution_cancelled_by_host() {
@@ -517,26 +487,6 @@ mod tests {
517487
}
518488
}
519489

520-
/// Test that ConvertRspPointer does not poison the sandbox
521-
#[test]
522-
fn test_promote_convert_rsp_pointer_no_poison() {
523-
let err = DispatchGuestCallError::ConvertRspPointer("test error".to_string());
524-
let (promoted, should_poison) = err.promote();
525-
526-
assert!(
527-
!should_poison,
528-
"ConvertRspPointer should not poison the sandbox"
529-
);
530-
assert!(
531-
matches!(
532-
promoted,
533-
HyperlightError::HyperlightVmError(HyperlightVmError::DispatchGuestCall(_))
534-
),
535-
"Expected HyperlightError::HyperlightVmError, got {:?}",
536-
promoted
537-
);
538-
}
539-
540490
/// Test that non-promoted Run errors are wrapped in HyperlightVmError
541491
#[test]
542492
fn test_promote_other_run_errors_wrapped() {

src/hyperlight_host/src/hypervisor/hyperlight_vm.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ pub(crate) struct HyperlightVm {
116116
/// DispatchGuestCall error
117117
#[derive(Debug, thiserror::Error)]
118118
pub enum DispatchGuestCallError {
119-
#[error("Failed to convert RSP pointer: {0}")]
120-
ConvertRspPointer(String),
121119
#[error("Failed to run vm: {0}")]
122120
Run(#[from] RunVmError),
123121
#[error("Failed to setup registers: {0}")]
@@ -131,9 +129,7 @@ impl DispatchGuestCallError {
131129
// These errors poison the sandbox because they can leave it in an inconsistent state
132130
// by returning before the guest can unwind properly
133131
DispatchGuestCallError::Run(_) => true,
134-
DispatchGuestCallError::ConvertRspPointer(_) | DispatchGuestCallError::SetupRegs(_) => {
135-
false
136-
}
132+
DispatchGuestCallError::SetupRegs(_) => false,
137133
}
138134
}
139135

@@ -145,12 +141,6 @@ impl DispatchGuestCallError {
145141
pub(crate) fn promote(self) -> (HyperlightError, bool) {
146142
let should_poison = self.is_poison_error();
147143
let promoted_error = match self {
148-
// These errors poison the sandbox because the guest did not run to completion
149-
DispatchGuestCallError::Run(RunVmError::StackOverflow)
150-
| DispatchGuestCallError::Run(RunVmError::HandleIo(HandleIoError::Outb(
151-
HandleOutbError::StackOverflow,
152-
))) => HyperlightError::StackOverflow(),
153-
154144
DispatchGuestCallError::Run(RunVmError::ExecutionCancelledByHost) => {
155145
HyperlightError::ExecutionCanceledByHost()
156146
}
@@ -188,8 +178,6 @@ pub enum InitializeError {
188178
/// Errors that can occur during VM execution in the run loop
189179
#[derive(Debug, thiserror::Error)]
190180
pub enum RunVmError {
191-
#[error("Error checking stack guard: {0}")]
192-
CheckStackGuard(Box<HyperlightError>),
193181
#[cfg(crashdump)]
194182
#[error("Crashdump generation error: {0}")]
195183
CrashdumpGeneration(Box<HyperlightError>),
@@ -217,8 +205,6 @@ pub enum RunVmError {
217205
MmioWriteUnmapped(u64),
218206
#[error("vCPU run failed: {0}")]
219207
RunVcpu(#[from] RunVcpuError),
220-
#[error("Stack overflow detected")]
221-
StackOverflow,
222208
#[error("Unexpected VM exit: {0}")]
223209
UnexpectedVmExit(String),
224210
#[cfg(gdb)]
@@ -278,8 +264,6 @@ pub enum CreateHyperlightVmError {
278264
#[cfg(gdb)]
279265
#[error("Failed to add hardware breakpoint: {0}")]
280266
AddHwBreakpoint(DebugError),
281-
#[error("Failed to convert RSP pointer: {0}")]
282-
ConvertRspPointer(Box<HyperlightError>),
283267
#[error("No hypervisor was found")]
284268
NoHypervisorFound,
285269
#[cfg(gdb)]

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use hyperlight_common::flatbuffer_wrappers::function_call::{FunctionCall, Functi
2828
use hyperlight_common::flatbuffer_wrappers::function_types::{
2929
ParameterValue, ReturnType, ReturnValue,
3030
};
31-
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
3231
use hyperlight_common::flatbuffer_wrappers::util::estimate_flatbuffer_capacity;
3332
use tracing::{Span, instrument};
3433

@@ -662,10 +661,10 @@ impl MultiUseSandbox {
662661
)
663662
.increment(1);
664663

665-
Err(match guest_error.code {
666-
ErrorCode::StackOverflow => HyperlightError::StackOverflow(),
667-
_ => HyperlightError::GuestError(guest_error.code, guest_error.message),
668-
})
664+
Err(HyperlightError::GuestError(
665+
guest_error.code,
666+
guest_error.message,
667+
))
669668
}
670669
}
671670
})();

src/hyperlight_host/src/sandbox/outb.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ use crate::sandbox::trace::MemTraceInfo;
3535
/// Errors that can occur when handling an outb operation from the guest.
3636
#[derive(Debug, thiserror::Error)]
3737
pub enum HandleOutbError {
38-
#[error("Stack overflow detected (signaled by guest)")]
39-
StackOverflow,
4038
#[error("Guest aborted: error code {code}, message: {message}")]
4139
GuestAborted {
4240
/// The error code from the guest
@@ -145,28 +143,24 @@ fn outb_abort(
145143
for &b in &bytes[1..=len as usize] {
146144
if b == ABORT_TERMINATOR {
147145
let guest_error_code = *buffer.first().unwrap_or(&0);
148-
let guest_error = ErrorCode::from(guest_error_code as u64);
149-
150-
let result = match guest_error {
151-
ErrorCode::StackOverflow => Err(HandleOutbError::StackOverflow),
152-
_ => {
153-
let message = if let Some(&maybe_exception_code) = buffer.get(1) {
154-
match Exception::try_from(maybe_exception_code) {
155-
Ok(exception) => {
156-
let extra_msg = String::from_utf8_lossy(&buffer[2..]);
157-
format!("Exception: {:?} | {}", exception, extra_msg)
158-
}
159-
Err(_) => String::from_utf8_lossy(&buffer[1..]).into(),
160-
}
161-
} else {
162-
String::new()
163-
};
164146

165-
Err(HandleOutbError::GuestAborted {
166-
code: guest_error_code,
167-
message,
168-
})
169-
}
147+
let result = {
148+
let message = if let Some(&maybe_exception_code) = buffer.get(1) {
149+
match Exception::try_from(maybe_exception_code) {
150+
Ok(exception) => {
151+
let extra_msg = String::from_utf8_lossy(&buffer[2..]);
152+
format!("Exception: {:?} | {}", exception, extra_msg)
153+
}
154+
Err(_) => String::from_utf8_lossy(&buffer[1..]).into(),
155+
}
156+
} else {
157+
String::new()
158+
};
159+
160+
Err(HandleOutbError::GuestAborted {
161+
code: guest_error_code,
162+
message,
163+
})
170164
};
171165

172166
buffer.clear();

src/hyperlight_host/tests/integration_test.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,6 @@ fn guest_panic_no_alloc() {
592592
)
593593
.unwrap_err();
594594

595-
if let HyperlightError::StackOverflow() = res {
596-
panic!("panic on OOM caused stack overflow, this implies allocation in panic handler");
597-
}
598-
599595
assert!(matches!(
600596
res,
601597
HyperlightError::GuestAborted(code, msg) if code == ErrorCode::UnknownError as u8 && msg.contains("memory allocation of ") && msg.contains("bytes failed")

src/schema/guest_error.fbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ enum ErrorCode: ulong {
99
GispatchFunctionPointerNotSet = 6, // Host Call Dispatch Function Pointer is not present.
1010
OutbError = 7, // Error in OutB Function
1111
UnknownError = 8, // The guest error is unknown.
12-
StackOverflow = 9, // Guest stack allocations caused stack overflow
1312
GsCheckFailed = 10, // __security_check_cookie failed
1413
TooManyGuestFunctions = 11, // The guest tried to register too many guest functions
1514
FailureInDlmalloc = 12, // this error is set when dlmalloc calls ABORT (e.g. function defined in ABORT (dlmalloc_abort() calls setError with this errorcode)

0 commit comments

Comments
 (0)