Explorar el Código

Kernel: Randomize the stack canary on startup

Andreas Kling hace 5 años
padre
commit
99f71a9a2c
Se han modificado 2 ficheros con 6 adiciones y 3 borrados
  1. 0 3
      Kernel/StdLib.cpp
  2. 6 0
      Kernel/init.cpp

+ 0 - 3
Kernel/StdLib.cpp

@@ -213,9 +213,6 @@ void free(void* p)
     return kfree(p);
 }
 
-extern u32 __stack_chk_guard;
-u32 __stack_chk_guard = (u32)0xc0000c13;
-
 [[noreturn]] void __stack_chk_fail()
 {
     ASSERT_NOT_REACHED();

+ 6 - 0
Kernel/init.cpp

@@ -44,6 +44,7 @@
 #include <Kernel/Net/RTL8139NetworkAdapter.h>
 #include <Kernel/PCI/Access.h>
 #include <Kernel/PCI/Initializer.h>
+#include <Kernel/Random.h>
 #include <Kernel/TTY/PTYMultiplexer.h>
 #include <Kernel/TTY/VirtualConsole.h>
 #include <Kernel/VM/MemoryManager.h>
@@ -219,6 +220,9 @@ extern "C" int __cxa_atexit(void (*)(void*), void*, void*)
     return 0;
 }
 
+extern u32 __stack_chk_guard;
+u32 __stack_chk_guard;
+
 extern "C" [[noreturn]] void init(u32 physical_address_for_kernel_page_tables)
 {
     // this is only used one time, directly below here. we can't use this part
@@ -313,6 +317,8 @@ extern "C" [[noreturn]] void init(u32 physical_address_for_kernel_page_tables)
         kprintf("x86: No RDRAND support detected. Randomness will be shitty\n");
     }
 
+    __stack_chk_guard = get_good_random<u32>();
+
     RTC::initialize();
     PIC::initialize();
     gdt_init();