efi/arm: Clean EFI stub exit code from cache instead of avoiding it

The following commit:

  c7225494b ("efi/arm: Work around missing cache maintenance in decompressor handover")

modified the EFI handover code written in assembler to work around the
missing cache maintenance of the piece of code that is executed after the
MMU and caches are turned off.

Due to the fact that this sequence incorporates a subroutine call, cleaning
that code from the cache is not a matter of simply passing the start and end of
the currently running subroutine into cache_clean_flush(), which is why
instead, the code jumps across into the cleaned copy of the image.

However, this assumes that this copy is executable, and this means we
expect EFI_LOADER_DATA regions to be executable as well, which is not
a reasonable assumption to make, even if this is true for most UEFI
implementations today.

So change this back, and add a cache_clean_flush() call to cover the
remaining code in the subroutine, and any code it may execute in the
context of cache_off().

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: linux-efi@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: David Hildenbrand <david@redhat.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://lore.kernel.org/r/20200228121408.9075-5-ardb@kernel.org
This commit is contained in:
Ard Biesheuvel 2020-02-28 13:14:06 +01:00 committed by Ingo Molnar
parent 98649365e5
commit 0698fac4ac

View File

@ -1452,13 +1452,11 @@ ENTRY(efi_enter_kernel)
@ The PE/COFF loader might not have cleaned the code we are @ The PE/COFF loader might not have cleaned the code we are
@ running beyond the PoU, and so calling cache_off below from @ running beyond the PoU, and so calling cache_off below from
@ inside the PE/COFF loader allocated region is unsafe. Let's @ inside the PE/COFF loader allocated region is unsafe unless
@ assume our own zImage relocation code did a better job, and @ we explicitly clean it to the PoC.
@ jump into its version of this routine before proceeding. adr r0, call_cache_fn @ region of code we will
ldr r1, .Ljmp adr r1, 0f @ run with MMU off
sub r1, r7, r1 bl cache_clean_flush
mov pc, r1 @ no mode switch
0:
bl cache_off bl cache_off
@ Set parameters for booting zImage according to boot protocol @ Set parameters for booting zImage according to boot protocol
@ -1467,10 +1465,10 @@ ENTRY(efi_enter_kernel)
mov r0, #0 mov r0, #0
mov r1, #0xFFFFFFFF mov r1, #0xFFFFFFFF
mov r2, r4 mov r2, r4
b __efi_start add r7, r7, #(__efi_start - start)
mov pc, r7 @ no mode switch
ENDPROC(efi_enter_kernel) ENDPROC(efi_enter_kernel)
.align 2 0:
.Ljmp: .long start - 0b
#endif #endif
.align .align