mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 08:50:37 +00:00
DynamicLoader: Annotate all loaded library ranges as immutable
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.
This commit is contained in:
parent
8585b2dc23
commit
d97aa9cf8c
Notes:
sideshowbarker
2024-07-18 03:35:30 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/d97aa9cf8c Pull-request: https://github.com/SerenityOS/serenity/pull/16515 Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 13 additions and 5 deletions
|
@ -394,17 +394,25 @@ static Result<void, DlErrorMessage> link_main_library(DeprecatedString const& pa
|
|||
VERIFY(!result.is_error());
|
||||
auto& object = result.value();
|
||||
|
||||
if (loader.filepath().ends_with("/libc.so"sv)) {
|
||||
initialize_libc(*object);
|
||||
}
|
||||
|
||||
if (loader.filepath().ends_with("/libsystem.so"sv)) {
|
||||
VERIFY(!loader.text_segments().is_empty());
|
||||
for (auto const& segment : loader.text_segments()) {
|
||||
if (syscall(SC_annotate_mapping, segment.address().get(), static_cast<int>(VirtualMemoryRangeFlags::SyscallCode))) {
|
||||
auto flags = static_cast<int>(VirtualMemoryRangeFlags::SyscallCode) | static_cast<int>(VirtualMemoryRangeFlags::Immutable);
|
||||
if (syscall(SC_annotate_mapping, segment.address().get(), flags)) {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (auto const& segment : loader.text_segments()) {
|
||||
auto flags = static_cast<int>(VirtualMemoryRangeFlags::Immutable);
|
||||
if (syscall(SC_annotate_mapping, segment.address().get(), flags)) {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (loader.filepath().ends_with("/libc.so"sv)) {
|
||||
initialize_libc(*object);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue