diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2019-10-20 08:24:42 -0600 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-20 16:24:42 +0200 |
commit | 138abb909808747f8f3f5cbb2dcb1ecf5503a6e0 (patch) | |
tree | 9a4a979bb781b60cca4ec0770cb800f7e3fcc547 /AK | |
parent | eb77e680ed615e9daf5b165359b4a45541b4e6f3 (diff) | |
download | serenity-138abb909808747f8f3f5cbb2dcb1ecf5503a6e0.zip |
ELF: Fail layout when program header hooks return nullptr (#673)
ELFLoader::layout() had a "failed" variable that was never set. This
patch checks the return value of each hook (alloc/map section and tls)
and fails the load if they return null.
I also needed to patch Process so that the alloc_section_hook and
map_section_hook actually return nullptr when allocating a region fails.
Fixes #664 :)
Diffstat (limited to 'AK')
-rw-r--r-- | AK/ELF/ELFLoader.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/AK/ELF/ELFLoader.cpp b/AK/ELF/ELFLoader.cpp index d0ad8d3a71..8c1e8302fa 100644 --- a/AK/ELF/ELFLoader.cpp +++ b/AK/ELF/ELFLoader.cpp @@ -38,6 +38,10 @@ bool ELFLoader::layout() if (program_header.type() == PT_TLS) { #ifdef KERNEL auto* tls_image = tls_section_hook(program_header.size_in_memory(), program_header.alignment()); + if (!tls_image) { + failed = true; + return; + } memcpy(tls_image, program_header.raw_data(), program_header.size_in_image()); #endif return; @@ -49,16 +53,20 @@ bool ELFLoader::layout() #endif #ifdef KERNEL if (program_header.is_writable()) { - alloc_section_hook( + auto* allocated_section = alloc_section_hook( program_header.vaddr(), program_header.size_in_memory(), program_header.alignment(), program_header.is_readable(), program_header.is_writable(), String::format("elf-alloc-%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "")); + if (!allocated_section) { + failed = true; + return; + } memcpy(program_header.vaddr().as_ptr(), program_header.raw_data(), program_header.size_in_image()); } else { - map_section_hook( + auto* mapped_section = map_section_hook( program_header.vaddr(), program_header.size_in_memory(), program_header.alignment(), @@ -67,6 +75,9 @@ bool ELFLoader::layout() program_header.is_writable(), program_header.is_executable(), String::format("elf-map-%s%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "", program_header.is_executable() ? "x" : "")); + if (!mapped_section) { + failed = true; + } } #endif }); |