From 298cd57fe7572f752c78d62a1225f4c37bd57791 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 6 Sep 2021 17:07:00 +0200 Subject: [PATCH] Kernel: Allocate signal trampoline before committing to a sys$execve() Once we commit to a new executable image in sys$execve(), we can no longer return with an error to whoever called us from userspace. We must make sure to surface any potential errors before that point. This patch moves signal trampoline allocation before the commit. A number of other things remain to be moved. --- Kernel/Syscalls/execve.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index fba1a5d838..15087db6eb 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -482,7 +482,10 @@ KResult Process::do_exec(NonnullRefPtr main_program_description auto main_program_metadata = main_program_description->metadata(); auto load_result = TRY(load(main_program_description, interpreter_description, main_program_header)); + auto signal_trampoline_range = TRY(load_result.space->try_allocate_range({}, PAGE_SIZE)); + auto signal_trampoline_region = TRY(load_result.space->allocate_region_with_vmobject(signal_trampoline_range, g_signal_trampoline_region->vmobject(), 0, "Signal trampoline", PROT_READ | PROT_EXEC, true)); + signal_trampoline_region->set_syscall_region(true); // We commit to the new executable at this point. There is no turning back! @@ -523,13 +526,6 @@ KResult Process::do_exec(NonnullRefPtr main_program_description } Memory::MemoryManager::enter_space(*m_space); - auto signal_trampoline_region = m_space->allocate_region_with_vmobject(signal_trampoline_range, g_signal_trampoline_region->vmobject(), 0, "Signal trampoline", PROT_READ | PROT_EXEC, true); - if (signal_trampoline_region.is_error()) { - VERIFY_NOT_REACHED(); - } - - signal_trampoline_region.value()->set_syscall_region(true); - m_executable = main_program_description->custody(); m_arguments = arguments; m_environment = environment; @@ -612,7 +608,7 @@ KResult Process::do_exec(NonnullRefPtr main_program_description m_protected_values.execpromises = 0; m_protected_values.has_execpromises = false; - m_protected_values.signal_trampoline = signal_trampoline_region.value()->vaddr(); + m_protected_values.signal_trampoline = signal_trampoline_region->vaddr(); // FIXME: PID/TID ISSUE m_protected_values.pid = new_main_thread->tid().value();