Skip to content

IMA & TPM load order broken, resulting in no hardware root of trust for Integrity Measurement Architecture #3291

@lukehinds

Description

@lukehinds

Describe the bug

The load order of IMA and a TPM device is incorrect , which results in IMA not seeing the TPM and activating a TPM-bypass.

As the TPM is bypassed, IMA cannot benefit from the hardware root of trust that is possible with a Trusted Platform Module.

The TPM should initialize first, and then IMA.

This is a key security feature for protecting run time environments.

To reproduce

Place a TPM chip onto GPIO (I used the Infineon Optiga™ SLB 9670 from letstrust.de)

Compile the Kernel with the below configs set to enable IMA, securityfs and the TPM

CONFIG_SECURITY=y
CONFIG_SECURITYFS=y
CONFIG_INTEGRITY=y
CONFIG_IMA=y
CONFIG_IMA_MEASURE_PCR_IDX=10
CONFIG_IMA_AUDIT=y
CONFIG_IMA_LSM_RULES=y
CONFIG_IMA_WRITE_POLICY=y
CONFIG_IMA_READ_POLICY=y
CONFIG_IMA_APPRAISE=y
CONFIG_IMA_APPRAISE_BOOTPARAM=y
CONFIG_HW_RANDOM_TPM=y
CONFIG_TCG_TPM=y
CONFIG_TCG_TIS_CORE=y
CONFIG_TCG_TIS=y
CONFIG_TCG_CRB=y

Put a basic IMA-policy in place:

cat /etc/ima/ima-policy 

# PROC_SUPER_MAGIC
dont_measure fsmagic=0x9fa0
# SYSFS_MAGIC
dont_measure fsmagic=0x62656572
# DEBUGFS_MAGIC
dont_measure fsmagic=0x64626720
# TMPFS_MAGIC
dont_measure fsmagic=0x01021994
# RAMFS_MAGIC
dont_measure fsmagic=0x858458f6
# SECURITYFS_MAGIC
dont_measure fsmagic=0x73636673
# MEASUREMENTS
measure func=BPRM_CHECK
measure func=FILE_MMAP mask=MAY_EXEC
measure func=MODULE_CHECK uid=0

reoot the pi, and run dmesg

pi@raspberrypi:~ $ dmesg | grep -i tpm
[    0.995705] ima: No TPM chip found, activating TPM-bypass! (rc=-19)
[    6.566532] tpm_tis_spi spi0.1: 2.0 TPM (device-id 0x1B, rev-id 22)
[    6.582596] tpm tpm0: A TPM error (256) occurred attempting the self test
[    6.582619] tpm tpm0: starting up the TPM manually

After some investigation I found the following mailing list discussion on the IMA list

One of the IMA developers was able to initialize the TPM prior to IMA, by reverting commit acddd39

And disabling the self test

-       rc = tpm2_start_selftest(chip, true);
+       rc = tpm2_start_selftest(chip, false);

This was from 2017 so a fresh RCA might play out differently.

Expected behaviour

The TPM should load first, which will result in IMA finding the TPM and using it for cryptographic extend operations in PCR 10.

Actual behaviour

The load order is wrong.

System

  • Which model of Raspberry Pi?
    Raspberry Pi 3 Model B+

  • Which OS and version (cat /etc/rpi-issue)?

Raspberry Pi reference 2019-07-10
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 175dfb027ffabd4b8d5080097af0e51ed9a4a56c, stage2
  • Which firmware version (vcgencmd version)?
Jul  9 2019 14:40:53 
Copyright (c) 2012 Broadcom
version 6c3fe3f096a93de3b34252ad98cdccadeb534be2 (clean) (release) (start)
  • Which kernel version (uname -a)?
uname -a
Linux raspberrypi 4.19.79-v7+ #1 SMP PREEMPT Thu Oct 17 11:01:59 BST 2019 armv7l GNU/Linux

Additional context
I will continue to debug this, but truth be told I don't know the clock functionality in code very well, so if anyone thinks they can fix this, please do go ahead and if you want any tests run against a HW TPM, I am happy to help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Waiting for external inputWaiting for a comment from the originator of the issue, or a collaborator.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions