From 2ea2e9fc0cc17c56ebc5b635f8511ca4df06d3d7 Mon Sep 17 00:00:00 2001 From: slipher Date: Tue, 21 Oct 2025 15:14:53 -0500 Subject: [PATCH 1/2] NaClAddrSpaceFree: do nothing if memory prereserved NaClAddrSpaceFree is supposed to unmap the whole memory range used in the sandbox, but when the bootstrap helper pre-reserved it starting at 0, it may have skipped the first few pages that the kernel does not allow to be mapped and we won't know how many pages were skipped. This function is only used in tests so just skip the unmap to avoid breaking the tests. Fixes run_trusted_mmap_test on ARM. --- src/trusted/service_runtime/posix/addrspace_teardown.c | 4 ++++ src/trusted/service_runtime/sel_addrspace.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/trusted/service_runtime/posix/addrspace_teardown.c b/src/trusted/service_runtime/posix/addrspace_teardown.c index ca1b089c15..08f0483265 100644 --- a/src/trusted/service_runtime/posix/addrspace_teardown.c +++ b/src/trusted/service_runtime/posix/addrspace_teardown.c @@ -18,6 +18,10 @@ void NaClAddrSpaceFree(struct NaClApp *nap) { uintptr_t addrsp_size = (uintptr_t) 1U << nap->addr_bits; size_t full_size = (NACL_ADDRSPACE_LOWER_GUARD_SIZE + addrsp_size + NACL_ADDRSPACE_UPPER_GUARD_SIZE); + if (g_prereserved_sandbox_size > 0) { + NaClLog(LOG_WARNING, "NaClAddrSpaceFree: can't unmap when memory is prereserved by bootstrap helper\n"); + return; + } if (munmap(base, full_size) != 0) { NaClLog(LOG_FATAL, "NaClAddrSpaceFree: munmap() failed, errno %d\n", errno); diff --git a/src/trusted/service_runtime/sel_addrspace.h b/src/trusted/service_runtime/sel_addrspace.h index ad790048a6..1ec2def6a8 100644 --- a/src/trusted/service_runtime/sel_addrspace.h +++ b/src/trusted/service_runtime/sel_addrspace.h @@ -94,6 +94,9 @@ NaClErrorCode NaClAllocateSpace(void **mem, size_t addrsp_size) NACL_WUR; * * Note that this does not free any other data structures associated * with the NaClApp. In particular, it does not free mem_map. + * + * FIXME: does not work when memory is prereserved by nacl_bootstrap_helper + * since we don't know what vm.mmap_min_addr sysctl was */ void NaClAddrSpaceFree(struct NaClApp *nap); From 9d581c76a097bfef8c6dda932fffc6c693d56f6c Mon Sep 17 00:00:00 2001 From: slipher Date: Tue, 21 Oct 2025 16:26:26 -0500 Subject: [PATCH 2/2] Fix building ARM sel_ldr without nacl in --mode --- src/trusted/validator_arm/build.scons | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trusted/validator_arm/build.scons b/src/trusted/validator_arm/build.scons index 7397eb1646..076acf72e3 100644 --- a/src/trusted/validator_arm/build.scons +++ b/src/trusted/validator_arm/build.scons @@ -265,7 +265,7 @@ validator_tests = { # The following tests generate ARM nexes from assembly and validate the # generate file. They're all expected to fail and produce the golden files' # stdout. Stderr is expected to be empty. -if env.Bit('build_arm'): +if env.Bit('build_arm') and UsingNaclMode(): untrusted_env = env.MakeUntrustedNativeEnv() for test, exit_status in validator_tests.items(): nexe = untrusted_env.ComponentProgram(test, 'testdata/' + test + '.S',