diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-06-30 19:59:03 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-01 10:50:49 +0200 |
commit | 9295f1936c6119b46893ba6325a795502550c52d (patch) | |
tree | 530b45ec7d1b5a37555e05f437bd71f3cd0fa8da | |
parent | f9a8c6f0535bf46b78a068b9cec35be47ff0350a (diff) | |
download | serenity-9295f1936c6119b46893ba6325a795502550c52d.zip |
LibELF: Check for missing PT_LOAD alignment header value
This ensures we dont divide by zero when checking for valid alignment
values.
-rw-r--r-- | Userland/Libraries/LibELF/Validation.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Libraries/LibELF/Validation.cpp b/Userland/Libraries/LibELF/Validation.cpp index 3dfef40997..dc68380f24 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); |