]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ukify: Validate that there are no overlapping sections 25814/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 Dec 2022 14:18:13 +0000 (15:18 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 22 Dec 2022 11:21:11 +0000 (12:21 +0100)
Let's make sure that after calling objcopy we have no overlapping
sections in the UKI

src/ukify/ukify.py

index 63e7202d3dafb854ec16d15c854a62a01f604e70..8f8537b30ea37ecd9d360aa03bc6e5c2e1edd827 100755 (executable)
@@ -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: