From c3eddbcb49a93c4b36f97b69f91766d90d8dd627 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 25 Dec 2020 14:06:19 +0100 Subject: [PATCH] Kernel: Add back missing ELF::Image validity check If the image is not a valid ELF we should just fail ASAP. --- Kernel/Syscalls/execve.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index e7bca9ee49..95ce71dadf 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -75,6 +75,11 @@ KResultOr Process::load_elf_object(FileDescription& object_ return KResult(-ENOMEM); } + auto elf_image = ELF::Image(region->vaddr().as_ptr(), loader_metadata.size); + + if (!elf_image.is_valid()) + return KResult(-ENOEXEC); + Region* master_tls_region { nullptr }; size_t master_tls_size = 0; size_t master_tls_alignment = 0; @@ -83,8 +88,6 @@ KResultOr Process::load_elf_object(FileDescription& object_ MM.enter_process_paging_scope(*this); String elf_name = object_description.absolute_path(); - auto elf_image = ELF::Image(region->vaddr().as_ptr(), loader_metadata.size); - ASSERT(!Processor::current().in_critical()); bool failed = false;