From: Daan De Meyer Date: Wed, 21 Dec 2022 14:18:13 +0000 (+0100) Subject: ukify: Validate that there are no overlapping sections X-Git-Tag: v253-rc1~225^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F25814%2Fhead;p=thirdparty%2Fsystemd.git ukify: Validate that there are no overlapping sections Let's make sure that after calling objcopy we have no overlapping sections in the UKI --- diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index 63e7202d3da..8f8537b30ea 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: