From 7f024ecfc31dd82aaa70e38dae0a955a41ee1270 Mon Sep 17 00:00:00 2001 From: sobomax Date: Fri, 19 Jun 2015 17:00:36 +0000 Subject: Fix bug in the ubldr introduced in the rev.283035. The new code fails to properly consider memory regions when the loader is located below of those regions or engulfs their lower limit. This results in "not enough RAM to load kernel" panic, which is totally bogus. On top of that, there are some variables that can be left unitialized in those cases, which might cause it fail with memory access violation instead of panic while trying to load kernel to a wrong or non-existing address of memory. Augment the code to properly deal with the loader being below or at the lower bound of the memory region in question. Also, don't leave ununitialized variables behind. Reviewed by: ian --- sys/boot/uboot/lib/copy.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sys/boot/uboot/lib/copy.c') diff --git a/sys/boot/uboot/lib/copy.c b/sys/boot/uboot/lib/copy.c index bb658e3..51416ac 100644 --- a/sys/boot/uboot/lib/copy.c +++ b/sys/boot/uboot/lib/copy.c @@ -118,6 +118,13 @@ uboot_loadaddr(u_int type, void *data, uint64_t addr) this_block = eubldr; this_size = eblock - eubldr; } + } else if (subldr < sblock && eubldr < eblock) { + /* Loader is below or engulfs the sblock */ + this_block = (eubldr < sblock) ? sblock : eubldr; + this_size = eblock - this_block; + } else { + this_block = 0; + this_size = 0; } if (biggest_size < this_size) { biggest_block = this_block; -- cgit v1.1