stivale: Make kaslr a config setting
This commit is contained in:
parent
5bc1e8d830
commit
1f10b55b29
BIN
limine-pxe.bin
BIN
limine-pxe.bin
Binary file not shown.
BIN
limine.bin
BIN
limine.bin
Binary file not shown.
BIN
stage2.map
BIN
stage2.map
Binary file not shown.
@ -324,10 +324,7 @@ int elf64_load(struct file_handle *fd, uint64_t *entry_point, uint64_t *top, uin
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (hdr.type == ET_DYN)
|
||||
*entry_point = hdr.entry + slide;
|
||||
else
|
||||
*entry_point = hdr.entry;
|
||||
*entry_point = hdr.entry;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <mm/mtrr.h>
|
||||
#include <stivale/stivale.h>
|
||||
|
||||
#define KASLR_SLIDE_BITMASK 0x03FFFF000u
|
||||
#define KASLR_SLIDE_BITMASK 0x000FFF000u
|
||||
|
||||
struct stivale_struct stivale_struct = {0};
|
||||
|
||||
@ -61,16 +61,14 @@ void stivale_load(char *config, char *cmdline) {
|
||||
level5pg = true;
|
||||
}
|
||||
|
||||
ret = elf64_load_section(kernel, &stivale_hdr, ".stivalehdr", sizeof(struct stivale_header), slide);
|
||||
|
||||
if (!ret && ((stivale_hdr.flags >> 2) & 1)) {
|
||||
char *s_kaslr = config_get_value(config, 0, "KASLR");
|
||||
if (s_kaslr != NULL && !strcmp(s_kaslr, "yes")) {
|
||||
// KASLR is enabled, set the slide
|
||||
slide = rand64() & KASLR_SLIDE_BITMASK;
|
||||
|
||||
// Re-read the .stivalehdr with slid relocations
|
||||
ret = elf64_load_section(kernel, &stivale_hdr, ".stivalehdr", sizeof(struct stivale_header), slide);
|
||||
}
|
||||
|
||||
ret = elf64_load_section(kernel, &stivale_hdr, ".stivalehdr", sizeof(struct stivale_header), slide);
|
||||
|
||||
break;
|
||||
}
|
||||
case 32:
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <stivale/stivale2.h>
|
||||
#include <pxe/tftp.h>
|
||||
|
||||
#define KASLR_SLIDE_BITMASK 0x03FFFF000u
|
||||
#define KASLR_SLIDE_BITMASK 0x000FFF000u
|
||||
|
||||
struct stivale2_struct stivale2_struct = {0};
|
||||
|
||||
@ -83,16 +83,14 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
|
||||
level5pg = true;
|
||||
}
|
||||
|
||||
ret = elf64_load_section(kernel, &stivale2_hdr, ".stivale2hdr", sizeof(struct stivale2_header), slide);
|
||||
|
||||
if (!ret && (stivale2_hdr.flags & 1)) {
|
||||
char *s_kaslr = config_get_value(config, 0, "KASLR");
|
||||
if (s_kaslr != NULL && !strcmp(s_kaslr, "yes")) {
|
||||
// KASLR is enabled, set the slide
|
||||
slide = rand64() & KASLR_SLIDE_BITMASK;
|
||||
|
||||
// Re-read the .stivale2hdr with slid relocations
|
||||
ret = elf64_load_section(kernel, &stivale2_hdr, ".stivale2hdr", sizeof(struct stivale2_header), slide);
|
||||
}
|
||||
|
||||
ret = elf64_load_section(kernel, &stivale2_hdr, ".stivale2hdr", sizeof(struct stivale2_header), slide);
|
||||
|
||||
break;
|
||||
}
|
||||
case 32:
|
||||
|
@ -26,6 +26,19 @@ MODULE_STRING=yooooo
|
||||
MODULE_PATH=bios://:1/boot/bg.bmp
|
||||
MODULE_STRING=yooooo
|
||||
|
||||
::Stivale Test (KASLR)
|
||||
|
||||
PROTOCOL=stivale
|
||||
KASLR=yes
|
||||
KERNEL_PATH=boot://1/boot/test.elf
|
||||
KERNEL_CMDLINE=Hi! This is an example!
|
||||
|
||||
MODULE_PATH=bios://:1/boot/test.elf
|
||||
MODULE_STRING=yooooo
|
||||
|
||||
MODULE_PATH=bios://:1/boot/bg.bmp
|
||||
MODULE_STRING=yooooo
|
||||
|
||||
:Stivale2 Test
|
||||
|
||||
PROTOCOL=stivale2
|
||||
@ -40,6 +53,7 @@ MODULE_STRING=yooooo
|
||||
|
||||
PROTOCOL=stivale2
|
||||
RESOLUTION=640x480x16
|
||||
KASLR=yes
|
||||
KERNEL_PATH=bios://:1/boot/test.elf
|
||||
KERNEL_CMDLINE=Woah! Another example!
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user