[U-Boot] [PATCH v2 1/1] efi_loader: abort on unsupported relocation type

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Jul 3 22:12:58 UTC 2017


From: "xypron.glpk at gmx.de" <xypron.glpk at gmx.de>

If a relocation type is not supported loading the EFI binary
should be aborted.

Writing a message only is insufficient.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
v2
	Use (uintptr_t) to convert a pointer to an integer. This avoids
	'warning: cast from pointer to integer of different size' on
	32bit systems.
---
 lib/efi_loader/efi_image_loader.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c
index 3262d76bca..607feff4e9 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -26,7 +26,7 @@ efi_status_t EFIAPI efi_return_handle(void *handle, efi_guid_t *protocol,
 	return EFI_SUCCESS;
 }
 
-static void efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
+static efi_status_t efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
 			unsigned long rel_size, void *efi_reloc)
 {
 	const IMAGE_BASE_RELOCATION *end;
@@ -63,11 +63,13 @@ static void efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
 			default:
 				printf("Unknown Relocation off %x type %x\n",
 				       offset, type);
+				return EFI_LOAD_ERROR;
 			}
 			relocs++;
 		}
 		rel = (const IMAGE_BASE_RELOCATION *)relocs;
 	}
+	return EFI_SUCCESS;
 }
 
 void __weak invalidate_icache_all(void)
@@ -171,7 +173,11 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info)
 	}
 
 	/* Run through relocations */
-	efi_loader_relocate(rel, rel_size, efi_reloc);
+	if (EFI_SUCCESS != efi_loader_relocate(rel, rel_size, efi_reloc)) {
+		efi_free_pages((uintptr_t) efi_reloc,
+			       (virt_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT);
+		return NULL;
+	}
 
 	/* Flush cache */
 	flush_cache((ulong)efi_reloc,
-- 
2.11.0



More information about the U-Boot mailing list