summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibELF
AgeCommit message (Collapse)Author
2022-12-16DynamicLoader: Annotate all loaded library ranges as immutableLiav A
To further protect all virtual memory regions of the loaded libraries, don't allow to mutate these regions both in changing their annotations nor the protection bits.
2022-12-16Kernel: Reintroduce the msyscall syscall as the annotate_mapping syscallLiav A
This syscall will be used later on to ensure we can declare virtual memory mappings as immutable (which means that the underlying Region is basically immutable for both future annotations or changing the protection bits of it).
2022-12-11Kernel+LibC+LibELF: Set stack size based on PT_GNU_STACK during execvesin-ack
Some programs explicitly ask for a different initial stack size than what the OS provides. This is implemented in ELF by having a PT_GNU_STACK header which has its p_memsz set to the amount that the program requires. This commit implements this policy by reading the p_memsz of the header and setting the main thread stack size to that. ELF::Image::validate_program_headers ensures that the size attribute is a reasonable value.
2022-12-06Everywhere: Rename to_{string => deprecated_string}() where applicableLinus Groh
This will make it easier to support both string types at the same time while we convert code, and tracking down remaining uses. One big exception is Value::to_string() in LibJS, where the name is dictated by the ToString AO.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-11-29LibELF: Add stack guard hardeningKeegan Saunders
Employ the same hardening that glibc and the Linux kernel use for generating stack guards: zero the first byte of the guard such that if C-style string functions read out of bounds on the stack, we do not overwrite or potentially leak the stack guard.
2022-11-29LibC: Use uintptr_t for __stack_chk_guardKeegan Saunders
We used size_t, which is a type that is guarenteed to be large enough to hold an array index, but uintptr_t is designed to be used to hold pointer values, which is the case of stack guards.
2022-10-31LibELF: Drop the "resolve and map" all-in-oneTim Schumacher
Both users of this function now have to do their resolving separately before anyways, so let's just drop the resolving part inside the function and require absolute paths to be fed in instead.
2022-10-31LibELF: Track libraries using their full pathTim Schumacher
2022-10-31LibELF: Handle absolute and relative paths for all resolve requestsTim Schumacher
2022-10-31LibELF: Sift down "library name only"-strings as far as possibleTim Schumacher
I might have gone a bit overboard with the `VERIFY`s, but this allows for very easy tracking of where we start to leak in non-absolute paths.
2022-10-31LibELF: Use a bit of `TRY` in `DynamicLinker`Tim Schumacher
`TRY` also works for `Result<>`. Who knew?
2022-10-31LibELF: Prepend `resolve_and` to one of the `map_library` overloadsTim Schumacher
Having two functions that are named the same and whose behavior regarding "should probably get a full path" and "does explicitly not require a full path" is quite confusing, especially since that difference is dictated through the other passed arguments.
2022-10-31LibELF: Drop the separate file name member from DynamicLoaderTim Schumacher
2022-10-31LibELF: Ensure that DynamicLoader only receives absolute pathsTim Schumacher
While at it, start renaming variables where we know that they store a path, so that we will get less confused in the future.
2022-10-14AK+Userland: Stub out code that isn't currently implemented on AARCH64Gunnar Beutner
Even though this almost certainly wouldn't run properly even if we had a working kernel for AARCH64 this at least lets us build all the userland binaries.
2022-10-10Everywhere: Replace uses of __serenity__ with AK_OS_SERENITYAndrew Kaster
Now that we have OS macros for essentially every supported OS, let's try to use them everywhere.
2022-09-05LibC: Move `dlfcn_integration.h` to the `bits` directoryTim Schumacher
2022-09-05Everywhere: Refer to `dlfcn*.h` by its non-prefixed nameTim Schumacher
2022-07-21Utilities+LibELF: Temporary promises for dynamic linker in "pledge"Itamar
This adds a "temporary promises for the dynamic-linker" flag ('-d') to the "pledge" utility. Example usage: pledge -d -p "stdio rpath" id Without the '-d' flag, id would crash because the dynamic linker requires 'prot_exec'. When this flag is used and the program to be run is dynamically linked, "pledge" adds promises that are required by the dynamic linker to the promise set provided by the user. The dynamic linker will later "give up" the pledge promises it no longer requires.
2022-07-20LibELF: Copy the entire TLS segment instead of each symbol one-by-oneTim Schumacher
This automatically fixes an issue where we were accidentally copying garbage data from beyond the TLS segment as uninitialized data isn't actually stored inside the image.
2022-07-20LibELF: Remove outdated TLS handling in generic program header codeTim Schumacher
2022-07-19LibC: Remove a bunch of weak `pthread_*` symbolsTim Schumacher
2022-07-12Everywhere: Use default StringView constructor over nullptrsin-ack
While null StringViews are just as bad, these prevent the removal of StringView(char const*) as that constructor accepts a nullptr. No functional changes.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-12Everywhere: Explicitly specify the size in StringView constructorssin-ack
This commit moves the length calculations out to be directly on the StringView users. This is an important step towards the goal of removing StringView(char const*), as it moves the responsibility of calculating the size of the string to the user of the StringView (which will prevent naive uses causing OOB access).
2022-07-10DynamicLoader: Stop performing relative relocations on non-pie objectsIdan Horowitz
Co-authored-by: Daniel Bertalan <dani@danielbertalan.dev>
2022-07-08LibC: Move stack canary initialization before the global constructorsTim Schumacher
Once again, QEMU creates threads while running its constructors, which is a recipe for disaster if we switch out the stack guard while that is already running in the background. To solve that, move initialization to our LibC initialization stage, which is before any actual external initialization code runs.
2022-07-06AK: Use an enum instead of a bool for String::replace(all_occurences)DexesTTP
This commit has no behavior changes. In particular, this does not fix any of the wrong uses of the previous default parameter (which used to be 'false', meaning "only replace the first occurence in the string"). It simply replaces the default uses by String::replace(..., ReplaceMode::FirstOnly), leaving them incorrect.
2022-07-05LibELF: Take TLS segment alignment into account in DynamicLoaderIdan Horowitz
Previously we would just tightly pack the different libraries' TLS segments together, but that is incorrect, as they might require some kind of minimum alignment for their TLS base address. We now plumb the required TLS segment alignment down to the TLS block linear allocator and align the base address down to the appropriate alignment.
2022-06-30LibELF: Store the full file path in DynamicObjectTim Schumacher
Otherwise, our `dirname` call on the parent object will always be empty when trying to resolve dependencies.
2022-06-24LibELF: Warn on self-dlopening libraries while initializingTim Schumacher
2022-06-24LibELF: Check if initializers ran instead of trusting s_global_objectsTim Schumacher
The original heuristic of "a library being in `s_global_objects` means that it was fully initialized already" doesn't hold up anymore since we changed the loading order. This was causing us to skip parts of the initialization of dependency libraries when running dlopen (since it was the only user of that setting). Instead, set a flag after we run stage 4 (which is the "run the global initializers" stage) and check that flag when determining unfinished dependencies. This entirely replaces the `skip_global_objects` logic.
2022-06-21LibELF: Only collect region sizes before reserving memoryTim Schumacher
This keeps us from needlessly allocating storage via `malloc` as part of the `Vector`s that early, which we might conflict on while reserving memory for the main executable.
2022-06-21LibELF: Unmap the source file temporarily while reserving spaceTim Schumacher
This further reduces the chance that we will conflict with data that is already present at the target location.
2022-06-21LibELF: Store DynamicLoader ELF images using an OwnPtrTim Schumacher
This is preparation work for the next commit, where we will replace the stored ELF image mid-load.
2022-06-21LibELF: Actually do the library mapping as early as possibleTim Schumacher
We previously trusted the `map` part in `map_library` too much, and assumed that this would already lock in the binary at its final place. However, the `map()` function of the loader was only called in `load_main_library`, which ran only right before jumping to the entrypoint. Make our binary loading a bit more stable by actually mapping the binary right after we read its information, and only do the linking right before jumping to the entrypoint.
2022-06-12LibELF: Always use parent object basename for $ORIGIN processingAndrew Kaster
Using the main executable basename produces the wrong $ORIGIN processing for libraries that are secondary dependencies of the main executable, or dependencies of an object loaded via dlopen.
2022-05-07LibELF: Name library maps with the full file pathTim Schumacher
2022-05-07LibELF: Separate library resolving into a new functionTim Schumacher
2022-05-01LibELF: Fail gracefully when IFUNC resolver's object has textrelsDaniel Bertalan
.text sections of objects that contain textrels have to be writable during the relocation procedure. Because of this, we would segfault if we tried to execute IFUNC resolvers defined in them. Let's print a meaningful error message instead. Additionally, a warning is now printed when we load objects with textrels, as in the future, additional security mitigations might interfere with them being loaded.
2022-05-01LibELF: Add support for IFUNCsDaniel Bertalan
IFUNC is a GNU extension to the ELF standard that allows a function to have multiple implementations. A resolver function has to be called at load time to choose the right one to use. The PLT will contain the entry to the resolved function, so branching and more indirect jumps can be avoided at run-time. This mechanism is usually used when a routine can be made faster using CPU features that are available in only some models, and a fallback implementation has to exist for others. We will use this feature to have two separate memset implementations for CPUs with and without ERMS (Enhanced REP MOVSB/STOSB) support.
2022-05-01LibELF: Keep track of whether the PLT contains REL or RELA relocationsDaniel Bertalan
2022-05-01LibELF: Perform .relr.dyn relocations before .rel.dynDaniel Bertalan
IFUNC resolvers depend on the resolved function's address having been relocated by the time they are called. This means that relative relocations have to be done first. The linker is kind enough to put R_*_RELATIVE before R_*_IRELATIVE in .rel.dyn, but .relr.dyn contains relative relocations too.
2022-05-01LibELF: Relax restriction on allowed values of EI_OSABI to allow GNUAndrew Kaster
This check is here to make sure we only try to load serenity binaries. However, with -fprofile-instr-generate -fcoverage-mapping, clang sets the EI_OSABI field to 3, for GNU. The instrumentation uses a lot of retained COMDAT sections for coverage instrumentation that get the SHF_GNU_RETAINED section header flag set on them, forcing llvm to set the ABI to GNU.
2022-04-03LibELF: Look up symbols in all global modulesTimur Sultanov
dlsym() called with RTLD_DEFAULT (nullptr) should look up symbol in all global modules instead of only looking into the executable file
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-31LibELF: Remove unused m_program_interpreter member from DynamicLoaderBrian Gianforcaro
While profiling I realized that this member is unused, so the StringBuilder and String allocation are completely un-necessary.
2022-03-31LibELF: Skip DynamicObject::dump() if logging isn't enabledBrian Gianforcaro
I noticed that we were populating this StringBuilder and then throwing away the result while profiling `true` with UserSpace emulator. Before: courage:~ $ time -n 1000 true Timing report: 3454 ms ============== Command: true Average time: 3.45 ms (median: 3, stddev: 3.42, min: 0, max:11) Excluding first: 3.45 ms (median: 3, stddev: 3.42, min: 0, max:11) After: courage:~ $ time -n 1000 true Timing report: 3308 ms ============== Command: true Average time: 3.30 ms (median: 3, stddev: 3.28, min: 0, max:12) Excluding first: 3.30 ms (median: 3, stddev: 3.29, min: 0, max:12)
2022-03-10Libraries: Use default constructors/destructors in LibELFLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."