diff mbox series

efi_loader: Handle RELA absolute relocations properly

Message ID 20181104212855.77692-1-agraf@suse.de
State Accepted
Commit afdc4fcc8931589f2fab75d8830ab9b43d2725c4
Headers show
Series efi_loader: Handle RELA absolute relocations properly | expand

Commit Message

Alexander Graf Nov. 4, 2018, 9:28 p.m. UTC
With RELA absolute relocations, the relocation target contains our link
offset which we need to remove from the equation again. We did this
properly in the relative relocation path, but not in the absolute one.

So let's do this for the absolute one as well. That way, u-boot can have
a TEXT_OFFSET of != 0 and still relocate itself properly.

This fixes a bug where efi_loader did not work on the RISC-V QEMU port.
With this patch, I can successfully run UEFI applications on the RISC-V
QEMU port.

Reported-by: Auer, Lukas <lukas.auer@aisec.fraunhofer.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
 lib/efi_loader/efi_runtime.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Bin Meng Nov. 5, 2018, 2:02 a.m. UTC | #1
On Mon, Nov 5, 2018 at 5:28 AM Alexander Graf <agraf@suse.de> wrote:
>
> With RELA absolute relocations, the relocation target contains our link
> offset which we need to remove from the equation again. We did this
> properly in the relative relocation path, but not in the absolute one.
>
> So let's do this for the absolute one as well. That way, u-boot can have
> a TEXT_OFFSET of != 0 and still relocate itself properly.
>
> This fixes a bug where efi_loader did not work on the RISC-V QEMU port.
> With this patch, I can successfully run UEFI applications on the RISC-V
> QEMU port.
>
> Reported-by: Auer, Lukas <lukas.auer@aisec.fraunhofer.de>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  lib/efi_loader/efi_runtime.c | 3 +++
>  1 file changed, 3 insertions(+)
>

Tested-by: Bin Meng <bmeng.cn@gmail.com>
Lukas Auer Nov. 5, 2018, 9:40 a.m. UTC | #2
On Sun, 2018-11-04 at 22:28 +0100, Alexander Graf wrote:
> With RELA absolute relocations, the relocation target contains our

> link

> offset which we need to remove from the equation again. We did this

> properly in the relative relocation path, but not in the absolute

> one.

> 

> So let's do this for the absolute one as well. That way, u-boot can

> have

> a TEXT_OFFSET of != 0 and still relocate itself properly.

> 

> This fixes a bug where efi_loader did not work on the RISC-V QEMU

> port.

> With this patch, I can successfully run UEFI applications on the

> RISC-V

> QEMU port.

> 

> Reported-by: Auer, Lukas <lukas.auer@aisec.fraunhofer.de>

> Signed-off-by: Alexander Graf <agraf@suse.de>

> ---

>  lib/efi_loader/efi_runtime.c | 3 +++

>  1 file changed, 3 insertions(+)

> 

> 


Tested-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>


Thanks for the patch! That explains why it was working on the Andes
targets.

Lukas
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index abcf03c5a4..ca66d33e58 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -380,6 +380,9 @@  void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
 			ulong symidx = rel->info >> SYM_INDEX;
 			extern struct dyn_sym __dyn_sym_start[];
 			newaddr = __dyn_sym_start[symidx].addr + offset;
+#ifdef IS_RELA
+			newaddr -= CONFIG_SYS_TEXT_BASE;
+#endif
 			break;
 		}
 #endif