|
|
d1e1c8 |
From 3d04aef8d80293d701f7efee6b5300f9f528ddfc Mon Sep 17 00:00:00 2001
|
|
|
d1e1c8 |
From: Maran Wilson <maran.wilson@oracle.com>
|
|
|
d1e1c8 |
Date: Tue, 7 Aug 2018 15:32:29 -0700
|
|
|
d1e1c8 |
Subject: [PATCH 15/62] Fix for "Section 0 has negative size" error when
|
|
|
d1e1c8 |
loading fbaa64.efi
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
The current code is incorrectly failing to load the fbaa64.efi image found
|
|
|
d1e1c8 |
in Arm servers even though the UEFI shell code is able to properly load
|
|
|
d1e1c8 |
and execute the same image.
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
The problem is due to the presence of a section header that has zero size
|
|
|
d1e1c8 |
and address and marked "discardable" in the fbaa64.efi image.
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
Although there is already a check further down in the code to look for
|
|
|
d1e1c8 |
the discardable bit and skip further verification checks if set, we never
|
|
|
d1e1c8 |
get to that point due to the "end < base" check at the start of the loop.
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
Here is a dump of the fbaa64.efi image as compiled on an Arm machine
|
|
|
d1e1c8 |
from the latest code in this repo:
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
% # First I used hexedit to change header byte from 'AA' to '86'
|
|
|
d1e1c8 |
% # so that objdump was able to correctly parse the file:
|
|
|
d1e1c8 |
% objdump -x -m aarch64 fbaa64.efi
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
fbaa64.efi: file format pei-x86-64
|
|
|
d1e1c8 |
fbaa64.efi
|
|
|
d1e1c8 |
architecture: i386:x86-64, flags 0x00000103:
|
|
|
d1e1c8 |
HAS_RELOC, EXEC_P, D_PAGED
|
|
|
d1e1c8 |
start address 0x0000000000000148
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
Characteristics 0x20e
|
|
|
d1e1c8 |
executable
|
|
|
d1e1c8 |
line numbers stripped
|
|
|
d1e1c8 |
symbols stripped
|
|
|
d1e1c8 |
debugging information removed
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
Time/Date Wed Dec 31 16:00:00 1969
|
|
|
d1e1c8 |
Magic 020b (PE32+)
|
|
|
d1e1c8 |
MajorLinkerVersion 2
|
|
|
d1e1c8 |
MinorLinkerVersion 20
|
|
|
d1e1c8 |
SizeOfCode 000b15d0
|
|
|
d1e1c8 |
SizeOfInitializedData 00000000
|
|
|
d1e1c8 |
SizeOfUninitializedData 00000000
|
|
|
d1e1c8 |
AddressOfEntryPoint 0000000000000148
|
|
|
d1e1c8 |
BaseOfCode 0000000000000148
|
|
|
d1e1c8 |
ImageBase 0000000000000000
|
|
|
d1e1c8 |
SectionAlignment 0000000000000020
|
|
|
d1e1c8 |
FileAlignment 0000000000000008
|
|
|
d1e1c8 |
MajorOSystemVersion 0
|
|
|
d1e1c8 |
MinorOSystemVersion 0
|
|
|
d1e1c8 |
MajorImageVersion 0
|
|
|
d1e1c8 |
MinorImageVersion 0
|
|
|
d1e1c8 |
MajorSubsystemVersion 0
|
|
|
d1e1c8 |
MinorSubsystemVersion 0
|
|
|
d1e1c8 |
Win32Version 00000000
|
|
|
d1e1c8 |
SizeOfImage 000b1718
|
|
|
d1e1c8 |
SizeOfHeaders 00000148
|
|
|
d1e1c8 |
CheckSum 00000000
|
|
|
d1e1c8 |
Subsystem 0000000a (EFI application)
|
|
|
d1e1c8 |
DllCharacteristics 00000000
|
|
|
d1e1c8 |
SizeOfStackReserve 0000000000000000
|
|
|
d1e1c8 |
SizeOfStackCommit 0000000000000000
|
|
|
d1e1c8 |
SizeOfHeapReserve 0000000000000000
|
|
|
d1e1c8 |
SizeOfHeapCommit 0000000000000000
|
|
|
d1e1c8 |
LoaderFlags 00000000
|
|
|
d1e1c8 |
NumberOfRvaAndSizes 00000006
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
The Data Directory
|
|
|
d1e1c8 |
Entry 0 0000000000000000 00000000 Export Directory [.edata (or where ever we found it)]
|
|
|
d1e1c8 |
Entry 1 0000000000000000 00000000 Import Directory [parts of .idata]
|
|
|
d1e1c8 |
Entry 2 0000000000000000 00000000 Resource Directory [.rsrc]
|
|
|
d1e1c8 |
Entry 3 0000000000000000 00000000 Exception Directory [.pdata]
|
|
|
d1e1c8 |
Entry 4 0000000000000000 00000000 Security Directory
|
|
|
d1e1c8 |
Entry 5 0000000000000000 00000000 Base Relocation Directory [.reloc]
|
|
|
d1e1c8 |
Entry 6 0000000000000000 00000000 Debug Directory
|
|
|
d1e1c8 |
Entry 7 0000000000000000 00000000 Description Directory
|
|
|
d1e1c8 |
Entry 8 0000000000000000 00000000 Special Directory
|
|
|
d1e1c8 |
Entry 9 0000000000000000 00000000 Thread Storage Directory [.tls]
|
|
|
d1e1c8 |
Entry a 0000000000000000 00000000 Load Configuration Directory
|
|
|
d1e1c8 |
Entry b 0000000000000000 00000000 Bound Import Directory
|
|
|
d1e1c8 |
Entry c 0000000000000000 00000000 Import Address Table Directory
|
|
|
d1e1c8 |
Entry d 0000000000000000 00000000 Delay Import Directory
|
|
|
d1e1c8 |
Entry e 0000000000000000 00000000 CLR Runtime Header
|
|
|
d1e1c8 |
Entry f 0000000000000000 00000000 Reserved
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
Sections:
|
|
|
d1e1c8 |
Idx Name Size VMA LMA File off Algn
|
|
|
d1e1c8 |
0 .reloc 00000000 0000000000000000 0000000000000000 00000000 2**0
|
|
|
d1e1c8 |
ALLOC, LOAD, READONLY, DATA
|
|
|
d1e1c8 |
1 .text 000b15d0 0000000000000148 0000000000000148 00000148 2**4
|
|
|
d1e1c8 |
CONTENTS, ALLOC, LOAD, CODE
|
|
|
d1e1c8 |
SYMBOL TABLE:
|
|
|
d1e1c8 |
no symbols
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
Signed-off-by: Maran Wilson <maran.wilson@oracle.com>
|
|
|
d1e1c8 |
Reviewed-by: Aaron Young <aaron.young@oracle.com>
|
|
|
d1e1c8 |
Reviewed-by: Jack Schwartz <jack.schwartz@oracle.com>
|
|
|
d1e1c8 |
Upstream-commit-id: 6df7a8f5609
|
|
|
d1e1c8 |
---
|
|
|
d1e1c8 |
shim.c | 5 +++++
|
|
|
d1e1c8 |
1 file changed, 5 insertions(+)
|
|
|
d1e1c8 |
|
|
|
d1e1c8 |
diff --git a/shim.c b/shim.c
|
|
|
d1e1c8 |
index ae03da7eddf..d980cadacfc 100644
|
|
|
d1e1c8 |
--- a/shim.c
|
|
|
d1e1c8 |
+++ b/shim.c
|
|
|
d1e1c8 |
@@ -1347,6 +1347,11 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize,
|
|
|
d1e1c8 |
*/
|
|
|
d1e1c8 |
Section = context.FirstSection;
|
|
|
d1e1c8 |
for (i = 0; i < context.NumberOfSections; i++, Section++) {
|
|
|
d1e1c8 |
+ /* Don't try to copy discardable sections with zero size */
|
|
|
d1e1c8 |
+ if ((Section->Characteristics & EFI_IMAGE_SCN_MEM_DISCARDABLE) &&
|
|
|
d1e1c8 |
+ !Section->Misc.VirtualSize)
|
|
|
d1e1c8 |
+ continue;
|
|
|
d1e1c8 |
+
|
|
|
d1e1c8 |
base = ImageAddress (buffer, context.ImageSize,
|
|
|
d1e1c8 |
Section->VirtualAddress);
|
|
|
d1e1c8 |
end = ImageAddress (buffer, context.ImageSize,
|
|
|
d1e1c8 |
--
|
|
|
d1e1c8 |
2.26.2
|
|
|
d1e1c8 |
|