x86/efi: don't write relocations in efi_arch_relocate_image() first pass
authorDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 25 Aug 2017 12:07:40 +0000 (14:07 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 25 Aug 2017 12:07:40 +0000 (14:07 +0200)
The function is invoked with delta=0 before ExitBootServices() is called,
as a dummy run purely to validate that all the relocations can be handled.
This allows us to exit gracefully with an error message.

However, we have relocations in read-only sections such as .rodata and
.init.te(xt). Recent versions of UEFI will actually make those sections
read-only, which will cause a fault. This functionaity was added in
EDK2 commit d0e92aad4 ("MdeModulePkg/DxeCore: Add UEFI image protection.")

It's OK to actually make the changes in the later pass because UEFI will
tear down the protection when ExitBootServices() is called, because it
knows we're going to need to do this kind of thing.

Reported-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
xen/arch/x86/efi/efi-boot.h

index bedac5cf17ebac73c3d5fa85fae244b1ac954980..8d295ff9afe4c7a809910e6037b69fe7c52d1d87 100644 (file)
@@ -87,7 +87,8 @@ static void __init efi_arch_relocate_image(unsigned long delta)
             case PE_BASE_RELOC_DIR64:
                 if ( in_page_tables(addr) )
                     blexit(L"Unexpected relocation type");
-                *(u64 *)addr += delta;
+                if ( delta )
+                    *(u64 *)addr += delta;
                 break;
             default:
                 blexit(L"Unsupported relocation type");