From 114e8fffcd233abeaa0be9cdbdbebfde2d8fdb15 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 29 Jun 2021 10:43:58 +0200 Subject: [PATCH] LibELF: Don't validate PT_LOAD alignment in ET_CORE files This was causing CrashDaemon to choke on our coredumps. Note that we didn't care about the validation failures before this change either, this patch simply reorders the checks to avoid divide-by-zero when validating an ET_CORE file. --- Userland/Libraries/LibELF/Validation.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibELF/Validation.cpp b/Userland/Libraries/LibELF/Validation.cpp index 8d3f1e23ec..3dfef40997 100644 --- a/Userland/Libraries/LibELF/Validation.cpp +++ b/Userland/Libraries/LibELF/Validation.cpp @@ -236,16 +236,16 @@ bool validate_program_headers(const ElfW(Ehdr) & elf_header, size_t file_size, c return false; } - if (program_header.p_type == PT_LOAD && program_header.p_align % (size_t)PAGE_SIZE != 0) { - if (elf_header.e_type != ET_CORE) { + if (elf_header.e_type != ET_CORE) { + if (program_header.p_type == PT_LOAD && program_header.p_align % (size_t)PAGE_SIZE != 0) { if (verbose) dbgln("Program header ({}) with p_type PT_LOAD has p_align ({}) not divisible by page size ({})", header_index, program_header.p_align, PAGE_SIZE); return false; } } - if (program_header.p_type == PT_LOAD && program_header.p_vaddr % program_header.p_align != program_header.p_offset % program_header.p_align) { - if (elf_header.e_type != ET_CORE) { + if (elf_header.e_type != ET_CORE) { + if (program_header.p_type == PT_LOAD && program_header.p_vaddr % program_header.p_align != program_header.p_offset % program_header.p_align) { if (verbose) dbgln("Program header ({}) with p_type PT_LOAD has mis-aligned p_vaddr ({:x})", header_index, program_header.p_vaddr); return false;