linux/drivers/char/tpm
Surendran Kanagaraj 015fb29a74 tpm: Disable TPM on null key name mismatch
The null key name check exists to protect against TPM reset attacks, so
a mismatch should stop the device from serving further requests.
Currently it does not disable the chip when it finds a mismatch.

The mismatch is logged:

    tpm tpm0: null key integrity check failed

but the chip keeps serving commands:

    / # tpm2_getcap -c properties-fixed
    TPM_PT_FAMILY_INDICATOR:
      as UINT32:                0x08322e3000
      as string:                "2.0"
    ...

tpm2_load_null() where the null key name check is run sets the chip as
disabled only if the rc is non zero. When the mismatch is seen, rc is
zero at that point and it returns success. The other issue is that the
caller expects the null key handle to be populated when the function
returns 0 which it does here without writing the handle and proceeds
assuming the null key handle is valid.

During the test, I noticed that tpm2_start_auth_session() uses the
uninitialized stack value as the key handle since tpm2_load_null()
returns 0 despite the integrity failure and proceeds with
TPM2_CC_START_AUTH_SESS with this value as salt key handle.

Set rc to -ENODEV on the mismatch. The error path then disables the chip
and returns the correct code to the caller.

Tested in QEMU with swtpm and CONFIG_TCG_TPM2_HMAC=y by making
TPM2_CC_CONTEXT_LOAD fail with TPM2_RC_INTEGRITY and changing the name
of the re-created null key. The chip is now disabled on the mismatch.

Fixes: cc7d859434 ("tpm: Rollback tpm2_load_null()")
Fixes: 423893fcbe ("tpm: Disable TPM on tpm2_create_primary() failure")
Cc: stable@vger.kernel.org # v6.12+
Assisted-by: LLM
Signed-off-by: Surendran Kanagaraj <surenkj@amazon.com>
Link: https://lore.kernel.org/r/20260918000731.48657-1-surenkj@amazon.com
Reviewed-by: Gunnar Kudrjavets <gunnarku@amazon.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
History 2026-09-29 22:15:21 +03:00
..
eventlog tpm: fix event_size output in tpm1_binary_bios_measurements_show 2026-06-21 04:25:28 +03:00
st33zp24 tpm: st33zp24: Validate locality read result 2026-08-25 18:13:34 +03:00
Kconfig tpm: atmel: depend on X86 2026-08-25 18:13:34 +03:00
Makefile tpm: Add a driver for Loongson TPM device 2025-09-02 12:29:57 +01:00
tpm-buf.c tpm-buf: Add TPM buffer support header for standalone reuse 2026-08-25 18:13:37 +03:00
tpm-chip.c tpm: Use kfree_sensitive() to free auth session in tpm_dev_release() 2026-04-21 18:54:28 +03:00
tpm-dev-common.c tpm: add WQ_PERCPU to alloc_workqueue users 2025-12-03 22:55:28 +02:00
tpm-dev.c tpm: Make the TPM character devices non-seekable 2026-07-12 12:52:34 -07:00
tpm-dev.h tpm: Handle negative priv->response_len in tpm_common_read() 2020-01-08 18:11:09 +02:00
tpm-interface.c tpm: Fix heap buffer overflow in tpm_transmit_cmd() 2026-09-29 22:15:20 +03:00
tpm-sysfs.c tpm-buf: Memory-safe allocations 2026-08-25 18:13:36 +03:00
tpm.h tpm: Move TPM common base definitions to the command header 2026-08-25 18:13:35 +03:00
tpm1-cmd.c tpm-buf: Memory-safe allocations 2026-08-25 18:13:36 +03:00
tpm2-cmd.c tpm: fix off-by-four bounds check in tpm2_get_random() 2026-09-29 22:15:21 +03:00
tpm2-sessions.c tpm: Disable TPM on null key name mismatch 2026-09-29 22:15:21 +03:00
tpm2-space.c tpm-buf: Memory-safe allocations 2026-08-25 18:13:36 +03:00
tpm_atmel.c tpm: add bufsiz parameter in the .send callback 2025-07-23 02:23:18 +03:00
tpm_crb.c tpm_crb: Check ACPI_COMPANION() against NULL during probe 2026-06-21 04:25:28 +03:00
tpm_crb_ffa.c tpm: tpm_crb_ffa: revert defered_probed when tpm_crb_ffa is built-in 2026-06-21 04:25:28 +03:00
tpm_crb_ffa.h tpm_crb_ffa: Remove unused export 2025-07-23 02:23:18 +03:00
tpm_ftpm_tee.c tpm/tpm_ftpm_tee: Fix kdoc after function renames 2026-01-15 10:28:33 +01:00
tpm_ftpm_tee.h tpm/tpm_ftpm_tee: support TPM_CHIP_FLAG_SYNC 2025-07-23 02:23:18 +03:00
tpm_i2c_atmel.c tpm: i2c: atmel: fix block comment formatting 2026-04-21 18:54:28 +03:00
tpm_i2c_infineon.c tpm: tpm_i2c_infineon: Fix locality leak on get_burstcount() failure 2026-02-03 02:36:32 +02:00
tpm_i2c_nuvoton.c tpm: Remove redundant dev_err() 2026-08-25 18:13:34 +03:00
tpm_ibmvtpm.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
tpm_ibmvtpm.h tpm: ibmvtpm: Avoid error message when process gets signal while waiting 2021-08-23 19:55:42 +03:00
tpm_infineon.c tpm: add bufsiz parameter in the .send callback 2025-07-23 02:23:18 +03:00
tpm_loongson.c tpm: loongson: Add bufsiz parameter to tpm_loongson_send() 2025-09-25 12:45:03 +01:00
tpm_nsc.c tpm: add bufsiz parameter in the .send callback 2025-07-23 02:23:18 +03:00
tpm_ppi.c tpm: Prevent local DOS via tpm/tpm0/ppi/*operations 2025-10-10 08:21:45 +03:00
tpm_svsm.c tpm: svsm: constify tpm_chip_ops 2026-06-21 04:25:27 +03:00
tpm_tis.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
tpm_tis_core.c tpm: tpm_tis: Add settle time for some TPMs 2026-06-21 04:25:28 +03:00
tpm_tis_core.h tpm: Move platform specific definitions to the new PTP header 2026-08-25 18:13:35 +03:00
tpm_tis_i2c.c tpm: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-09-17 18:56:37 +03:00
tpm_tis_i2c_cr50.c tpm: Remove redundant dev_err() 2026-08-25 18:13:34 +03:00
tpm_tis_spi.h tpm: tpm_tis_spi: fix nodef CR50 tpm_tis_spi_resume is null 2026-08-25 18:13:34 +03:00
tpm_tis_spi_cr50.c char: tpm: cr50: Remove IRQF_ONESHOT 2026-02-01 17:37:15 +01:00
tpm_tis_spi_main.c tpm_tis_spi: add missing attpm20p SPI device ID entry 2024-07-01 15:50:02 +00:00
tpm_tis_synquacer.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
tpm_vtpm_proxy.c tpm-buf: Memory-safe allocations 2026-08-25 18:13:36 +03:00
tpmrm-dev.c tpm: Make the TPM character devices non-seekable 2026-07-12 12:52:34 -07:00
xen-tpmfront.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00