Skip to content

Commit

Permalink
LibELF: Check for missing PT_LOAD alignment header value
Browse files Browse the repository at this point in the history
This ensures we dont divide by zero when checking for valid alignment
values.
  • Loading branch information
IdanHo authored and awesomekling committed Jul 1, 2021
1 parent f9a8c6f commit 9295f19
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Userland/Libraries/LibELF/Validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9295f19

Please sign in to comment.