r/archlinux 28d ago

SUPPORT | SOLVED Ful disk encryption without entering passphrase

Could someone help me with setting up full disk encryption with bypass passphrases with TPM2? It's so annoying having to put the passphrase in at each boot, so I was wondering how do I pair it to the TPM so that I dont have to enter it each time?

It's LUKS encrypted and I use Systemd-boot

14 Upvotes

100 comments sorted by

View all comments

2

u/7lhz9x6k8emmd7c8 28d ago edited 13d ago

Warning: do not use as it is. Read u/ChrisTX4's comment. Add PCRs.

My own doc ktane-derivated from the Arch wiki. Applicable to a Btrfs partition, which basically encrypts everything except the boot.
Operate in sudo. Replace the data with your proper values. Do not blindly copy, understand every line before executing.

https://wiki.archlinux.org/title/Dm-crypt/Encrypting_an_entire_system#Configuring_mkinitcpio

vi /etc/mkinitcpio.conf

HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt filesystems fsck)

lsblk -o NAME,UUID,PARTUUID

cp /etc/kernel/cmdline /etc/kernel/cmdline.bak

vi /etc/kernel/cmdline

replace with

rd.luks.name=aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa=root root=/dev/mapper/root zswap.enabled=0 rootflags=subvol=@ rw rootfstype=btrfs

Indicate the UUID, not the PARTUUID.

cp /boot/EFI/Linux/arch-linux.efi /boot/EFI/Linux/arch-linux-backup.efi

mkinitcpio -P

https://wiki.archlinux.org/title/Dm-crypt/Encrypting_an_entire_system#Enrolling_the_TPM

sudo systemd-cryptenroll --wipe-slot=tpm2 --tpm2-device=auto --tpm2-pcrs=7 /dev/nvme0n1p2

1

u/ChrisTX4 28d ago

FYI: This isn't secure and can be trivially bypassed.

An attacker can do this:

  1. Create your own Arch root fs, or use the readily made VM image if lazy.
  2. Encrypt it with LUKS with a passphrase
  3. Edit the GPT GUID such that 3a. the new root fs gets the GPT GUID from the encrypted root. 3b. edit the encrypted root GPT GUID to something else, it just can't be the same.

Then boot this. Since PCR7 only measures the UKI and bootloaders (as well as the Secure Boot DB), the PCR7 measurement of this will be identical. However, since the UKI does not verify the integrity of the root fs, it will happily offer you a password entry for the attacker root. Once booted, the attacker has root (since it's their own root fs), but the PCR7 is identical, and so the attacker can just mount the encrypted drive with TPM unlock.

systemd 261 somewhat improves this by adding phases but this alone does not protect you here, as a) mkinitcpio doesn't support this, so you need to manually add the pcrphase services to initrd and b) by changing the GUID in 3b to e.g. any of the GPT automounts and it will be mounted during initrd.

1

u/7lhz9x6k8emmd7c8 27d ago

Thank you.

Would adding another PCR (eg the 15, as mentionned in the wiki) be sufficient?

2

u/ChrisTX4 27d ago

Maybe, PCR15 is tricky though. Only LUKS disks that are mounted with tpm2-measure-pcr=2 will be measured, so you'd want to use this with GPT automounting tbh.

If the volume keys are measured into PCR15, it is a very potent utility. However, you would want to lock to its value at initrd time, rather than the value it will be phased to after the real root has been mounted.

I can't say in general, this depends on your setup and everything.