From d30dbf47f569fa798040e201b8daf423c29a1f49 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Wed, 7 Jul 2021 20:38:54 +0200 Subject: [PATCH] Kernel: Map non-page-aligned text segments correctly `.text` segments with non-aligned offsets had their lengths applied to the first page's base address. This meant that in some cases the last PAGE_SIZE - 1 bytes weren't mapped. Previously, it did not cause any problems as the GNU ld insists on aligning everything; but that's not the case with the LLVM toolchain. --- Kernel/Syscalls/execve.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 2e72df23e5..297a1b6c6e 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -387,7 +387,10 @@ static KResultOr load_elf_object(NonnullOwnPtr new_space, Fil prot |= PROT_WRITE; if (program_header.is_executable()) prot |= PROT_EXEC; - auto range = new_space->allocate_range(program_header.vaddr().offset(load_offset), program_header.size_in_memory()); + + auto range_base = VirtualAddress { page_round_down(program_header.vaddr().offset(load_offset).get()) }; + auto range_end = VirtualAddress { page_round_up(program_header.vaddr().offset(load_offset).offset(program_header.size_in_memory()).get()) }; + auto range = new_space->allocate_range(range_base, range_end.get() - range_base.get()); if (!range.has_value()) { ph_load_result = ENOMEM; return IterationDecision::Break;