Skip to content

Commit

Permalink
Kernel: Read the ELF header from the inode rather than the mapped pages
Browse files Browse the repository at this point in the history
Reading from the mapping doesn't work when the text segment has a non-zero
offset because in that case the first mapped page doesn't contain the ELF
header.
  • Loading branch information
gunnarbeutner authored and awesomekling committed Apr 14, 2021
1 parent 2d91761 commit c3ee705
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Kernel/Syscalls/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ static bool should_make_executable_exception_for_dynamic_loader(bool make_readab
if (!region.vmobject().is_private_inode())
return false;

auto& inode_vm = static_cast<const InodeVMObject&>(region.vmobject());
auto& inode = inode_vm.inode();

Elf32_Ehdr header;
if (!copy_from_user(&header, region.vaddr().as_ptr(), sizeof(header)))
auto buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)&header);
auto nread = inode.read_bytes(0, sizeof(header), buffer, nullptr);
if (nread != sizeof(header))
return false;

auto& inode = static_cast<const InodeVMObject&>(region.vmobject());

// The file is a valid ELF binary
if (!ELF::validate_elf_header(header, inode.size()))
return false;
Expand Down

0 comments on commit c3ee705

Please sign in to comment.