mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-20 00:12:20 +00:00
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.
This commit is contained in:
parent
6863d015ec
commit
298cd57fe7
|
@ -482,7 +482,10 @@ KResult Process::do_exec(NonnullRefPtr<FileDescription> 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<FileDescription> 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<FileDescription> 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();
|
||||
|
|
Loading…
Reference in a new issue