elf: Add guards to prevent non-higher half 64-bit kernels from loading when using PMRs or fully virtual mappings
diff --git a/stage23/lib/elf.c b/stage23/lib/elf.c
index 80863635..38203594 100644
--- a/stage23/lib/elf.c
+++ b/stage23/lib/elf.c
@@ -371,6 +371,10 @@ static void elf64_get_ranges(uint8_t *elf, uint64_t slide, bool use_paddr, struc
ranges_count++;
}
+ if (ranges_count == 0) {
+ panic("elf: Attempted to use PMRs but no higher half PHDR exists");
+ }
+
struct elf_range *ranges = ext_mem_alloc(ranges_count * sizeof(struct elf_range));
size_t r = 0;
@@ -466,6 +470,10 @@ int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_sl
}
}
+ if (max_vaddr == 0 || min_vaddr == (uint64_t)-1) {
+ panic("elf: Attempted to use fully virtual mappings but no higher half PHDR exists");
+ }
+
image_size = max_vaddr - min_vaddr;
*physical_base = (uintptr_t)ext_mem_alloc_type_aligned(image_size, alloc_type, max_align);
