mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 18:23:32 +08:00
elf2efi: Check ELF image base if possible
This commit is contained in:
parent
142f0c61a3
commit
5713c50d84
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user