summaryrefslogtreecommitdiff
path: root/src/ukify
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-12-21 15:18:13 +0100
committerDaan De Meyer <daan.j.demeyer@gmail.com>2022-12-22 12:21:11 +0100
commit3fc1ae89e756d1624f5135aec5510a939ed01317 (patch)
treebde4c10fcf02113c30443dabb01a4e9de61f7e97 /src/ukify
parent789a642738d28cf2a8ad3f65df9c0c136e83af09 (diff)
downloadsystemd-3fc1ae89e756d1624f5135aec5510a939ed01317.tar.gz
ukify: Validate that there are no overlapping sections
Let's make sure that after calling objcopy we have no overlapping sections in the UKI
Diffstat (limited to 'src/ukify')
-rwxr-xr-xsrc/ukify/ukify.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py
index 63e7202d3d..8f8537b30e 100755
--- a/src/ukify/ukify.py
+++ b/src/ukify/ukify.py
@@ -424,6 +424,18 @@ def join_initrds(initrds):
assert False
+def pe_validate(filename):
+ import pefile
+
+ pe = pefile.PE(filename)
+
+ sections = sorted(pe.sections, key=lambda s: (s.VirtualAddress, s.Misc_VirtualSize))
+
+ for l, r in itertools.pairwise(sections):
+ if l.VirtualAddress + l.Misc_VirtualSize > r.VirtualAddress + r.Misc_VirtualSize:
+ raise ValueError(f'Section "{l.Name.decode()}" ({l.VirtualAddress}, {l.Misc_VirtualSize}) overlaps with section "{r.Name.decode()}" ({r.VirtualAddress}, {r.Misc_VirtualSize})')
+
+
def make_uki(opts):
# kernel payload signing
@@ -540,6 +552,8 @@ def make_uki(opts):
print('+', shell_join(cmd))
subprocess.check_call(cmd)
+ pe_validate(output)
+
# UKI signing
if opts.sb_key: