u-boot-brain/lib/efi_loader
Ilias Apalodimas 53e54bf50d efi_loader: Avoid emitting efi_var_buf to .GOT
Atish reports that on RISC-V, accessing the EFI variables causes
a kernel panic. An objdump of the file verifies that, since the
global pointer for efi_var_buf ends up in .GOT section which is
not mapped in virtual address space for Linux.

<snip of efi_var_mem_find>

0000000000000084 <efi_var_mem_find>:
  84:   715d                    addi    sp,sp,-80

* objdump -dr
0000000000000086 <.LCFI2>:
  86:   e0a2                    sd  s0,64(sp)
  88:   fc26                    sd  s1,56(sp)
  8a:   e486                    sd  ra,72(sp)
  8c:   f84a                    sd  s2,48(sp)
  8e:   f44e                    sd  s3,40(sp)
  90:   f052                    sd  s4,32(sp)
  92:   ec56                    sd  s5,24(sp)
  94:   00000497            auipc   s1,0x0
            94: R_RISCV_GOT_HI20    efi_var_buf
  98:   0004b483            ld  s1,0(s1) # 94 <.LCFI2+0xe>
            98: R_RISCV_PCREL_LO12_I    .L0
            98: R_RISCV_RELAX   *ABS*

* objdump -t
0000000000000084 g     F .text.efi_runtime  00000000000000b8 efi_var_mem_find

With the patch applied:

* objdump -dr
0000000000000086 <.LCFI2>:
  86:   e0a2                    sd  s0,64(sp)
  88:   fc26                    sd  s1,56(sp)
  8a:   e486                    sd  ra,72(sp)
  8c:   f84a                    sd  s2,48(sp)
  8e:   f44e                    sd  s3,40(sp)
  90:   f052                    sd  s4,32(sp)
  92:   ec56                    sd  s5,24(sp)
  94:   00000497            auipc   s1,0x0
            94: R_RISCV_PCREL_HI20  .LANCHOR0
            94: R_RISCV_RELAX   *ABS*
  98:   00048493            mv  s1,s1
            98: R_RISCV_PCREL_LO12_I    .L0
            98: R_RISCV_RELAX   *ABS*

* objdump -t
0000000000000008 l     O .data.efi_runtime  0000000000000008 efi_var_buf

On arm64 this works, because there's no .GOT entries for this
and everything is converted to relative references.

* objdump -dr (identical pre-post patch, only the new function shows up)
00000000000000b4 <efi_var_mem_find>:
  b4:   aa0003ee    mov x14, x0
  b8:   9000000a    adrp    x10, 0 <efi_var_mem_compare>
            b8: R_AARCH64_ADR_PREL_PG_HI21  .data.efi_runtime
  bc:   91000140    add x0, x10, #0x0
            bc: R_AARCH64_ADD_ABS_LO12_NC   .data.efi_runtime
  c0:   aa0103ed    mov x13, x1
  c4:   79400021    ldrh    w1, [x1]
  c8:   aa0203eb    mov x11, x2
  cc:   f9400400    ldr x0, [x0, #8]
  d0:   b940100c    ldr w12, [x0, #16]
  d4:   8b0c000c    add x12, x0, x12

So let's switch efi_var_buf to static and create a helper function for
anyone that needs to update it.

Fixes: e01aed47d6 ("efi_loader: Enable run-time variable support for tee based variables")
Reported-by: Atish Patra <atishp@atishpatra.org>
Tested-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2021-01-20 08:17:17 +01:00
..
.gitignore efi_loader: git ignore helloworld_efi.S 2020-01-07 18:08:20 +01:00
efi_acpi.c common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
efi_bootmgr.c efi_loader: move load options to new module 2021-01-19 18:56:08 +01:00
efi_boottime.c efi_loader: event queueing 2020-12-31 14:33:32 +01:00
efi_capsule.c efi: capsule: Add support for uefi capsule authentication 2020-12-31 14:41:31 +01:00
efi_console.c efi_loader: typedef efi_string_t text output protocol 2021-01-13 02:38:01 +01:00
efi_device_path_to_text.c efi_loader: device path for SATA devices 2020-05-21 10:00:17 +02:00
efi_device_path_utilities.c SPDX: Convert a few files that were missed before 2018-05-10 20:38:35 -04:00
efi_device_path.c dm: Use access methods for dev/uclass private data 2021-01-05 12:24:40 -07:00
efi_disk.c dm: treewide: Rename 'platdata' variables to just 'plat' 2020-12-13 16:51:08 -07:00
efi_dt_fixup.c efi_loader: make EFI_DT_FIXUP_PROTOCOL configurable 2021-01-20 08:17:17 +01:00
efi_file.c efi_loader: implement non-blocking file services 2021-01-13 02:38:00 +01:00
efi_firmware.c efi_loader: Enable uefi capsule authentication 2020-12-31 14:41:31 +01:00
efi_freestanding.c efi_loader: fix freestanding memmove() 2020-03-22 11:06:23 +01:00
efi_gop.c common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
efi_hii_config.c efi_loader: remove EFI_HII_CONFIG_ROUTING_PROTOCOL 2020-12-10 09:15:32 +01:00
efi_hii.c efi_loader: ListPackageLists() return EFI_NOT_FOUND 2019-06-20 22:26:19 +00:00
efi_image_loader.c efi_loader: carve out efi_check_pe() 2021-01-13 02:38:00 +01:00
efi_load_initrd.c efi_loader: Remove unused headers from efi_load_initrd.c 2020-12-31 14:33:22 +01:00
efi_load_options.c efi_loader: move load options to new module 2021-01-19 18:56:08 +01:00
efi_memory.c efi_loader: remove outdated TODO in efi_memory.c 2021-01-13 02:38:01 +01:00
efi_net.c efi_loader: fix use after free in receive path 2020-10-19 22:59:53 +02:00
efi_rng.c efi_loader: Add missing newline to log_{err,warning} 2020-11-14 05:05:46 +01:00
efi_root_node.c efi_loader: remove EFI_UNICODE_COLLATION_PROTOCOL 2021-01-20 08:17:17 +01:00
efi_runtime.c efi_loader: don't set EFI_RT_SUPPORTED_UPDATE_CAPSULE 2020-12-10 09:15:32 +01:00
efi_setup.c efi_loader: Remove unconditional installation of file2 protocol for initrd 2020-12-31 14:33:22 +01:00
efi_signature.c efi: capsule: Add support for uefi capsule authentication 2020-12-31 14:41:31 +01:00
efi_smbios.c common: Drop log.h from common header 2020-05-18 21:19:18 -04:00
efi_string.c efi_loader: Add size checks to efi_create_indexed_name() 2020-12-31 14:33:23 +01:00
efi_tcg2.c efi_loader: Introduce eventlog support for TCG2_PROTOCOL 2020-12-03 21:22:40 +01:00
efi_unicode_collation.c efi_loader: remove EFI_UNICODE_COLLATION_PROTOCOL 2021-01-20 08:17:17 +01:00
efi_var_common.c efi_loader: add copyright notice 2020-08-08 19:03:24 +02:00
efi_var_file.c efi_loader: Enable run-time variable support for tee based variables 2020-08-01 11:57:41 +02:00
efi_var_mem.c efi_loader: Avoid emitting efi_var_buf to .GOT 2021-01-20 08:17:17 +01:00
efi_var_seed.S efi_loader: pre-seed UEFI variables 2020-07-16 12:37:02 +02:00
efi_variable_tee.c efi_loader: Avoid emitting efi_var_buf to .GOT 2021-01-20 08:17:17 +01:00
efi_variable.c efi_loader: Make the pkcs7 header parsing function an extern 2020-12-31 14:41:31 +01:00
efi_watchdog.c efi_loader: function descriptions efi_watchdog.c 2020-04-16 08:10:02 +02:00
helloworld.c efi_loader: print boot device and file path in helloworld 2021-01-13 02:38:00 +01:00
Kconfig efi_loader: remove EFI_UNICODE_COLLATION_PROTOCOL 2021-01-20 08:17:17 +01:00
Makefile efi_loader: EFI_DEVICE_PATH_UTILITIES_PROTOCOL configurable 2021-01-20 08:17:17 +01:00