From 9264303f5db9c6248922104428ed25b40b0dcf4e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 8 Apr 2023 07:24:19 +0200 Subject: [PATCH] Kernel: Don't reuse old master TLS region data in sys$execve() When switching to the new address space, we also have to switch the Process::m_master_tls_* variables as they may refer to a region in the old address space. This was causing `su` to not run correctly. Regression from 65641187ffb15e3512fcf9c260c02287f83b5d09. --- Kernel/Syscalls/execve.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 10a91bfb50..d5d6db4c99 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -490,16 +490,25 @@ ErrorOr Process::do_exec(NonnullRefPtr main_program_d auto allocated_space = TRY(Memory::AddressSpace::try_create(*this, nullptr)); OwnPtr old_space; + auto old_master_tls_region = m_master_tls_region; + auto old_master_tls_size = m_master_tls_size; + auto old_master_tls_alignment = m_master_tls_alignment; auto& new_space = m_space.with([&](auto& space) -> Memory::AddressSpace& { old_space = move(space); space = move(allocated_space); return *space; }); + m_master_tls_region = nullptr; + m_master_tls_size = 0; + m_master_tls_alignment = 0; ArmedScopeGuard space_guard([&]() { // If we failed at any point from now on we have to revert back to the old address space m_space.with([&](auto& space) { space = old_space.release_nonnull(); }); + m_master_tls_region = old_master_tls_region; + m_master_tls_size = old_master_tls_size; + m_master_tls_alignment = old_master_tls_alignment; Memory::MemoryManager::enter_process_address_space(*this); });