Skip to content

Commit a06ead6

Browse files
JonathonHall-Purismtlaurion
authored andcommitted
tpmr: Don't continue blindly if a TPM reset step fails
If a TPM reset step fails, don't blindly continue onto the other steps. Use DO_WITH_DEBUG to trace failures, so they're visible in the log but we still exit due to set -e. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm> Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent c4bb410 commit a06ead6

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

initrd/bin/tpmr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,15 @@ tpm2_reset() {
665665
# output TPM Owner Password to a file to be reused in this boot session until recovery shell/reboot
666666
DEBUG "Caching TPM Owner Password to $SECRET_DIR/tpm_owner_password"
667667
echo -n "$tpm_owner_password" >"$SECRET_DIR/tpm_owner_password"
668-
tpm2 clear -c platform >/dev/null 2>&1 || LOG "Unable to clear TPM on platform hierarchy"
669-
tpm2 changeauth -c owner "$(tpm2_password_hex "$tpm_owner_password")" >/dev/null 2>&1 || LOG "Unable to change owner password"
670-
tpm2 changeauth -c endorsement "$(tpm2_password_hex "$tpm_owner_password")" >/dev/null 2>&1 || LOG "Unable to change endorsement password"
671-
tpm2 createprimary -C owner -g sha256 -G "${CONFIG_PRIMARY_KEY_TYPE:-rsa}" \
672-
-c "$SECRET_DIR/primary.ctx" -P "$(tpm2_password_hex "$tpm_owner_password")" >/dev/null 2>&1 || LOG "Unable to create primary key"
673-
tpm2 evictcontrol -C owner -c "$SECRET_DIR/primary.ctx" "$PRIMARY_HANDLE" \
674-
-P "$(tpm2_password_hex "$tpm_owner_password")" >/dev/null 2>&1 || LOG "Unable to evict primary key"
675-
shred -u "$SECRET_DIR/primary.ctx" >/dev/null 2>&1
676-
tpm2_startsession >/dev/null 2>&1 || LOG "Unable to start session"
668+
DO_WITH_DEBUG tpm2 clear -c platform &>/dev/null
669+
DO_WITH_DEBUG tpm2 changeauth -c owner "$(tpm2_password_hex "$tpm_owner_password")" &>/dev/null
670+
DO_WITH_DEBUG tpm2 changeauth -c endorsement "$(tpm2_password_hex "$tpm_owner_password")" &>/dev/null
671+
DO_WITH_DEBUG tpm2 createprimary -C owner -g sha256 -G "${CONFIG_PRIMARY_KEY_TYPE:-rsa}" \
672+
-c "$SECRET_DIR/primary.ctx" -P "$(tpm2_password_hex "$tpm_owner_password")" &>/dev/null
673+
DO_WITH_DEBUG tpm2 evictcontrol -C owner -c "$SECRET_DIR/primary.ctx" "$PRIMARY_HANDLE" \
674+
-P "$(tpm2_password_hex "$tpm_owner_password")" &>/dev/null
675+
shred -u "$SECRET_DIR/primary.ctx" &>/dev/null
676+
DO_WITH_DEBUG tpm2_startsession &>/dev/null
677677

678678
# Set the dictionary attack parameters. TPM2 defaults vary widely, we
679679
# want consistent behavior on any TPM.
@@ -715,17 +715,17 @@ tpm1_reset() {
715715
DEBUG "Caching TPM Owner Password to $SECRET_DIR/tpm_owner_password"
716716
echo -n "$tpm_owner_password" >"$SECRET_DIR/tpm_owner_password"
717717
# Make sure the TPM is ready to be reset
718-
tpm physicalpresence -s >/dev/null 2>&1 || LOG "Unable to assert physical presence"
719-
tpm physicalenable >/dev/null 2>&1 || LOG "Unable to enable TPM"
720-
tpm physicalsetdeactivated -c >/dev/null 2>&1 || LOG "Unable to deactivate TPM"
721-
tpm forceclear >/dev/null 2>&1 || LOG "Unable to clear TPM"
722-
tpm physicalenable >/dev/null 2>&1 || LOG "Unable to enable TPM"
723-
tpm takeown -pwdo "$tpm_owner_password" >/dev/null 2>&1 || LOG "Unable to take ownership of TPM"
718+
DO_WITH_DEBUG tpm physicalpresence -s &>/dev/null
719+
DO_WITH_DEBUG tpm physicalenable &>/dev/null
720+
DO_WITH_DEBUG tpm physicalsetdeactivated -c &>/dev/null
721+
DO_WITH_DEBUG tpm forceclear &>/dev/null
722+
DO_WITH_DEBUG tpm physicalenable &>/dev/null
723+
DO_WITH_DEBUG tpm takeown -pwdo "$tpm_owner_password" &>/dev/null
724724

725725
# And now turn it all back on
726-
tpm physicalpresence -s >/dev/null 2>&1 || LOG "Unable to assert physical presence"
727-
tpm physicalenable >/dev/null 2>&1 || LOG "Unable to enable TPM"
728-
tpm physicalsetdeactivated -c >/dev/null 2>&1 || LOG "Unable to deactivate TPM physical presence requirement"
726+
DO_WITH_DEBUG tpm physicalpresence -s &>/dev/null
727+
DO_WITH_DEBUG tpm physicalenable &>/dev/null
728+
DO_WITH_DEBUG tpm physicalsetdeactivated -c &>/dev/null
729729
}
730730

731731
# Perform final cleanup before boot and lock the platform heirarchy.

0 commit comments

Comments
 (0)