<p dir="ltr">Thanks for you reply. My point is that defeating the PCR update in the measuring step of systemd-crypsetup could be not so hard to realize (see the two ways in my initial email)</p>
<br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Le dim. 9 mars 2025 à 09:02, Andrei Borzenkov <<a href="mailto:arvidjaar@gmail.com">arvidjaar@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">08.03.2025 22:40, Andrei Borzenkov wrote:<br>
> 08.03.2025 21:52, Diorcet Yann wrote:<br>
>> Hello,<br>
>><br>
>> I'm in the process of using SecureBoot, TPM2.0 and LUKS2 to protect an<br>
>> industrial embedded computer.<br>
>><br>
>> I have a chain of trust in the UEFI (own secure boot keys/certificates),<br>
>> signed grub2, all files used by grub2 signed including kernel and<br>
>> initramfs,  and successfully automatically unlocked LUKS partitions<br>
>> using TPM2.0 using PCR7.<br>
>><br>
>> The main concern remaining is to be sure to chroot on the "good" root<br>
>> partition (and not a malicious one allowing to decrypt using TPM the<br>
>> "good" partition).<br>
>><br>
>> pcrphase ensures that "good" root partition can only be unlocked in the<br>
>> good phase (after enter-initrd for example), this is an additional security.<br>
>><br>
>> tpm2-measure-pcr provides a way to only decrypt other partitions after<br>
>> the "good" root partition: Using for example 7+11+15<br>
>><br>
>><br>
>> But in the case of multiple partitions unlocked by the initrd, I can't<br>
>> figure why an attacker couldn't succeed to :<br>
>><br>
> <br>
> tpm2-measure-pcr is in /etc/crypttab which is included in the signed<br>
> initrd and so cannot be forged. As long as the second device depends on<br>
> the result of the measurement of the first (root), replacing root will<br>
> fail to automatically unlock it.<br>
> <br>
<br>
Sorry, you actually were right. Normally root will not depend on any <br>
previous measurements and we trust device metadata to provide the list <br>
of PCRs.<br>
<br>
You will need to add the PCR into which root is measured to the root <br>
metadata. It would normally be in the initial well known state directly <br>
after boot (so, when root is normally unlocked) but will change if you <br>
exchange the real root for the fake one.<br>
<br>
>> - Clone the original disk (notably ESP)<br>
>><br>
>> - Replace root partition by a malicious one<br>
>><br>
>> - Fake the second (using UUID/PARTLABEL/...) but using LUKS partition<br>
>> from the "good" root partition<br>
>><br>
>> - Boot the machine<br>
>><br>
>> - The initrd will try unlocks the malicious partition as root. As the<br>
>> TPM token will not work, the attacker will use the password of his<br>
>> malicious LUKS<br>
>><br>
>> - Make the update of the PCR due to the measuring of the malicious<br>
>> partition fails<br>
>><br>
>> - Initrd will try to unlock the second partition, which is the "good"<br>
>> root partition, and it will succeed, allowing the attacker to finally<br>
>> access all data from the partition.<br>
>><br>
>><br>
>> The main point here is to "Make the update of the PCR due to  the<br>
>> measuring of the malicious partition fails".<br>
>><br>
>> Indeed the measuring may be never executed:<br>
>><br>
>> <a href="https://github.com/systemd/systemd/blob/bd0d22c2a5bdbf427c68eab630dc06f55dc96c72/src/cryptsetup/cryptsetup.c#L1085" rel="noreferrer noreferrer" target="_blank">https://github.com/systemd/systemd/blob/bd0d22c2a5bdbf427c68eab630dc06f55dc96c72/src/cryptsetup/cryptsetup.c#L1085</a><br>
>><br>
>> This may happens in few cases:<br>
>><br>
>> - volume_key_size == 0? Is it possible to make cryptsetup to unlock a<br>
>> malicious partition during initrd with this condition? I'm not aware of<br>
>> the details for example with LUKS2<br>
>><br>
>> - Making the measure_volume_key fails will not produce any counter<br>
>> reaction (just an error message for example "Could not extend PCR: 15"):<br>
>> "OK if fails"<br>
>><br>
>> A way to make it happens, is to glitching at a specific moment the<br>
>> communication with the TPM2.0, or using MITM faking/failing an update of<br>
>> the PCR allowing automatic unlock of the "good" root partitions as<br>
>> second partition. Adding a check on measure_volume_key return value may<br>
>> be not sufficient.<br>
>><br>
>><br>
>> Maybe I missing some pieces, but I only see two ways to defeat that:<br>
>><br>
>> - Enforcing the use of TPM2.0 exclusively (no fallback on password):<br>
>> cryptsetup exiting with non zero exit code making initrd fails. Is it<br>
>> possible?<br>
>><br>
>> - Don't use multiple encrypted partitions.<br>
>><br>
>><br>
>> May I miss understanding something?<br>
>><br>
>><br>
>> Regards,<br>
>><br>
>> Yann<br>
>><br>
>><br>
>><br>
>><br>
> <br>
<br>
</blockquote></div>