Parcourir la source

crash: Add "-X" option for attempting to execute non-executable memory

Andreas Kling il y a 5 ans
Parent
commit
33efeaf71a
2 fichiers modifiés avec 17 ajouts et 1 suppressions
  1. 1 0
      Base/usr/share/man/man1/crash.md
  2. 16 1
      Userland/crash.cpp

+ 1 - 0
Base/usr/share/man/man1/crash.md

@@ -30,6 +30,7 @@ kinds of crashes.
 * `-S`: Make a syscall from writeable memory.
 * `-S`: Make a syscall from writeable memory.
 * `-x`: Read from recently freed memory. (Tests an opportunistic malloc guard.)
 * `-x`: Read from recently freed memory. (Tests an opportunistic malloc guard.)
 * `-y`: Write to recently freed memory. (Tests an opportunistic malloc guard.)
 * `-y`: Write to recently freed memory. (Tests an opportunistic malloc guard.)
+* `-X`: Attempt to execute non-executable memory. (Not mapped with PROT\_EXEC.)
 
 
 ## Examples
 ## Examples
 
 

+ 16 - 1
Userland/crash.cpp

@@ -6,7 +6,7 @@
 
 
 static void print_usage_and_exit()
 static void print_usage_and_exit()
 {
 {
-    printf("usage: crash -[sdiamfMFTt]\n");
+    printf("usage: crash -[sdiamfMFTtSxyX]\n");
     exit(0);
     exit(0);
 }
 }
 
 
@@ -28,6 +28,7 @@ int main(int argc, char** argv)
         SyscallFromWritableMemory,
         SyscallFromWritableMemory,
         WriteToFreedMemoryStillCachedByMalloc,
         WriteToFreedMemoryStillCachedByMalloc,
         ReadFromFreedMemoryStillCachedByMalloc,
         ReadFromFreedMemoryStillCachedByMalloc,
+        ExecuteNonExecutableMemory,
     };
     };
     Mode mode = SegmentationViolation;
     Mode mode = SegmentationViolation;
 
 
@@ -62,6 +63,8 @@ int main(int argc, char** argv)
         mode = ReadFromFreedMemoryStillCachedByMalloc;
         mode = ReadFromFreedMemoryStillCachedByMalloc;
     else if (String(argv[1]) == "-y")
     else if (String(argv[1]) == "-y")
         mode = WriteToFreedMemoryStillCachedByMalloc;
         mode = WriteToFreedMemoryStillCachedByMalloc;
+    else if (String(argv[1]) == "-X")
+        mode = ExecuteNonExecutableMemory;
     else
     else
         print_usage_and_exit();
         print_usage_and_exit();
 
 
@@ -184,6 +187,18 @@ int main(int argc, char** argv)
         ASSERT_NOT_REACHED();
         ASSERT_NOT_REACHED();
     }
     }
 
 
+    if (mode == ExecuteNonExecutableMemory) {
+        auto* ptr = (u8*)mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
+        ASSERT(ptr != MAP_FAILED);
+
+        ptr[0] = 0xc3; // ret
+
+        typedef void* (*CrashyFunctionPtr)();
+        ((CrashyFunctionPtr)ptr)();
+
+        ASSERT_NOT_REACHED();
+    }
+
     ASSERT_NOT_REACHED();
     ASSERT_NOT_REACHED();
     return 0;
     return 0;
 }
 }