]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[bzimage] Fix page alignment of initrd images
authorMichael Brown <mcb30@ipxe.org>
Fri, 28 Oct 2016 23:08:48 +0000 (00:08 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 28 Oct 2016 23:32:33 +0000 (00:32 +0100)
The initrd_addr_max field represents the highest byte address that may
be used to hold initrd images, and is therefore almost certainly not
aligned to a page boundary: a typical value might be 0x7fffffff.

Fix the address calculations to ensure that the initrd images are
always aligned to a page boundary.

Reported-by: Sitsofe Wheeler <sitsofe@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/image/bzimage.c

index d9b5ddc073f071ccd053b0681d5fc3d70ce9c3f8..e3c4cb83d04ef2f2172914c7689edc8e401f3943 100644 (file)
@@ -522,10 +522,12 @@ static void bzimage_load_initrds ( struct image *image,
 
        /* Find highest usable address */
        top = userptr_add ( highest->data, bzimage_align ( highest->len ) );
-       if ( user_to_phys ( top, 0 ) > bzimg->mem_limit )
-               top = phys_to_user ( bzimg->mem_limit );
+       if ( user_to_phys ( top, -1 ) > bzimg->mem_limit ) {
+               top = phys_to_user ( ( bzimg->mem_limit + 1 ) &
+                                    ~( INITRD_ALIGN - 1 ) );
+       }
        DBGC ( image, "bzImage %p loading initrds from %#08lx downwards\n",
-              image, user_to_phys ( top, 0 ) );
+              image, user_to_phys ( top, -1 ) );
 
        /* Load initrds in order */
        for_each_image ( initrd ) {