From 9fc8ec0ce3a3ed6743a1bd45458d47c8ba3062b2 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sat, 29 Jan 2022 12:29:27 +0100 Subject: [PATCH] pmm_randomise_memory: Add guard for BIOS port to avoid accessing bogus pointers --- CONFIG.md | 2 +- stage23/mm/pmm.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CONFIG.md b/CONFIG.md index 5259f53f..d3998057 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -89,7 +89,7 @@ Some keys take *URIs* as values; these are described in the next section. * `EDITOR_HIGHLIGHTING` - If set to `no`, syntax highlighting in the editor will be disabled. Defaults to `yes`. * `EDITOR_VALIDATION` - If set to `no`, the editor will not alert you about invalid keys / syntax errors. Defaults to `yes`. * `VERBOSE` - If set to `yes`, print additional information during boot. Defaults to not verbose. -* `RANDOMISE_MEMORY` - If set to `yes`, randomise the contents of RAM at bootup in order to find bugs related to non zeroed memory or for security reasons. This option will slow down boot time significantly. +* `RANDOMISE_MEMORY` - If set to `yes`, randomise the contents of RAM at bootup in order to find bugs related to non zeroed memory or for security reasons. This option will slow down boot time significantly. For the BIOS port of Limine, this will only randomise memory below 4GiB. * `RANDOMIZE_MEMORY` - Alias of `RANDOMISE_MEMORY`. *Locally assignable (non protocol specific)* keys are: diff --git a/stage23/mm/pmm.c b/stage23/mm/pmm.c index a351afeb..8e0625e4 100644 --- a/stage23/mm/pmm.c +++ b/stage23/mm/pmm.c @@ -9,6 +9,14 @@ void pmm_randomise_memory(void) { if (memmap[i].type != MEMMAP_USABLE) continue; +#if bios == 1 + // We're not going to randomise memory above 4GiB from protected mode, + // are we? + if (memmap[i].base >= 0x100000000) { + continue; + } +#endif + uint8_t *ptr = (void *)(uintptr_t)memmap[i].base; size_t len = memmap[i].length;