mirror of
https://github.com/systemd/systemd.git
synced 2025-08-05 16:22:27 +03:00
elf2efi: Add GNU_RELRO support
This commit is contained in:
@ -258,6 +258,13 @@ def iter_copy_sections(elf: ELFFile) -> typing.Iterator[PeSection]:
|
||||
# manually, so that we can easily strip unwanted sections. We try to only discard things we know
|
||||
# about so that there are no surprises.
|
||||
|
||||
relro = None
|
||||
for elf_seg in elf.iter_segments():
|
||||
if elf_seg["p_type"] == "PT_LOAD" and elf_seg["p_align"] != SECTION_ALIGNMENT:
|
||||
raise RuntimeError("ELF segments are not properly aligned.")
|
||||
elif elf_seg["p_type"] == "PT_GNU_RELRO":
|
||||
relro = elf_seg
|
||||
|
||||
for elf_s in elf.iter_sections():
|
||||
if (
|
||||
elf_s["sh_flags"] & SH_FLAGS.SHF_ALLOC == 0
|
||||
@ -275,6 +282,10 @@ def iter_copy_sections(elf: ELFFile) -> typing.Iterator[PeSection]:
|
||||
else:
|
||||
rwx = PE_CHARACTERISTICS_R
|
||||
|
||||
# PE images are always relro.
|
||||
if relro and relro.section_in_segment(elf_s):
|
||||
rwx = PE_CHARACTERISTICS_R
|
||||
|
||||
if pe_s and pe_s.Characteristics != rwx:
|
||||
yield pe_s
|
||||
pe_s = None
|
||||
|
Reference in New Issue
Block a user