From: Jan Janssen Date: Thu, 28 Sep 2023 14:22:13 +0000 (+0200) Subject: elf2efi: Check ELF image base if possible X-Git-Tag: v255-rc1~379^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5713c50d84296aa3d986f31fed04f970f93965d9;p=thirdparty%2Fsystemd.git elf2efi: Check ELF image base if possible --- diff --git a/tools/elf2efi.py b/tools/elf2efi.py index f1fbf1e630f..8dbf881a0c5 100755 --- a/tools/elf2efi.py +++ b/tools/elf2efi.py @@ -348,7 +348,6 @@ def apply_elf_relative_relocation( addend = target.data[addend_offset : addend_offset + addend_size] addend = int.from_bytes(addend, byteorder="little") - # This currently assumes that the ELF file has an image base of 0. value = (image_base + addend).to_bytes(addend_size, byteorder="little") target.data[addend_offset : addend_offset + addend_size] = value @@ -417,6 +416,13 @@ def convert_elf_relocations( if not flags_tag["d_val"] & ENUM_DT_FLAGS_1["DF_1_PIE"]: raise RuntimeError("ELF file is not a PIE.") + # This checks that the ELF image base is 0. + symtab = elf.get_section_by_name(".symtab") + if symtab: + exe_start = symtab.get_symbol_by_name("__executable_start") + if exe_start and exe_start[0]["st_value"] != 0: + raise RuntimeError("Unexpected ELF image base.") + opt.SizeOfHeaders = align_to( PE_OFFSET + len(PE_MAGIC)