stivale: Make kaslr a config setting
diff --git a/limine-pxe.bin b/limine-pxe.bin
index f755ddd7..391f18d8 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index 3a8a4743..926cc7bd 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index c3c512ad..2c6f8729 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/lib/elf.c b/stage2/lib/elf.c
index 23440c28..b9bcae46 100644
--- a/stage2/lib/elf.c
+++ b/stage2/lib/elf.c
@@ -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;
}
diff --git a/stage2/protos/stivale.c b/stage2/protos/stivale.c
index 3a5738e7..72bf4698 100644
--- a/stage2/protos/stivale.c
+++ b/stage2/protos/stivale.c
@@ -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:
diff --git a/stage2/protos/stivale2.c b/stage2/protos/stivale2.c
index cdcccdfc..13a5728f 100644
--- a/stage2/protos/stivale2.c
+++ b/stage2/protos/stivale2.c
@@ -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:
diff --git a/test/limine.cfg b/test/limine.cfg
index b578fbc8..0af42a2c 100644
--- a/test/limine.cfg
+++ b/test/limine.cfg
@@ -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!
