[PATCH] efi: let the generic relocate code handle all relocations
Sascha Hauer
s.hauer at pengutronix.de
Wed Apr 6 22:30:57 PDT 2016
On Tue, Apr 05, 2016 at 09:33:25AM +0200, Michael Olbrich wrote:
> Part of the barebox code and variables are put in separate sections
> (.barebox* and .initcall*). When this code is compiled as position
> independent code then the compiler creates corresponding .rela.barebox* and
> .rela.initcall* sections with the relocation table entries.
> These sections don't match the .rela.data* wildcard in the linker script.
> As a result, they are not added to the .rela section during linking but are
> added individually after it instead. And when the EFI binary is created
> from the ELF binary, these sections are not copied.
> This has two side effects:
>
> 1. The corresponding relocations are not handled by the generic relocation
> code. 'fixup_tables()' was added to do these relocations manually.
>
> 2. In the DYNAMIC section, the RELASZ entry contains the total size of
> relocations in bytes. This includes the .rela.barebox* and .rela.initcall*
> sections. This value is not modified when the EFI binary is created. So the
> value is too large.
> The generic relocation code in _relocate() used this value when iterating
> over all relocation entries. With the wrong RELASZ value it iterates beyond
> the end of the .rela section into uninitialized memory. After power-on this
> memory is zero and the relocation code interprets this as 'nothing to do',
> so there is no visible effect. After a soft reset, random data in that area
> may produce a seemingly valid relocation entry, a random address is
> modified and barebox crashes.
>
> This patch adds the .rela.barebox* and .rela.initcall* sections to the
> normal .rela section. The RELASZ now contains the correct size and the
> generic relocation code works correctly. 'fixup_tables()' must be removed
> at the same time to avoid relocating these entries twice.
>
> Signed-off-by: Michael Olbrich <m.olbrich at pengutronix.de>
> ---
> arch/efi/efi/efi.c | 42 ---------------------------------------
> arch/efi/lib/elf_x86_64_efi.lds.S | 2 ++
> 2 files changed, 2 insertions(+), 42 deletions(-)
Applied, thanks. And thanks for finally fixing this issue :)
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list