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 65641187ff.
This commit is contained in:
Andreas Kling 2023-04-08 07:24:19 +02:00
parent 44dd824764
commit 9264303f5d
Notes: sideshowbarker 2024-07-17 06:51:48 +09:00

View file

@ -490,16 +490,25 @@ ErrorOr<void> Process::do_exec(NonnullRefPtr<OpenFileDescription> main_program_d
auto allocated_space = TRY(Memory::AddressSpace::try_create(*this, nullptr)); auto allocated_space = TRY(Memory::AddressSpace::try_create(*this, nullptr));
OwnPtr<Memory::AddressSpace> old_space; OwnPtr<Memory::AddressSpace> 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& { auto& new_space = m_space.with([&](auto& space) -> Memory::AddressSpace& {
old_space = move(space); old_space = move(space);
space = move(allocated_space); space = move(allocated_space);
return *space; return *space;
}); });
m_master_tls_region = nullptr;
m_master_tls_size = 0;
m_master_tls_alignment = 0;
ArmedScopeGuard space_guard([&]() { ArmedScopeGuard space_guard([&]() {
// If we failed at any point from now on we have to revert back to the old address space // If we failed at any point from now on we have to revert back to the old address space
m_space.with([&](auto& space) { m_space.with([&](auto& space) {
space = old_space.release_nonnull(); 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); Memory::MemoryManager::enter_process_address_space(*this);
}); });