Visitar URL original
cryptsetup: Skip TPM2 tokens that fail to parse, in all code paths by pothos · Pull Request #44486 · systemd/systemd · GitHub
Skip to content

cryptsetup: Skip TPM2 tokens that fail to parse, in all code paths - #44486

Open
pothos wants to merge 1 commit into
systemd:mainfrom
pothos:tpm2-malformed-token-skip
Open

pothos wants to merge 1 commit into
systemd:mainfrom
pothos:tpm2-malformed-token-skip

Conversation

@pothos

@pothos pothos commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

When a systemd-tpm2 token failed to parse, find_tpm2_auto_data() only skipped it for EUCLEAN and returned any other error, thus stopping the unlock early even if the next token would be working. This could be the case where one token is for a machine with newer software. This affects the cryptsetup fallback path, systemd-cryptenroll, and the new unlocking of DDIs but the crypsetup plugin skipped over every error except EUCLEAN (e.g., incomplete Argon2id parameters). All errors from tpm2_parse_luks2_json() except ENOMEM are about the token's own data and we should skip over them equally in all code paths. Skip over parsing errors for tokens in find_tpm2_auto_data(). Also remap the error to EPERM in the plugin as already done for JSON that can't be parsed at all. This unifies the behavior and gets tested now with two malformed tokens in front of a good one for the token plugin, the fallback path, systemd-cryptenroll, and systemd-dissect (the DDI case).

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Reviewed f6baef2 (architecture, correctness, lifetimes, style, tests; failed: security).

Suggestions

  • src/shared/cryptsetup-tpm2.c:380 The -EUCLEAN special case now only stops the warning from being logged. Its comment is also out of date: the parser returns EUCLEAN for our own Argon2id fields too, so token 1 gets skipped silently while token 0 (EINVAL) logs a warning. Drop the special case so the generic skip-with-warning branch below handles it.
  • src/shared/cryptsetup-tpm2.c:384 No caller special-cases -EUCLEAN anymore, so the keyslot error remap to -EUCLEAN in tpm2_parse_luks2_json() (tpm2-util.c ~11994-12002) and its "callers can handle gracefully" comment are dead. They only make this warning print "Structure needs cleaning" instead of the real errno. Return keyslot directly.

Nits

  • src/shared/cryptsetup-tpm2.c:384 This new comment is 128 columns, well over the ~109ch limit in CODING_STYLE.md. Wrap it across two lines like the other multi-line comments.

The review is incomplete, so the next push reviews the full diff again.

Workflow run

Comment thread src/shared/cryptsetup-tpm2.c Outdated
Comment thread src/shared/cryptsetup-tpm2.c Outdated
When a systemd-tpm2 token failed to parse, find_tpm2_auto_data() only
skipped it for EUCLEAN and returned any other error, thus stopping the
unlock early even if the next token would be working. This could be the
case where one token is for a machine with newer software. This affects
the cryptsetup fallback path, systemd-cryptenroll, and the new unlocking
of DDIs but the cryptsetup plugin skipped over every error except
EUCLEAN (e.g., incomplete Argon2id parameters). All errors from
tpm2_parse_luks2_json() except ENOMEM are about the token's own data and
we should skip over them equally in all code paths.
Skip over parsing errors for tokens in find_tpm2_auto_data() with a
warning. Also remap the error to EPERM in the plugin as already done for
JSON that can't be parsed at all. This unifies the behavior and gets
tested now with two malformed tokens in front of a good one for the
token plugin, the fallback path, systemd-cryptenroll, and
systemd-dissect (the DDI case).
@pothos
pothos force-pushed the tpm2-malformed-token-skip branch from bc001da to f6baef2 Compare October 30, 2026 04:08
@pothos
pothos marked this pull request as ready for review October 30, 2026 04:09
@github-actions github-actions Bot added downstream/amutable Issues that apply to downstream amutable distribution please-review PR is ready for (re-)review by a maintainer labels Oct 30, 2026
Comment on lines +379 to +384
if (r == -ENOMEM)
return log_full_errno(log_level, r, "Failed to parse TPM2 JSON data: %m");
if (r < 0) {
/* A token written by a newer version might use values we don't know, or it might be
* broken otherwise. Another token might still work. */
log_full_errno(MAX(log_level, LOG_WARNING), r, "Failed to parse TPM2 JSON data of token %i, skipping: %m", token);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: suggestion: No caller special-cases -EUCLEAN anymore, so the keyslot error remap to -EUCLEAN in tpm2_parse_luks2_json() (tpm2-util.c ~11994-12002) and its "callers can handle gracefully" comment are dead. They only make this warning print "Structure needs cleaning" instead of the real errno. Return keyslot directly.

@yuwata yuwata added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Oct 30, 2026

This branch has not been deployed

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

Labels

claude-review cryptsetup dissect downstream/amutable Issues that apply to downstream amutable distribution reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks tests tpm2 util-lib

Development

Successfully merging this pull request may close these issues.

2 participants