Skip to contentSkip to conversation

efi_loader: Fix relocations above 64kb image size

PATCH In review Alexander Graf 2 participants 2 messages Aug 18, 2016 – Aug 21, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_loader: Fix relocations above 64kb image size

We were truncating the image offset within the target image to 16 bits which again meant that we were potentially overwriting random memory in the lower 16 bits of the image.

This patch casts the offset to a more reasonable 32bits.

With this applied, I can successfully see Shell.efi assert because it can't find a protocol it expects to be available.

---
 lib/efi_loader/efi_image_loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_image_loader.c +1 -1
index 574b204..5165377 100644
@@ -37,7 +37,7 @@ static void efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
 		const uint16_t *relocs = (const uint16_t *)(rel + 1);
 		i = (rel->SizeOfBlock - sizeof(*rel)) / sizeof(uint16_t);
 		while (i--) {
-			uint16_t offset = (*relocs & 0xfff) +
+			uint32_t offset = (uint32_t)(*relocs & 0xfff) +
 					  rel->VirtualAddress;
 			int type = *relocs >> EFI_PAGE_SHIFT;
 			unsigned long delta = (unsigned long)efi_reloc;
Signature · 1 line
2.6.6
#1 lore raw
Quoted 10 lines · Alexander Graf

We were truncating the image offset within the target image to 16 bits which again meant that we were potentially overwriting random memory in the lower 16 bits of the image.

This patch casts the offset to a more reasonable 32bits.

With this applied, I can successfully see Shell.efi assert because it can't find a protocol it expects to be available.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160821/595f3a4a/attachment.sig>