Skip to content

Commit c2136dc

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
efi/libstub/arm64: Avoid image_base value from efi_loaded_image
Commit: 9f92237 ("efi/libstub/arm: Make efi_entry() an ordinary PE/COFF entrypoint") did some code refactoring to get rid of the EFI entry point assembler code, and in the process, it got rid of the assignment of image_addr to the value of _text. Instead, it switched to using the image_base field of the efi_loaded_image struct provided by UEFI, which should contain the same value. However, Michael reports that this is not the case: older GRUB builds corrupt this value in some way, and since we can easily switch back to referring to _text to discover this value, let's simply do that. While at it, fix another issue in commit 9f92237, which may result in the unassigned image_addr to be misidentified as the preferred load offset of the kernel, which is unlikely but will cause a boot crash if it does occur. Finally, let's add a warning if the _text vs. image_base discrepancy is detected, so we can tell more easily how widespread this issue actually is. Reported-by: Michael Kelley <[email protected]> Tested-by: Michael Kelley <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected]
1 parent d5528d5 commit c2136dc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/firmware/efi/libstub/arm64-stub.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
116116
* Mustang), we can still place the kernel at the address
117117
* 'dram_base + TEXT_OFFSET'.
118118
*/
119+
*image_addr = (unsigned long)_text;
119120
if (*image_addr == preferred_offset)
120121
return EFI_SUCCESS;
121122

@@ -140,7 +141,11 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
140141
}
141142
*image_addr = *reserve_addr + TEXT_OFFSET;
142143
}
143-
memcpy((void *)*image_addr, image->image_base, kernel_size);
144+
145+
if (image->image_base != _text)
146+
pr_efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n");
147+
148+
memcpy((void *)*image_addr, _text, kernel_size);
144149

145150
return EFI_SUCCESS;
146151
}

0 commit comments

Comments
 (0)