From b3be275cf78e0904f6949390dbe48d8ddd090c7e Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 9 Sep 2020 08:40:17 +0100 Subject: LibELF: Validate PT_GNU_RELRO program header I'm not sure if this is the correct validation. This is based on it being "read-only after relocation". --- Libraries/LibELF/Validation.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Libraries/LibELF/Validation.cpp') diff --git a/Libraries/LibELF/Validation.cpp b/Libraries/LibELF/Validation.cpp index 62229f923f..759ce24bc9 100644 --- a/Libraries/LibELF/Validation.cpp +++ b/Libraries/LibELF/Validation.cpp @@ -202,6 +202,12 @@ bool validate_program_headers(const Elf32_Ehdr& elf_header, size_t file_size, u8 dbgprintf("Possible shenanigans! Validating an ELF with executable stack.\n"); } break; + case PT_GNU_RELRO: + if ((program_header.p_flags & PF_X) && (program_header.p_flags & PF_W)) { + dbgprintf("SHENANIGANS! Program header %zu segment is marked write and execute\n", header_index); + return false; + } + break; default: // Not handling other program header types in other code so... let's not surprise them dbgprintf("Found program header (%zu) of unrecognized type %x!\n", header_index, program_header.p_type); -- cgit v1.2.3