mirror of
https://github.com/systemd/systemd.git
synced 2026-08-11 09:36:28 +00:00
boot: reject inner kernel entry point outside the image
pe_kernel_info() returned AddressOfEntryPoint (and the .compat section entry_point) straight from the PE header with no check against SizeOfImage. Sincecab9c7b5a4the stub calls the inner kernel directly as ImageBase + entry_point, and only EFI_SIZE_TO_PAGES(SizeOfImage) pages are allocated for it. Follow-up forcab9c7b5a4(cherry picked from commitecf3f5056a) (cherry picked from commit1dbedeef33) (cherry picked from commita10dd5d8df)
This commit is contained in:
@@ -495,6 +495,10 @@ EFI_STATUS pe_kernel_info(
|
||||
return EFI_UNSUPPORTED;
|
||||
|
||||
if (pe->FileHeader.Machine == TARGET_MACHINE_TYPE) {
|
||||
/* The entry point is later called as ImageBase + entry_point, and only SizeOfImage
|
||||
* bytes are allocated for the image, so reject an entry point outside of it. */
|
||||
if (pe->OptionalHeader.AddressOfEntryPoint >= size_in_memory)
|
||||
return EFI_LOAD_ERROR;
|
||||
if (ret_entry_point)
|
||||
*ret_entry_point = pe->OptionalHeader.AddressOfEntryPoint;
|
||||
if (ret_compat_entry_point)
|
||||
@@ -510,6 +514,9 @@ EFI_STATUS pe_kernel_info(
|
||||
if (compat_entry_point == 0)
|
||||
/* Image type not supported and no compat entry found. */
|
||||
return EFI_UNSUPPORTED;
|
||||
if (compat_entry_point >= size_in_memory)
|
||||
/* Same as above: the compat entry point is called as ImageBase + entry_point. */
|
||||
return EFI_LOAD_ERROR;
|
||||
|
||||
if (ret_entry_point)
|
||||
*ret_entry_point = 0;
|
||||
|
||||
Reference in New Issue
Block a user