ソースを参照

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.
Liav A 2 年 前
コミット
d97aa9cf8c
1 ファイル変更13 行追加5 行削除
  1. 13 5
      Userland/Libraries/LibELF/DynamicLinker.cpp

+ 13 - 5
Userland/Libraries/LibELF/DynamicLinker.cpp

@@ -394,17 +394,25 @@ static Result<void, DlErrorMessage> link_main_library(DeprecatedString const& pa
         VERIFY(!result.is_error());
         VERIFY(!result.is_error());
         auto& object = result.value();
         auto& object = result.value();
 
 
+        if (loader.filepath().ends_with("/libc.so"sv)) {
+            initialize_libc(*object);
+        }
+
         if (loader.filepath().ends_with("/libsystem.so"sv)) {
         if (loader.filepath().ends_with("/libsystem.so"sv)) {
             VERIFY(!loader.text_segments().is_empty());
             VERIFY(!loader.text_segments().is_empty());
             for (auto const& segment : loader.text_segments()) {
             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();
                     VERIFY_NOT_REACHED();
                 }
                 }
             }
             }
-        }
-
-        if (loader.filepath().ends_with("/libc.so"sv)) {
-            initialize_libc(*object);
         }
         }
     }
     }