Re: [PATCH v2 02/16] x86/compressed: efi-mixed: move 32-bit entrypoint code into .text section

From: Ard Biesheuvel
Date: Thu Oct 06 2022 - 06:56:30 EST


On Thu, 6 Oct 2022 at 12:42, Borislav Petkov <bp@xxxxxxxxx> wrote:
>
> On Wed, Sep 21, 2022 at 04:54:08PM +0200, Ard Biesheuvel wrote:
> > Move the code that stores the arguments passed to the EFI entrypoint
> > into the .text section, so that it can be moved into a separate
> > compilation unit in a subsequent patch.
> >
> > Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
> > ---
> > arch/x86/boot/compressed/head_64.S | 34 ++++++++++++--------
> > 1 file changed, 20 insertions(+), 14 deletions(-)
> >
> > diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
> > index d33f060900d2..1ba2fc2357e6 100644
> > --- a/arch/x86/boot/compressed/head_64.S
> > +++ b/arch/x86/boot/compressed/head_64.S
> > @@ -303,24 +303,28 @@ SYM_FUNC_START(efi32_stub_entry)
> > popl %ecx
> > popl %edx
> > popl %esi
> > + jmp efi32_entry
> > +SYM_FUNC_END(efi32_stub_entry)
> >
> > + .text
> > +SYM_FUNC_START_LOCAL(efi32_entry)
> > call 1f
> > -1: pop %ebp
> > - subl $ rva(1b), %ebp
> > -
> > - movl %esi, rva(efi32_boot_args+8)(%ebp)
> > -SYM_INNER_LABEL(efi32_pe_stub_entry, SYM_L_LOCAL)
> > - movl %ecx, rva(efi32_boot_args)(%ebp)
> > - movl %edx, rva(efi32_boot_args+4)(%ebp)
> > - movb $0, rva(efi_is64)(%ebp)
> > +1: pop %ebx
>
> I'm guessing according to the EFI mixed mode calling convention, %ebx is
> not a live register which gets overwritten here...?
>
> Looking at efi32_pe_entry() from where this is called, %ebx looks live.
>
> What am I missing?
>

efi32_pe_entry() preserves and restores the caller's value of %ebx,
because from there, we might actually return control to the firmware.
The value it keeps in %ebx itself is not live when it jumps to
efi32_entry - it stores its value into image_offset, which is reloaded
from memory at a later point.

efi32_stub_entry() is the 'EFI handover protocol' entry point, which
cannot return to the firmware (and we discard the return address
already) so %ebx can be clobbered.