summaryrefslogtreecommitdiff
path: root/Libraries/LibELF
AgeCommit message (Collapse)Author
2020-03-08Userspace: Add missing #includes now that AK/StdLibExtras.h is smallerAndreas Kling
2020-03-08AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*)Andreas Kling
Use this instead of uintptr_t throughout the codebase. This makes it possible to pass a FlatPtr to something that has u32 and u64 overloads.
2020-03-03AK: Make quick_sort() a little more ergonomicAndreas Kling
Now it actually defaults to "a < b" comparison, instead of forcing you to provide a trivial less-than comparator. Also you can pass in any collection type that has .begin() and .end() and we'll sort it for you.
2020-02-29LibELF: Use MAP_PRIVATE for file-backed mmaps in ELFDynamicLoaderAndrew Kaster
Clean up some unused code, clean up FIXMEs, and remove premature --dynamic-loader/-pie from LinkDemo (so it runs again on master)
2020-02-22LibELF: Avoid unnecessarily recomputing loop boundaries over and overAndreas Kling
2020-02-21LibELF: Use the ELF_STRTAB string constant instead of hard-codingAndreas Kling
2020-02-19LibELF: Short-circuit symbolication when there are no symbolsAndreas Kling
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-14AK: Add a forward declaration headerAndreas Kling
You can now #include <AK/Forward.h> to get most of the AK types as forward declarations. Header dependency explosion is one of the main contributors to compile times at the moment, so this is a step towards smaller include graphs.
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-02-09LibELF: Use VirtualAddress class from LibBareMetalLiav A
2020-02-06LibGfx: Unpublish Gfx::Size from the global namespaceAndreas Kling
2020-02-02Meta: Claim copyright on files added by meAndrew Kaster
Demos/DynamicLink, LibC/cxxabi.cpp, and LibELF/ELFDynamic*.[cpp/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-10Kernel+LibELF: Enable SMAP protection during non-syscall exec()Andreas Kling
When loading a new executable, we now map the ELF image in kernel-only memory and parse it there. Then we use copy_to_user() when initializing writable regions with data from the executable. Note that the exec() syscall still disables SMAP protection and will require additional work. This patch only affects kernel-originated process spawns.
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-09LibELF: Map .text segment with MAP_ANONYMOUS for shared objectsAndrew Kaster
We need to workaround the fact that MAP_PRIVATE when passed a file descriptor doesn't work the way we expect. We can't change the permissions on our mmap to PROT_WRITE if the original executable doesn't have PROT_WRITE. Because of this, we need to construct our ELFDynamicObject using the actual virtual address of the .dynamic section, instead of using the offset into the ELFImage that was actually getting modified by accident ...somehow. Not clear what was going on.
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-02LibELF: Simplify R_386_32 relocations to ignore symbol bind valueAndrew Kaster
For dynamic loading, the symbol bind of a symbol actually doesn't matter. We could do what old glibc did and try to find a strong symbol for any weak definitions, but the ELF spec doesn't require it and they changed that a few years ago anyway. So, moot point. :)
2020-01-01LibELF: Re-organize ELFDynamicObject::load and add PLT trampolineAndrew Kaster
ELFDynamicObject::load looks a lot better with all the steps re-organized into helpers. Add plt_trampoline.S to handle PLT fixups for lazy loading. Add the needed trampoline-trampolines in ELFDynamicObject to get to the proper relocations and to return the symbol back to the assembly method to call into from the PLT once we return back to user code.
2020-01-01LibELF: Call DT_INIT method now that startfiles are correct for DSOsAndrew Kaster
We weren't calling the method here before because it was ill-formed. No start files meant that we got the front half of the init section but not the back half (no 'ret' in _init!). Now that we have the proper crtbeginS and crtendS files from libgcc to help us out, we can assume that DSOs will have the proper _init method defined.
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-12-25Kernel: Make kernel memory regions be non-executable by defaultAndreas Kling
From now on, you'll have to request executable memory specifically if you want some.
2019-12-20Build: clean up build system, use one shared Makefilejoshua stein
Allow everything to be built from the top level directory with just 'make', cleaned with 'make clean', and installed with 'make install'. Also support these in any particular subdirectory. Specifying 'make VERBOSE=1' will print each ld/g++/etc. command as it runs. Kernel and early host tools (IPCCompiler, etc.) are built as object.host.o so that they don't conflict with other things built with the cross-compiler.
2019-12-12Kernel: Separate out the symbol offsets in profile outputAndreas Kling
Instead of saying "main +39" and "main +57" etc, we now have a separate field in /proc/profile for the offset-into-the-symbol.
2019-11-29Kernel: Demangle kernel C++ symbols correctly againAndreas Kling
I broke this while implementing module linking. Also move the actual demangling work to AK, in AK::demangle(const char*)
2019-11-28LibELF: Add ELFImage::Symbol::bind()Andreas Kling
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-27Kernel: Demangle userspace ELF symbols in backtracesAndreas Kling
Turns out we can use abi::__cxa_demangle() for this, and all we need to provide is sprintf(), realloc() and free(), so this patch exposes them. We now have fully demangled C++ backtraces :^)
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.