Skip to content

Commit 6104cbc

Browse files
committed
Remove the remainder of host-managed stack cookies
They may not be terribly useful as we move towards a stack that the guest is allowed to grow on its own. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent 2b783dd commit 6104cbc

6 files changed

Lines changed: 1 addition & 82 deletions

File tree

src/hyperlight_common/src/mem.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pub struct GuestStack {
4141
#[derive(Debug, Clone, Copy)]
4242
#[repr(C)]
4343
pub struct HyperlightPEB {
44-
pub security_cookie_seed: u64,
4544
pub guest_function_dispatch_ptr: u64,
4645
pub input_stack: GuestMemoryRegion,
4746
pub output_stack: GuestMemoryRegion,

src/hyperlight_host/src/hypervisor/hyperlight_vm.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,6 @@ impl HyperlightVm {
771771
});
772772
}
773773
None => {
774-
if !mem_mgr
775-
.check_stack_guard()
776-
.map_err(|e| RunVmError::CheckStackGuard(Box::new(e)))?
777-
{
778-
break Err(RunVmError::StackOverflow);
779-
}
780-
781774
break Err(RunVmError::MmioReadUnmapped(addr));
782775
}
783776
}
@@ -800,13 +793,6 @@ impl HyperlightVm {
800793
});
801794
}
802795
None => {
803-
if !mem_mgr
804-
.check_stack_guard()
805-
.map_err(|e| RunVmError::CheckStackGuard(Box::new(e)))?
806-
{
807-
break Err(RunVmError::StackOverflow);
808-
}
809-
810796
break Err(RunVmError::MmioWriteUnmapped(addr));
811797
}
812798
}

src/hyperlight_host/src/mem/layout.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ use std::fmt::Debug;
7272
use std::mem::{offset_of, size_of};
7373

7474
use hyperlight_common::mem::{GuestStack, HyperlightPEB, PAGE_SIZE_USIZE};
75-
use rand::{RngCore, rng};
7675
use tracing::{Span, instrument};
7776

7877
#[cfg(feature = "init-paging")]
@@ -101,7 +100,6 @@ pub(crate) struct SandboxMemoryLayout {
101100
/// The following fields are offsets to the actual PEB struct fields.
102101
/// They are used when writing the PEB struct itself
103102
peb_offset: usize,
104-
peb_security_cookie_seed_offset: usize,
105103
peb_guest_dispatch_function_ptr_offset: usize, // set by guest in guest entrypoint
106104
peb_input_data_offset: usize,
107105
peb_output_data_offset: usize,
@@ -149,10 +147,6 @@ impl Debug for SandboxMemoryLayout {
149147
.field("PEB Address", &format_args!("{:#x}", self.peb_address))
150148
.field("PEB Offset", &format_args!("{:#x}", self.peb_offset))
151149
.field("Code Size", &format_args!("{:#x}", self.code_size))
152-
.field(
153-
"Security Cookie Seed Offset",
154-
&format_args!("{:#x}", self.peb_security_cookie_seed_offset),
155-
)
156150
.field(
157151
"Guest Dispatch Function Pointer Offset",
158152
&format_args!("{:#x}", self.peb_guest_dispatch_function_ptr_offset),
@@ -245,8 +239,6 @@ impl SandboxMemoryLayout {
245239
let guest_code_offset = 0;
246240
// The following offsets are to the fields of the PEB struct itself!
247241
let peb_offset = code_size.next_multiple_of(PAGE_SIZE_USIZE);
248-
let peb_security_cookie_seed_offset =
249-
peb_offset + offset_of!(HyperlightPEB, security_cookie_seed);
250242
let peb_guest_dispatch_function_ptr_offset =
251243
peb_offset + offset_of!(HyperlightPEB, guest_function_dispatch_ptr);
252244
let peb_input_data_offset = peb_offset + offset_of!(HyperlightPEB, input_stack);
@@ -281,7 +273,6 @@ impl SandboxMemoryLayout {
281273
peb_offset,
282274
stack_size: stack_size_rounded,
283275
heap_size,
284-
peb_security_cookie_seed_offset,
285276
peb_guest_dispatch_function_ptr_offset,
286277
peb_input_data_offset,
287278
peb_output_data_offset,
@@ -692,11 +683,6 @@ impl SandboxMemoryLayout {
692683

693684
// Start of setting up the PEB. The following are in the order of the PEB fields
694685

695-
// Set up the security cookie seed
696-
let mut security_cookie_seed = [0u8; 8];
697-
rng().fill_bytes(&mut security_cookie_seed);
698-
shared_mem.copy_from_slice(&security_cookie_seed, self.peb_security_cookie_seed_offset)?;
699-
700686
// Skip guest_dispatch_function_ptr_offset because it is set by the guest
701687

702688
// Skip code, is set when loading binary

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#[cfg(feature = "init-paging")]
17-
use std::cmp::Ordering;
18-
1916
use flatbuffers::FlatBufferBuilder;
2017
use hyperlight_common::flatbuffer_wrappers::function_call::{
2118
FunctionCall, validate_guest_function_call_buffer,
@@ -33,9 +30,6 @@ use super::shared_mem::{ExclusiveSharedMemory, GuestSharedMemory, HostSharedMemo
3330
use crate::sandbox::snapshot::Snapshot;
3431
use crate::{Result, new_error};
3532

36-
/// The size of stack guard cookies
37-
pub(crate) const STACK_COOKIE_LEN: usize = 16;
38-
3933
/// A struct that is responsible for laying out and managing the memory
4034
/// for a given `Sandbox`.
4135
#[derive(Clone)]
@@ -52,8 +46,6 @@ pub(crate) struct SandboxMemoryManager<S> {
5246
pub(crate) entrypoint_offset: Option<Offset>,
5347
/// How many memory regions were mapped after sandbox creation
5448
pub(crate) mapped_rgns: u64,
55-
/// Stack cookie for stack guard verification
56-
pub(crate) stack_cookie: [u8; STACK_COOKIE_LEN],
5749
/// Buffer for accumulating guest abort messages
5850
pub(crate) abort_buffer: Vec<u8>,
5951
}
@@ -160,7 +152,6 @@ where
160152
scratch_mem: S,
161153
load_addr: RawPtr,
162154
entrypoint_offset: Option<Offset>,
163-
stack_cookie: [u8; STACK_COOKIE_LEN],
164155
) -> Self {
165156
Self {
166157
layout,
@@ -169,17 +160,10 @@ where
169160
load_addr,
170161
entrypoint_offset,
171162
mapped_rgns: 0,
172-
stack_cookie,
173163
abort_buffer: Vec::new(),
174164
}
175165
}
176166

177-
/// Get the stack cookie
178-
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
179-
pub(crate) fn get_stack_cookie(&self) -> &[u8; STACK_COOKIE_LEN] {
180-
&self.stack_cookie
181-
}
182-
183167
/// Get mutable access to the abort buffer
184168
pub(crate) fn get_abort_buffer_mut(&mut self) -> &mut Vec<u8> {
185169
&mut self.abort_buffer
@@ -217,7 +201,6 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
217201
shared_mem.copy_from_slice(s.memory(), 0)?;
218202
let scratch_mem = ExclusiveSharedMemory::new(s.layout().get_scratch_size())?;
219203
let load_addr: RawPtr = RawPtr::try_from(layout.get_guest_code_address())?;
220-
let stack_cookie = rand::random::<[u8; STACK_COOKIE_LEN]>();
221204
let entrypoint_gva = s.preinitialise();
222205
let entrypoint_offset = entrypoint_gva.map(|x| (x - u64::from(&load_addr)).into());
223206
Ok(Self::new(
@@ -226,7 +209,6 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
226209
scratch_mem,
227210
load_addr,
228211
entrypoint_offset,
229-
stack_cookie,
230212
))
231213
}
232214

@@ -266,7 +248,6 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
266248
load_addr: self.load_addr.clone(),
267249
entrypoint_offset: self.entrypoint_offset,
268250
mapped_rgns: self.mapped_rgns,
269-
stack_cookie: self.stack_cookie,
270251
abort_buffer: self.abort_buffer,
271252
};
272253
let guest_mgr = SandboxMemoryManager {
@@ -276,7 +257,6 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
276257
load_addr: self.load_addr.clone(),
277258
entrypoint_offset: self.entrypoint_offset,
278259
mapped_rgns: self.mapped_rgns,
279-
stack_cookie: self.stack_cookie,
280260
abort_buffer: Vec::new(), // Guest doesn't need abort buffer
281261
};
282262
host_mgr.update_scratch_bookkeeping(
@@ -287,33 +267,6 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
287267
}
288268

289269
impl SandboxMemoryManager<HostSharedMemory> {
290-
/// Check the stack guard of the memory in `shared_mem`, using
291-
/// `layout` to calculate its location.
292-
///
293-
/// Return `true`
294-
/// if `shared_mem` could be accessed properly and the guard
295-
/// matches `cookie`. If it could be accessed properly and the
296-
/// guard doesn't match `cookie`, return `false`. Otherwise, return
297-
/// a descriptive error.
298-
///
299-
/// This method could be an associated function instead. See
300-
/// documentation at the bottom `set_stack_guard` for description
301-
/// of why it isn't.
302-
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
303-
#[cfg(feature = "init-paging")]
304-
pub(crate) fn check_stack_guard(&self) -> Result<bool> {
305-
let expected = self.stack_cookie;
306-
let offset = self.layout.get_top_of_user_stack_offset();
307-
let actual: [u8; STACK_COOKIE_LEN] = self.shared_mem.read(offset)?;
308-
let cmp_res = expected.iter().cmp(actual.iter());
309-
Ok(cmp_res == Ordering::Equal)
310-
}
311-
312-
#[cfg(not(feature = "init-paging"))]
313-
pub(crate) fn check_stack_guard(&self) -> Result<bool> {
314-
Ok(true)
315-
}
316-
317270
/// Get the address of the dispatch function in memory
318271
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
319272
pub(crate) fn get_pointer_to_dispatch_function(&self) -> Result<u64> {

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,6 @@ impl MultiUseSandbox {
649649
return Err(error);
650650
}
651651

652-
self.mem_mgr.check_stack_guard()?;
653-
654652
let guest_result = self.mem_mgr.get_guest_function_call_result()?.into_inner();
655653

656654
match guest_result {
@@ -817,9 +815,7 @@ impl Callable for MultiUseSandbox {
817815

818816
impl std::fmt::Debug for MultiUseSandbox {
819817
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
820-
f.debug_struct("MultiUseSandbox")
821-
.field("stack_guard", &self.mem_mgr.get_stack_cookie())
822-
.finish()
818+
f.debug_struct("MultiUseSandbox").finish()
823819
}
824820
}
825821

src/hyperlight_host/src/sandbox/snapshot.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ mod tests {
575575
scratch_mem,
576576
0.into(),
577577
None,
578-
[0u8; 16],
579578
);
580579
let (mgr, _) = mgr.build().unwrap();
581580
(mgr, pt_base as u64)

0 commit comments

Comments
 (0)