From 9295f1936c6119b46893ba6325a795502550c52d Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 30 Jun 2021 19:59:03 +0300 Subject: [PATCH] LibELF: Check for missing PT_LOAD alignment header value This ensures we dont divide by zero when checking for valid alignment values. --- Userland/Libraries/LibELF/Validation.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibELF/Validation.cpp b/Userland/Libraries/LibELF/Validation.cpp index 3dfef40997e304..dc68380f242520 100644 --- a/Userland/Libraries/LibELF/Validation.cpp +++ b/Userland/Libraries/LibELF/Validation.cpp @@ -237,14 +237,18 @@ bool validate_program_headers(const ElfW(Ehdr) & elf_header, size_t file_size, c } if (elf_header.e_type != ET_CORE) { + if (program_header.p_type == PT_LOAD && program_header.p_align == 0) { + if (verbose) + dbgln("Program header ({}) with p_type PT_LOAD missing p_align (p_align == 0)", header_index); + return false; + } + 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 (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);