]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[initrd] Allow for images straddling the top of the reshuffle region
authorMichael Brown <mcb30@ipxe.org>
Thu, 22 May 2025 13:12:12 +0000 (14:12 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 22 May 2025 15:28:15 +0000 (16:28 +0100)
It is hypothetically possible for external heap memory allocated
during driver startup to have been freed before an image was
downloaded, which could therefore leave an image straddling the
address recorded as the top of the reshuffle region.

Allow for this possibility by skipping squashing for any images
already straddling (or touching) the top of the reshuffle region.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/image/initrd.c

index 5e87355180e70347607cbc9bbade8473952c5ffb..5ba8c473deacaf0bfb64a6d01c24c20c73be9441 100644 (file)
@@ -68,8 +68,15 @@ static void initrd_squash_high ( physaddr_t top ) {
                if ( ! highest )
                        break;
 
-               /* Move this image to its final position */
+               /* Calculate final position */
                current -= initrd_align ( highest->len );
+               if ( current <= virt_to_phys ( highest->data ) ) {
+                       /* Already at (or crossing) top of region */
+                       current = virt_to_phys ( highest->data );
+                       continue;
+               }
+
+               /* Move this image to its final position */
                DBGC ( &images, "INITRD squashing %s [%#08lx,%#08lx)->"
                       "[%#08lx,%#08lx)\n", highest->name,
                       virt_to_phys ( highest->data ),