arrfab / rpms / shim

Forked from rpms/shim 5 years ago
Clone

Blame SOURCES/0052-Handle-empty-.reloc-section-in-PE-COFF-loader.patch

4210fa
From 94c9a77f6504170a6bd38b0aa29039208987650e Mon Sep 17 00:00:00 2001
4210fa
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
4210fa
Date: Wed, 13 Aug 2014 13:35:38 +0200
4210fa
Subject: [PATCH 52/74] Handle empty .reloc section in PE/COFF loader
4210fa
4210fa
On archs where no EFI aware objcopy is available, the generated PE/COFF
4210fa
header contains a .reloc section which is completely empty. Handle this by
4210fa
- returning early from relocate_coff() with EFI_SUCCESS,
4210fa
- ignoring discardable sections in the section loader.
4210fa
4210fa
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
4210fa
---
4210fa
 shim.c | 11 ++++++++---
4210fa
 1 file changed, 8 insertions(+), 3 deletions(-)
4210fa
4210fa
diff --git a/shim.c b/shim.c
4210fa
index ea8eba8..1329212 100644
4210fa
--- a/shim.c
4210fa
+++ b/shim.c
4210fa
@@ -145,6 +145,9 @@ static EFI_STATUS relocate_coff (PE_COFF_LOADER_IMAGE_CONTEXT *context,
4210fa
 		return EFI_UNSUPPORTED;
4210fa
 	}
4210fa
 
4210fa
+	if (!context->RelocDir->Size)
4210fa
+		return EFI_SUCCESS;
4210fa
+
4210fa
 	RelocBase = ImageAddress(data, size, context->RelocDir->VirtualAddress);
4210fa
 	RelocBaseEnd = ImageAddress(data, size, context->RelocDir->VirtualAddress + context->RelocDir->Size - 1);
4210fa
 
4210fa
@@ -996,7 +999,11 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize,
4210fa
 	 * Copy the executable's sections to their desired offsets
4210fa
 	 */
4210fa
 	Section = context.FirstSection;
4210fa
-	for (i = 0; i < context.NumberOfSections; i++) {
4210fa
+	for (i = 0; i < context.NumberOfSections; i++, Section++) {
4210fa
+		if (Section->Characteristics & 0x02000000)
4210fa
+			/* section has EFI_IMAGE_SCN_MEM_DISCARDABLE attr set */
4210fa
+			continue;
4210fa
+
4210fa
 		size = Section->Misc.VirtualSize;
4210fa
 
4210fa
 		if (size > Section->SizeOfRawData)
4210fa
@@ -1021,8 +1028,6 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize,
4210fa
 
4210fa
 		if (size < Section->Misc.VirtualSize)
4210fa
 			ZeroMem (base + size, Section->Misc.VirtualSize - size);
4210fa
-
4210fa
-		Section += 1;
4210fa
 	}
4210fa
 
4210fa
 	/*
4210fa
-- 
4210fa
1.9.3
4210fa