#846383 grub2: add TPM support

Package:
grub2
Source:
grub2
Description:
GRand Unified Bootloader, version 2 (dummy package)
Submitter:
"Urquiza, Fabio"
Date:
2021-08-21 20:33:04 UTC
Severity:
wishlist
Tags:
#846383#5
Date:
2016-11-30 20:11:03 UTC
From:
To:
### Overview ###

The Measured or Trusted Boot feature provides Anti-Malware (AM) software with a
trusted (resistant to spoofing and tampering) log of all boot components that
started before AM software. AM software can use the log to determine whether
components that ran before it are trustworthy or if they have been tampered
with. The AM software on the local machine can send the log to a remote server
for evaluation. The remote server may initiate remediation actions either by
interacting with software on the client or through out-of-band mechanisms, as
appropriate.

We think that TPM support is a good addition to Debian because it can increase
its adoption in environments where a more secure approach to the booting is
needed, by being able to securely measure if any component has been tampered.

### Patches origin and submission to upstream ###

TPM support for architectures i386 and x86_64 have been submitted to CoreOS by
Matthew Garrett from its private GRUB repository. The patches submitted allow
GRUB to measure all loaded files (Linux kernel, initrd and Grub modules) and
all command executed. They have not been submitted to GRUB upstream for
political and philosophic reasons. More detail about that on the links below:

https://www.gnu.org/philosophy/can-you-trust.html
http://lists.gnu.org/archive/html/grub-devel/2013-09/msg00070.html

### Removal of floppy probe ###

Although EFI does not have the MBR size constraints, the grub-pc first stage
must be 512 bytes. The addition of the TPM code to measure the MBR on boot,
made the image size increased to 553 bytes (with some adjustments to keep both
TPM and floppy code at the same time). The Debian build process fails when
executing the tests for floppy and HDD boot if both TPM and Floppy code
co-exists, not generating the images and packages.

If the floppy support is needed, all the user needed to do is to disable TPM
support during the build. More details about how to disable its support below.

### Tests ###

We tested the feature in a HPE ProLiant DL180 Generation9 with TPM hardware and
secure boot enabled. To check the feature, please execute the following
procedure:

Check the values of the PCR registers:

$ sudo cat /sys/devices/pnp0/00:00/pcrs | grep -C1 PCR-08
PCR-07: F3 56 28 7E E4 09 02 0E A1 11 7B 90 49 09 3D DD FF 0D 60 23
PCR-08: 7B F7 E5 4C 38 D7 29 E7 5D B9 85 88 E4 C0 AF 07 04 4B D7 2E
PCR-09: 0A BC 8E E7 D3 7D 21 72 01 11 C9 D4 E4 7E E7 C3 A5 D7 21 48

Change something in the /boot/efi/EFI/debian/grub.cfg file (for instance, add
a directory slash in the command linux /boot/vmlinuz-4.4.19-1-amd64-hpelinux).
from the former boot.

$ sudo cat /sys/devices/pnp0/00:00/pcrs | grep -C1 PCR-08
PCR-07: F3 56 28 7E E4 09 02 0E A1 11 7B 90 49 09 3D DD FF 0D 60 23
PCR-08: 64 3A 96 3E 02 45 5B 26 83 8B 9A 4F 77 AF E5 39 80 71 DF 66
PCR-09: 0A BC 8E E7 D3 7D 21 72 01 11 C9 D4 E4 7E E7 C3 A5 D7 21 48

Remove the change that was made in /boot/grub/grub.cfg and restart the server.
The PCR-08 should return to it's former value.

### Application of the patches ###

The patches have been divided into two patch sets that are attached to the
message as compressed tarballs:

1. grub-tpm-support.tar.xz - contains all patches related to the
functionality itself.
2. grub-tpm-enable.tar.xz - contains the patches that modifies de debian/
directory in order to enable the feature during the build.

The last patch set enable to TPM support by exporting a environment variable in
the debian/rules file

To disable the TPM (and get the floppy support back) simply remove that line.

#846383#12
Date:
2017-02-17 00:14:18 UTC
From:
To:
If you read the *end* of the Stallman link at

https://www.gnu.org/philosophy/can-you-trust.html

it looks like the FSF has noticed that TPMs totally failed for DRM and
remote attestation, and no longer objects to using them for things
like locally verifying code integrity.

Which means that I'd expect vanilla grub2 to now be willing to take
measured boot patches. The 2013 email link would appear to be
way out of date.

#846383#17
Date:
2021-08-21 14:05:11 UTC
From:
To:
 ❦ 30 November 2016 20:11 GMT, Urquiza, Fabio:

It seems that Grub in Debian has now TPM support as there is a tpm.mod
shipped with Grub. Manual here:
https://www.gnu.org/software/grub/manual/grub/html_node/Measured-Boot.html

The documentation suggests the module should be builtin. If not, it is a
bit unknown what can happen. Maybe the tpm.mod itself can be tampered?

Would it be possible to have the module builtin for GRUB UEFI (where
the size does not matter)?

#846383#22
Date:
2021-08-21 16:45:13 UTC
From:
To:
It already is, in bullseye:

grub2 (2.04-18) unstable; urgency=medium

  [ Steve McIntyre ]
  * Enable the shim_lock and tpm modules for i386-efi too. Ensure that
    tpm is included in our EFI images.
  [...]

#846383#27
Date:
2021-08-21 18:42:26 UTC
From:
To:
 ❦ 21 August 2021 17:45 +01, Colin Watson:

Does this mean it's inside "core.efi"? I think this is not the case:
there is a "tpm.mod" file and "strings core.efi | grep tpm" does not
return any result. But maybe it's easy for a user to build a core.efi
with the module added? Some users may like core.efi to be signed, but
that's not my case.

#846383#32
Date:
2021-08-21 20:22:17 UTC
From:
To:
fixed 846383 2.04-18
thanks

 ❦ 21 August 2021 20:42 +02, Vincent Bernat:

OK, that's not the file which is used to boot with EFI. This is
/usr/lib/grub/x86_64-efi/monolithic/grubx64.efi which contains the TPM
module. So, yes, this can be closed.