Skip to content

Bugfix: Fix TPM auth retry, counter error handling, and NV error surfacing#2099

Open
tlaurion wants to merge 1 commit intolinuxboot:masterfrom
tlaurion:bugfix-tpm_increment_on_seal
Open

Bugfix: Fix TPM auth retry, counter error handling, and NV error surfacing#2099
tlaurion wants to merge 1 commit intolinuxboot:masterfrom
tlaurion:bugfix-tpm_increment_on_seal

Conversation

@tlaurion
Copy link
Copy Markdown
Collaborator

@tlaurion tlaurion commented May 5, 2026

This PR fixes regressions introduced by PR #2068, merged to origin/master on 2026-04-07.

Regressions fixed (present in origin/master post-PR #2068):

  • No "out of resources" (0x15) TPM counter error detection: caused generic DIE "Unable to create TPM counter" instead of setting tpm_reset_required.
  • TPM2 counter increment had no auth retry on wrong passphrase: failed immediately instead of retrying up to 3 times.
  • TPM1 counter increment had no error handling: fell through to raw exec tpm with no retry or error checking.
  • tpm1_seal silenced NV define/write errors via 2>&1 | DEBUG and || true, hiding failures from users.
  • Duplicate TPM1/TPM2 retry loops across seal, counter create, and increment functions (~100 lines of redundant code).
  • $pass: command not found bug in retry logic due to mishandled passphrase variables.
  • No tpm_reset_required flag set on 0x15 non-auth counter errors.

Fixes implemented:

  • Add shared _tpm_auth_retry helper for TPM1 (stdout errors, -pwdo/-pwdc flags) and TPM2 (stderr errors, -P flag) with up to 3 auth retry attempts.
  • check_tpm_counter only triggers set_tpm_reset_required on 0x15 errors, not auth failures.
  • tpm1_seal surfaces NV define/write errors with a retry loop instead of silencing them.
  • Simplify reset_tpm to verify tpmr.sh reset exit code and fix indentation.
  • Update documentation: doc/tpm.md (0x15 error recovery), doc/ux-patterns.md (TPM error UX patterns).

Copilot review fixes:

  • Fix counter_present dead code: add counter_read check in increment_tpm_counter to properly distinguish "readable but not incrementable" from missing counter.
  • Fix doc references: tpmr -> tpmr.sh for consistency with actual binary name.

Docs: unify script name references

  • Update all initrd/bin/* and initrd/etc/* references in doc/* to use .sh extension, matching the actual filenames (scripts were renamed in older PR, docs didn't follow).

Testing: Verified with tlaurion-bugfix-tpm_increment_on_seal-seal.log and tlaurion-bugfix-tpm_increment_on_seal-review.log — no regressions, counter increments succeed, no TPM reset required.

Copilot AI review requested due to automatic review settings May 5, 2026 18:31
@tlaurion tlaurion changed the title Bugfix: Fix TPM auth retry, counter error handling, and NV error surf… Bugfix: Fix TPM auth retry, counter error handling, and NV error surfacing May 5, 2026
@tlaurion tlaurion linked an issue May 5, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses TPM regressions introduced in PR #2068 by reworking TPM counter creation/increment error handling and auth retry behavior, and updating GUI flows/docs to surface TPM reset-required states more clearly.

Changes:

  • Add shared TPM auth-retry helper logic and refactor TPM1/TPM2 counter operations in tpmr.sh.
  • Improve rollback counter creation/increment handling and propagate TPM “out of resources (0x15)” into a tpm_reset_required marker + targeted UX.
  • Update GUI flows and documentation to support “Reset the TPM” gate-bypass patterns and clearer recovery guidance.

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
initrd/etc/gui_functions.sh Exit integrity investigation loop when update_checksums triggers tpm_reset_required.
initrd/etc/functions.sh Detect TPM 0x15 on counter_create and adjust TPM counter increment plumbing.
initrd/bin/tpmr.sh Introduce _tpm_auth_retry, refactor TPM counter ops, and surface TPM1 stdout quirks.
initrd/bin/gui-init.sh Improve UX around checksum update failure and gate bypass for TPM reset; verify TPM reset result.
doc/ux-patterns.md Document the reset gate-bypass UX pattern.
doc/tpm.md Document 0x15 recovery behavior and TPM1 stdout behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/tpm.md Outdated
Comment thread initrd/etc/functions.sh
@tlaurion tlaurion marked this pull request as draft May 5, 2026 19:08
@tlaurion tlaurion force-pushed the bugfix-tpm_increment_on_seal branch from 35fa6b0 to d76d01c Compare May 5, 2026 21:25
@tlaurion tlaurion requested a review from Copilot May 5, 2026 21:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 13 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

initrd/etc/functions.sh:1901

  • The comment above the counter_increment pipeline says stdout is captured “while still letting stdout appear on the console”, but the current pipeline ends with tee /tmp/counter-... >/dev/null, which discards stdout from the console entirely. Either update the comment to match the behavior, or adjust the pipeline if the intent really is to keep stdout visible to the user.
	# Try to increment the counter.  We normally hide the verbose
	# output of tpmr.sh commands to avoid overwhelming the console, but we
	# must *not* swallow any interactive prompts.  The previous implementation
	# redirected the entire `tpmr.sh counter_create` invocation to a file and
	# /dev/null, which meant that when the counter was missing the password
	# prompt could not be seen by the user even though tpmr.sh printed it to the
	# controlling terminal.  Instead, capture just the stdout in a temporary
	# file while still letting stdout appear on the console (and logging
	# stderr to debug log).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tlaurion tlaurion force-pushed the bugfix-tpm_increment_on_seal branch from d76d01c to 9241c16 Compare May 5, 2026 21:50
@tlaurion tlaurion requested a review from Copilot May 5, 2026 22:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 13 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

initrd/etc/functions.sh:1901

  • The comment above the counter increment pipeline says stdout is captured “while still letting stdout appear on the console”, but the actual pipeline sends stdout into tee ... >/dev/null, which suppresses console output. Either adjust the redirection to match the comment (if console output is desired) or update the comment to reflect that stdout is intentionally hidden and only logged/stored.
	# Try to increment the counter.  We normally hide the verbose
	# output of tpmr.sh commands to avoid overwhelming the console, but we
	# must *not* swallow any interactive prompts.  The previous implementation
	# redirected the entire `tpmr.sh counter_create` invocation to a file and
	# /dev/null, which meant that when the counter was missing the password
	# prompt could not be seen by the user even though tpmr.sh printed it to the
	# controlling terminal.  Instead, capture just the stdout in a temporary
	# file while still letting stdout appear on the console (and logging
	# stderr to debug log).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/tpm.md Outdated
Comment thread doc/tpm.md Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 13 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/tpm.md Outdated
Comment thread doc/tpm.md Outdated
Comment thread initrd/etc/functions.sh Outdated
…acing

This commit fixes regressions introduced by PR linuxboot#2068, merged to origin/master on 2026-04-07.

Regressions fixed (present in origin/master post-PR linuxboot#2068):
- No "out of resources" (0x15) TPM counter error detection
- TPM2 counter increment had no auth retry on wrong passphrase
- TPM1 counter increment had no error handling
- tpm1_seal silenced NV define/write errors
- Duplicate TPM1/TPM2 retry loops (~100 lines of redundant code)
- counter_present dead code (now fixed with counter_read check)
- Comment mismatch (stdout vs console) now fixed
- set -e issue in check_tpm_counter (wrapped in subshell)

Fixes implemented:
- Add shared _tpm_auth_retry helper for TPM1/TPM2
- check_tpm_counter only triggers tpm_reset_required on 0x15 errors
- tpm1_seal surfaces NV errors with retry loop
- Simplify reset_tpm to verify tpmr.sh reset exit code

Copilot review fixes:
- Fix counter_present dead code: add counter_read check
- Fix doc references: tpmr -> tpmr.sh for consistency
- Fix comment at line 1901: stdout goes to /dev/null via tee
- Wrap tpmr.sh counter_create in subshell for set -e compatibility

Signed-off-by: Thierry Laurion <insurgo@riseup.net>
@tlaurion tlaurion force-pushed the bugfix-tpm_increment_on_seal branch from a88ee0e to 73b1916 Compare May 5, 2026 23:27
@tlaurion tlaurion requested a review from Copilot May 5, 2026 23:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tlaurion tlaurion marked this pull request as ready for review May 5, 2026 23:34
@tlaurion
Copy link
Copy Markdown
Collaborator Author

tlaurion commented May 5, 2026

Wating for +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TPM1 sometimes fail to seal secrets

2 participants