From 0acf166eec8d2872490fb4e688cf326463277df3 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Thu, 1 Apr 2021 20:42:54 +0100 Subject: [PATCH] sandbox test: use snmalloc to allocate sandbox arena We're going to try calling (our, out-of-sandbox) ->dealloc() on pointers into sandbox memory, so, when CHERIfied, we will need amplification authority over that memory. Rather than asking the PAL for memory directly, ask the out-of-sandbox snmalloc so that it will, on CHERI, go through its whole dance with its AuthMap. --- src/test/func/sandbox/sandbox.cc | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/test/func/sandbox/sandbox.cc b/src/test/func/sandbox/sandbox.cc index d81265c..1d2ff2e 100644 --- a/src/test/func/sandbox/sandbox.cc +++ b/src/test/func/sandbox/sandbox.cc @@ -199,20 +199,10 @@ namespace template void* alloc_sandbox_heap(size_t sb_size) { - if constexpr (pal_supports) - { - return PAL::template reserve_aligned(sb_size); - } - else - { - // Note: This wastes address space because the PAL will reserve - // double the amount we ask for to ensure alignment. It's fine for - // the test, but any call to this function that ignores `.second` - // (the allocated size) is deeply suspect. - void* ptr = PAL::reserve_at_least(sb_size).first; - PAL::template notify_using(ptr, sb_size); - return ptr; - } + // Use the outside-sandbox snmalloc to allocate memory, rather than using + // the PAL directly, so that our out-of-sandbox can amplify sandbox + // pointers + return ThreadAlloc::get_noncachable()->alloc(sb_size); } }; }