Skip to content

Commit d713104

Browse files
DaanDeMeyerbluca
authored andcommitted
ukify: Only run systemd-measure after adding all sections
We were running systemd-measure before adding the sbat section, let's fix that. Also make sure we only pass --linux to systemd-measure once instead of twice.
1 parent 46f0a4e commit d713104

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/ukify/ukify.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -792,23 +792,29 @@ def make_uki(opts):
792792
for section in opts.sections:
793793
uki.add_section(section)
794794

795-
# PCR measurement and signing
796-
797-
call_systemd_measure(uki, linux, opts=opts)
798-
799-
# UKI or addon creation - addons don't use the stub so we add SBAT manually
800-
801795
if linux is not None:
802796
# Merge the .sbat sections from stub, kernel and parameter, so that revocation can be done on either.
803797
uki.add_section(Section.create('.sbat', merge_sbat([opts.stub, linux], opts.sbat), measure=True))
804-
uki.add_section(Section.create('.linux', linux, measure=True))
805798
else:
799+
# Addons don't use the stub so we add SBAT manually
806800
if not opts.sbat:
807801
opts.sbat = ["""sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md
808802
uki,1,UKI,uki,1,https://www.freedesktop.org/software/systemd/man/systemd-stub.html
809803
"""]
810804
uki.add_section(Section.create('.sbat', merge_sbat([], opts.sbat), measure=False))
811805

806+
# PCR measurement and signing
807+
808+
# We pass in the contents for .linux separately because we need them to do the measurement but can't add
809+
# the section yet because we want .linux to be the last section. Make sure any other sections are added
810+
# before this function is called.
811+
call_systemd_measure(uki, linux, opts=opts)
812+
813+
# UKI creation
814+
815+
if linux is not None:
816+
uki.add_section(Section.create('.linux', linux, measure=True))
817+
812818
if sign_args_present:
813819
unsigned = tempfile.NamedTemporaryFile(prefix='uki')
814820
unsigned_output = unsigned.name

0 commit comments

Comments
 (0)