:: commit a9d69d3823a86c3c00e68a83f2057297a659972f

mintsuki <mintsuki@protonmail.com> — 2020-12-01 02:19

parents: 4c09663a28

linux: Fix issue where command line buffer might be in memory in an address outside the range the boot protocol mandates

diff --git a/limine-pxe.bin b/limine-pxe.bin
index ce964849..276c6502 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index d733c71e..80ec8d5a 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index 29a91ec2..970d7fc3 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/protos/linux.c b/stage2/protos/linux.c
index 5e1c420e..cbeb6acd 100644
--- a/stage2/protos/linux.c
+++ b/stage2/protos/linux.c
@@ -2,6 +2,7 @@
 #include <stddef.h>
 #include <protos/linux.h>
 #include <fs/file.h>
+#include <lib/libc.h>
 #include <lib/blib.h>
 #include <lib/real.h>
 #include <lib/term.h>
@@ -120,7 +121,12 @@ void linux_load(char *config, char *cmdline) {
     *((uint8_t *)(real_mode_code + 0x211)) = loadflags;
 
     // cmdline
-    *((uint32_t *)(real_mode_code + 0x228)) = (uint32_t)cmdline;
+    // the command line needs to be before address 0xa0000, we can use
+    // conv_mem_alloc() for that
+    size_t cmdline_len = strlen(cmdline);
+    char *cmdline_reloc = conv_mem_alloc(cmdline_len + 1);
+    strcpy(cmdline_reloc, cmdline);
+    *((uint32_t *)(real_mode_code + 0x228)) = (uint32_t)cmdline_reloc;
 
     // load kernel
     print("Loading kernel...\n");
tab: 248 wrap: offon