@@ -13,9 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
16- #[ cfg( feature = "init-paging" ) ]
17- use std:: cmp:: Ordering ;
18-
1916use flatbuffers:: FlatBufferBuilder ;
2017use hyperlight_common:: flatbuffer_wrappers:: function_call:: {
2118 FunctionCall , validate_guest_function_call_buffer,
@@ -33,9 +30,6 @@ use super::shared_mem::{ExclusiveSharedMemory, GuestSharedMemory, HostSharedMemo
3330use crate :: sandbox:: snapshot:: Snapshot ;
3431use 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
289269impl 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 > {
0 commit comments