Closed anssih closed 3 years ago
We could of course read the active banks from the EFI stub we provide (i.e. from EFI code before transitioning to the Linux kernel), and store it in some efi var. But that would only work if people actually use our efi stub, not sure all distros do that.
I prepped a patch for this in #20716. Would be great if you could give this a whirl.
(Should suffice building the git tree, then invoking systemd-cryptenroll/systemd-cryptsetup from the build tree, for testing. No need to install)
Seems to work on the affected system:
# truncate --size=50M testfile2
# touch key
# cryptsetup --batch-mode luksFormat testfile2 key
# PASSWORD= /opt/systemd/bin/systemd-cryptenroll --tpm2-device=auto testfile2
TPM2 device supports both SHA1 and SHA256 PCR banks, but only SHA1 PCRs are valid, falling back to SHA1 bank. This reduces the security level substantially.
New TPM2 token enrolled as key slot 1.
# cryptsetup luksDump testfile2 | grep tpm2-bank
tpm2-bank: sha1
systemd version the issue has been seen with
3da57008e743 (master from a few weeks ago - no TPM2 changes to master since)
20134 is a different issue and the fix for that does not help here
Used distribution
Buildroot 2021.02.3
Linux kernel version used (
uname -a
)5.4.123
CPU architecture issue was seen on
x86_64
Expected behaviour you didn't see
On some systems the TPM2 supports both SHA-1 and SHA-256 banks, but only the SHA-1 bank is active in EFI, i.e. the EFI firmware is only extending hashes in the SHA1 bank, and the SHA-256 bank is zero (banks 17-22 are FF, others 00, per spec). TPM2 event log shows SHA-1 extensions but no SHA-256 extensions.
The TCG EFI Protocol Specification has a notion of "Active PCR banks". The system I'm testing on responds to
GetCapability
with a structure withHashAlgorithmBitmap
set to 0x1 (only SHA-1 supported). So only SHA-1 bank is supported and therefore active. The capability structure has brokenness, though, see full output further below.The SHA-256 bank can still be extended in Linux via e.g.
tpm2_pcrevent
, as expected - it is just not active in EFI.In this specific case, the expected behavior would probably be for
systemd-cryptenroll
to use SHA-1 bank which is active in EFI, or produce a warning or error. It could probably try to detect empty banks, or somehow use the active banks information from EFI TCG protocol (which would have to be relayed to it somehow as it is a Boot Service). It could also look at event log in /sys/kernel/security/tpm0/binary_bios_measurements via tpm2-tss on whether it has SHA-256 extensions logged, but I do have another weird system here where the log does not have SHA-256 extensions even though SHA-256 bank seems active.Or there could just be a simple warning message if the PCR bank is zero/one-filled.
Alternatively, it should be mentioned in
systemd-cryptenroll
man page that it does not verify that the PCR bank is actually used by the firmware, and just consider this as firmware weirdness or misconfiguration. (My actual use case does not actually require fixing this issue either, I just noticed it during testing.)Unexpected behaviour you saw
systemd-cryptenroll
seals the key against an empty SHA-256 bank, offering no security at all.The encrypted volume can be opened regardless of system state.
(I checked with systemd-security@ that this is OK to publish)
Steps to reproduce the problem
On a system with an affected firmware and TPM2:
Additional program output to the terminal or log subsystem illustrating the issue
GetCapability()
returns the followingEFI_TCG2_BOOT_SERVICE_CAPABILITY
:The PCR bank fields being left alone is clearly broken behavior from firmware.
GetActivePcrBanks
works in the same way, it does not return error but does not touch the output bitmap.If the active-pcr-banks fields or calls were to be used somehow, the input should probably be zeroed first (which e.g. systemd
src/boot/efi/measure.c
does not currently do).Enrollment:
Banks: