summaryrefslogtreecommitdiff
path: root/Libraries/LibELF/ELFImage.cpp
AgeCommit message (Collapse)Author
2020-04-11LibELF: Move ELF classes into namespace ELFAndrew Kaster
This is for consistency with other namespace changes that were made a while back to the other libraries :)
2020-04-11LibELF: Return false instead of assert on unrecognized program headerAndrew Kaster
2020-04-11LibELF: Add a find_symbol() API that finds a Symbol for an addressAndreas Kling
Also add ELFImage::Symbol::raw_data() to get a StringView containing the entire symbol contents.
2020-03-23AK: Reduce header dependency graph of String.hAndreas Kling
String.h no longer pulls in StringView.h. We do this by moving a bunch of String functions out-of-line.
2020-03-08Userspace: Add missing #includes now that AK/StdLibExtras.h is smallerAndreas Kling
2020-02-21LibELF: Use the ELF_STRTAB string constant instead of hard-codingAndreas Kling
2020-02-10AK: Remove bitrotted Traits::dump() mechanismAndreas Kling
This was only used by HashTable::dump() which I used when doing the first HashTable implementation. Removing this allows us to also remove most includes of <AK/kstdio.h>.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-16Kernel+LibELF: Don't blindly trust ELF symbol offsets in symbolicationAndreas Kling
It was possible to craft a custom ELF executable that when symbolicated would cause the kernel to read from user-controlled addresses anywhere in memory. You could then fetch this memory via /proc/PID/stack We fix this by making ELFImage hand out StringView rather than raw const char* for symbol names. In case a symbol offset is outside the ELF image, you get a null StringView. :^) Test: Kernel/elf-symbolication-kernel-read-exploit.cpp
2020-01-13LibELF: Add methods to validate the ELF and program headersAndrew Kaster
These will make sure there's no funny business or funny offsets in the main ELF header or each Program Header. More can still be done (like validating section headers), but this is a good start
2020-01-09LibELF: Remove DynamicSection from ELFImageAndrew Kaster
Since ELFDynamicObject needs the actual virtual address of the .dynamic section in the loaded image, and not the file offset like we assumed before, due to MAP_PRIVATE secretly giving us a MAP_SHARED, we can remove all of the Dynamic* code from ELFImage. ELFDynamicLoader only needs ELFImage to get the Program headers at this point. More consolidation opportunities seem likely in the future.
2020-01-06Kernel+LibELF: Validate PT_LOAD and PT_TLS offsets before memcpy()'ingAndreas Kling
Before this, you could make the kernel copy memory from anywhere by setting up an ELF executable with a program header specifying file offsets outside the file. Since ELFImage didn't even know how large it was, we had no clue that we were copying things from outside the ELF. Fix this by adding a size field to ELFImage and validating program header ranges before memcpy()'ing to them. The ELF code is definitely going to need more validation and checking.
2020-01-05LibELF: Fix stack overflow in ELFImage::relocations()Andreas Kling
Thanks to braindead for finding the bug! :^)
2020-01-04LibELF+LibC: Split ELFDynamicObject into a Loader + ObjectAndrew Kaster
Separate some responsibilities: ELFDynamicLoader is responsible for loading elf binaries from disk and performing relocations, calling init functions, and eventually calling finalizer functions. ELFDynamicObject is a helper class to parse the .dynamic section of an elf binary, or the table of Elf32_Dyn entries at the _DYNAMIC symbol. ELFDynamicObject now owns the helper classes for Relocations, Symbols, Sections and the like that ELFDynamicLoader will use to perform relocations and symbol lookup. Because these new helpers are constructed from offsets into the .dynamic section within the loaded .data section of the binary, we don't need the ELFImage for nearly as much of the loading processes as we did before. Therefore we can remove most of the extra DynamicXXX classes and just keep the one that lets us find the location of _DYNAMIC in the new ELF. And finally, since we changed the name of the class that dlopen/dlsym care about, we need to compile/link and use the new ELFDynamicLoader class in LibC.
2020-01-01LibELF: Add ELFDynamicObject to dynamically load libariesAndrew Kaster
This patch also adds some missing relocation defines to exec_elf.h, and a few helper classes/methods to ELFImage so that we can use it for our dynamically loaded libs and not just main program images from the kernel :)
2020-01-01LibELF: Replace kprintf's in ELFImage.cpp with dbgprintfAndrew Kaster
This lets us use the class in userspace
2019-11-28LibELF: Restore the relocation code from git historyAndreas Kling
This is going to be very useful for implementing kernel modules. We'll also need it for dynamic linking later on.
2019-11-06LibELF: Move AK/ELF/ into Libraries/LibELF/Andreas Kling
Let's arrange things like this instead. It didn't feel right for all of the ELF handling code to live in AK.