Commit acd644bb authored by H. Peter Anvin's avatar H. Peter Anvin Committed by Ingo Molnar

x86 setup: guard the heap against invalid stack setups

If we use the bootloader-provided stack pointer, we might end up in a
situation where the bootloader (incorrectly) pointed the stack in the
middle of our heap.  Catch this by simply comparing the computed heap
end value to the stack pointer minus the defined stack size.
Signed-off-by: default avatarH. Peter Anvin <hpa@zytor.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 1a8514e0
...@@ -100,20 +100,32 @@ static void set_bios_mode(void) ...@@ -100,20 +100,32 @@ static void set_bios_mode(void)
#endif #endif
} }
void main(void) static void init_heap(void)
{ {
/* First, copy the boot header into the "zeropage" */ char *stack_end;
copy_boot_params();
/* End of heap check */
if (boot_params.hdr.loadflags & CAN_USE_HEAP) { if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
heap_end = (char *)(boot_params.hdr.heap_end_ptr asm("leal %P1(%%esp),%0"
+0x200-STACK_SIZE); : "=r" (stack_end) : "i" (-STACK_SIZE));
heap_end = (char *)
((size_t)boot_params.hdr.heap_end_ptr + 0x200);
if (heap_end > stack_end)
heap_end = stack_end;
} else { } else {
/* Boot protocol 2.00 only, no heap available */ /* Boot protocol 2.00 only, no heap available */
puts("WARNING: Ancient bootloader, some functionality " puts("WARNING: Ancient bootloader, some functionality "
"may be limited!\n"); "may be limited!\n");
} }
}
void main(void)
{
/* First, copy the boot header into the "zeropage" */
copy_boot_params();
/* End of heap check */
init_heap();
/* Make sure we have all the proper CPU support */ /* Make sure we have all the proper CPU support */
if (validate_cpu()) { if (validate_cpu()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment