Skip to content

Commit 1fa004a

Browse files
authored
systemd: fix pcrlock failure on Hyper-V VMs with vTPM (#16309)
1 parent 0ffb633 commit 1fa004a

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

SPECS-SIGNED/systemd-boot-signed/systemd-boot-signed.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Version: 255
2020
# determine the build information from local checkout
2121
Version: %(tools/meson-vcs-tag.sh . error | sed -r 's/-([0-9])/.^\1/; s/-g/_g/')
2222
%endif
23-
Release: 26%{?dist}
23+
Release: 27%{?dist}
2424
License: LGPL-2.1-or-later AND MIT AND GPL-2.0-or-later
2525
Vendor: Microsoft Corporation
2626
Distribution: Azure Linux
@@ -98,6 +98,9 @@ popd
9898
/boot/efi/EFI/BOOT/%{grubefiname}
9999

100100
%changelog
101+
* Thu Mar 26 2026 Lanze Liu <lanzeliu@microsoft.com> - 255-27
102+
- Bump release to match systemd spec
103+
101104
* Tue Mar 03 2026 Dan Streetman <ddstreet@ieee.org> - 255-26
102105
- Bump release to match systemd spec
103106

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
From e90a255e55e3af0effac927ccaa10c2662501e1a Mon Sep 17 00:00:00 2001
2+
From: Lennart Poettering <lennart@poettering.net>
3+
Date: Wed, 21 Feb 2024 14:43:42 +0100
4+
Subject: [PATCH] pcrlock: handle measurement logs where hash algs in header
5+
are announced in different order than in records
6+
7+
Apparently on HyperV the measurement logs announce the hash algs in a
8+
different order in the header than the records have them. Let's handle
9+
this gracefully
10+
---
11+
src/pcrlock/pcrlock.c | 21 ++++++++++++++-------
12+
1 file changed, 14 insertions(+), 7 deletions(-)
13+
14+
diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c
15+
index e70c44c6..1fb9d692 100644
16+
--- a/src/pcrlock/pcrlock.c
17+
+++ b/src/pcrlock/pcrlock.c
18+
@@ -936,23 +936,30 @@ static int event_log_load_firmware(EventLog *el) {
19+
assert(event->digests.count == n_algorithms);
20+
21+
for (size_t i = 0; i < n_algorithms; i++, ha = ha_next) {
22+
- ha_next = (const uint8_t*) ha + offsetof(TPMT_HA, digest) + algorithms[i].digestSize;
23+
-
24+
/* The TPMT_HA is not aligned in the record, hence read the hashAlg field via an unaligned read */
25+
assert_cc(__builtin_types_compatible_p(uint16_t, typeof(TPMI_ALG_HASH)));
26+
uint16_t hash_alg = unaligned_read_ne16((const uint8_t*) ha + offsetof(TPMT_HA, hashAlg));
27+
28+
- if (hash_alg != algorithms[i].algorithmId)
29+
- return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Hash algorithms in event log record don't match log.");
30+
+ /* On some systems (some HyperV?) the order of hash algorithms announced in the
31+
+ * header does not match the order in the records. Let's hence search for the right
32+
+ * mapping */
33+
+ size_t j;
34+
+ for (j = 0; j < n_algorithms; j++)
35+
+ if (hash_alg == algorithms[j].algorithmId)
36+
+ break;
37+
+ if (j >= n_algorithms)
38+
+ return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Hash algorithms in event log record not among those advertised by log header.");
39+
+
40+
+ ha_next = (const uint8_t*) ha + offsetof(TPMT_HA, digest) + algorithms[j].digestSize;
41+
42+
- if (!tpm2_hash_alg_to_string(algorithms[i].algorithmId))
43+
+ if (!tpm2_hash_alg_to_string(hash_alg))
44+
continue;
45+
46+
r = event_log_record_add_bank(
47+
record,
48+
- algorithms[i].algorithmId,
49+
+ hash_alg,
50+
(const uint8_t*) ha + offsetof(TPMT_HA, digest),
51+
- algorithms[i].digestSize,
52+
+ algorithms[j].digestSize,
53+
/* ret= */ NULL);
54+
if (r < 0)
55+
return log_error_errno(r, "Failed to add bank to event log record: %m");
56+
--
57+
2.45.4
58+

SPECS/systemd/systemd.spec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Version: 255
5050
# determine the build information from local checkout
5151
Version: %(tools/meson-vcs-tag.sh . error | sed -r 's/-([0-9])/.^\1/; s/-g/_g/')
5252
%endif
53-
Release: 26%{?dist}
53+
Release: 27%{?dist}
5454

5555
# FIXME - hardcode to 'stable' for now as that's what we have in our blobstore
5656
%global stable 1
@@ -149,6 +149,7 @@ Patch0905: ipc-call-0001-path-util-add-flavour-of-path_startswith-that-leav
149149
Patch0906: ipc-call-0003-core-cgroup-avoid-one-unnecessary-strjoina.patch
150150
Patch0907: ipc-call-0002-path-util-invert-PATH_STARTSWITH_ACCEPT_DOT_DOT-flag.patch
151151
Patch0908: ipc-call-0004-core-validate-input-cgroup-path-more-prudently.patch
152+
Patch0909: fix-pcrlock-hyperv-hash-algorithm-ordering.patch
152153

153154
%ifarch %{ix86} x86_64 aarch64
154155
%global want_bootloader 1
@@ -1234,6 +1235,10 @@ rm -f %{name}.lang
12341235
# %autochangelog. So we need to continue manually maintaining the
12351236
# changelog here.
12361237
%changelog
1238+
* Thu Mar 26 2026 Lanze Liu <lanzeliu@microsoft.com> - 255-27
1239+
- Fix pcrlock failure on Hyper-V/Azure VMs with vTPM by backporting upstream
1240+
commit e90a255 from systemd v256 (PR #31429).
1241+
12371242
* Mon Mar 02 2026 Dan Streetman <ddstreet@ieee.org> - 255-26
12381243
- Apply patches for ipc issue.
12391244

0 commit comments

Comments
 (0)