1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:37:35 +00:00

Kernel: Read the ELF header from the inode rather than the mapped pages

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.
This commit is contained in:
Gunnar Beutner 2021-04-13 19:29:34 +02:00 committed by Andreas Kling
parent 2d91761cf6
commit c3ee70591a

View file

@ -64,11 +64,14 @@ static bool should_make_executable_exception_for_dynamic_loader(bool make_readab
if (!region.vmobject().is_private_inode())
return false;
Elf32_Ehdr header;
if (!copy_from_user(&header, region.vaddr().as_ptr(), sizeof(header)))
return false;
auto& inode_vm = static_cast<const InodeVMObject&>(region.vmobject());
auto& inode = inode_vm.inode();
auto& inode = static_cast<const InodeVMObject&>(region.vmobject());
Elf32_Ehdr 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;
// The file is a valid ELF binary
if (!ELF::validate_elf_header(header, inode.size()))