forked from pepper-org/pepperOS
Stack Smashing Protection
This commit is contained in:
+16
-1
@@ -12,6 +12,15 @@
|
||||
#include <kernel.h>
|
||||
#include <time/date.h>
|
||||
|
||||
__attribute__((noinline))
|
||||
void smash_it()
|
||||
{
|
||||
char buf[16]; (void)buf;
|
||||
for (size_t i=0; i<256; i++) {
|
||||
buf[i] = (char)i;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* pedicel_main - Kernel shell main function
|
||||
* @arg: argument (optional)
|
||||
@@ -38,7 +47,8 @@ void pedicel_main(void* arg)
|
||||
"panic - trigger a test panic\r\n"
|
||||
"syscall - trigger int 0x80\r\n"
|
||||
"pf - trigger a page fault\r\n"
|
||||
"now - get current date\r\n");
|
||||
"now - get current date\r\n"
|
||||
"smash - smash the stack\r\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -64,6 +74,11 @@ void pedicel_main(void* arg)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strncmp(input_buf, "smash", 5) == 0) {
|
||||
smash_it();
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s: command not found\r\n", input_buf);
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,15 @@ void thing_main(void* arg)
|
||||
|
||||
extern uintptr_t kheap_start;
|
||||
|
||||
/* Stack Smashing Protection */
|
||||
|
||||
uint64_t __stack_chk_guard = STACK_CHK_GUARD;
|
||||
|
||||
void __stack_chk_fail(void)
|
||||
{
|
||||
panic(NULL, "SSP: Stask Smashing Detected!!! (very spicy)");
|
||||
}
|
||||
|
||||
/*
|
||||
* kmain - Kernel entry point
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user