Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TPM DUK retry loop (bogus), uniformize related vocabulary #1595

Merged
merged 3 commits into from
Jan 22, 2024

Conversation

tlaurion
Copy link
Collaborator

@tlaurion tlaurion commented Jan 19, 2024

#1588 related: fixes retry. Left behind: capslock key detection and fix.

@JonathonHall-Purism please review

Tested:

  • lukskillslot of slot 1 when two available.
  • lukschangepassword without specifying slot so that slot 0 LUKS Disk Recovery Key is put under slot1 where no slot 0 exist.
    • on TPM DUK addition, warning showed to user to repair manual config which is unsupported
    • when manually fixed as suggested, both slot 1 and slot 0 exist and Heads detects and warns correctly on both LUSKv1 and LUKSv2
  • TPM DUK loops for 1/3 to 3/3 and warns that capslock might be the cause of failing.
  • After 3 bad attempts, normal codepath continue proposing user to type LUKS Disk Recovery Key password in OS.

Basically, the loop code was bogues because of pipefail, TPM DUK passphrase failing to unseal caused pipefail and exiting without retrying input as codepath expected.

TODO: find a nice way to get capslock state from tty. Only way found as of now would be through kbd, and extracting ioctl call to tty to get state of key modifiers. That is estimated to be 7kb of compiled c code that would need to be an independent app. I have not found any other easy way to get capslock state. Reminder, there is no capslock led on old lenovos, and exposing those leds through kernel modules successfully exposes capclock but since EC firmware doesn't interact in any way with abent leds, the state cannot be read from LEDs so not an alternative solution. If anybody has an idea that could go through exposed /sys /proc or even agetty/stty, I tried a lot but didn't succeed. @JonathonHall-Purism ideas there?

Copy link
Collaborator

@JonathonHall-Purism JonathonHall-Purism left a comment

Choose a reason for hiding this comment

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

Thanks @tlaurion, good find, improvements to wording consistency are great too. Posted a few notes but generally looks good. Not sure if the fix is 100% correct from a read over but made a suggestion, details on kexec-unseal-key.

initrd/bin/kexec-unseal-key Outdated Show resolved Hide resolved
initrd/bin/kexec-seal-key Outdated Show resolved Hide resolved
initrd/etc/luks-functions Outdated Show resolved Hide resolved
…output to check active keyslot 1 is not the only one existing

Signed-off-by: Thierry Laurion <[email protected]>
@tlaurion tlaurion force-pushed the fix_tpm_duk_retry branch 3 times, most recently from d701946 to 5a52c67 Compare January 19, 2024 20:43
When playing with long fbwhiptail/whiptail messages, this commit played around the long string using fold.

'''
echo -e "This will replace the encrypted container content and its LUKS Disk Recovery Key.\n\nThe passphrase associated with this key will be asked from the user under the following conditions:\n 1-Every boot if no Disk Unlock Key was added to the TPM\n 2-If the TPM fails (hardware failure)\n 3-If the firmware has been tampered with/modified by the user\n\nThis process requires you to type the current LUKS Disk Recovery Key passphrase and will delete the LUKS TPM Disk Unlock Key slot, if set up, by setting a default boot LUKS key slot (1) if present.\n\nAt the next prompt, you may be asked to select which file corresponds to the LUKS device container.\n\nHit Enter to continue." | fold -w 70 -s
'''

Which gave the exact output of what will be inside of the fbwhiptail prompt, fixed to 70 chars width:

'''
This will replace the encrypted container content and its LUKS Disk
Recovery Key.

The passphrase associated with this key will be asked from the user
under the following conditions:
 1-Every boot if no Disk Unlock Key was added to the TPM
 2-If the TPM fails (hardware failure)
 3-If the firmware has been tampered with/modified by the user

This process requires you to type the current LUKS Disk Recovery Key
passphrase and will delete the LUKS TPM Disk Unlock Key slot, if set
up, by setting a default boot LUKS key slot (1) if present.

At the next prompt, you may be asked to select which file corresponds
to the LUKS device container.

Hit Enter to continue.
'''

Therefore, for long prompts in the future, one can just deal with "\n 1-" alignments to be respected in prompts and have fold deal with cutting the length of strings properly.

Signed-off-by: Thierry Laurion <[email protected]>
…UG mode/Recovery Shell

Next steps on this is introspection and PCRs reconstruction helpers, which will output in DEBUG and be usable from recovery shell.
We have to keep in mind that providing those tools is useful in DEBUG mode and for users having access to Recovery Shell.
But currently, having access to cbmem -L output and final PCRs content is making it too easy for Evil Maid to know what needs to be hardcoded to pass measured boot.

Signed-off-by: Thierry Laurion <[email protected]>
@tlaurion
Copy link
Collaborator Author

@JonathonHall-Purism Ready for merge?

Copy link
Collaborator

@JonathonHall-Purism JonathonHall-Purism left a comment

Choose a reason for hiding this comment

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

LGTM, thanks 👍

@tlaurion tlaurion merged commit bd9125f into linuxboot:master Jan 22, 2024
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants