linux/drivers/char
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>
2026-09-29 22:15:21 +03:00
..
agp agp/amd-k7: Don't rely on address of pci_device_id 2026-07-28 11:18:24 -05:00
hw_random This update includes the following changes: 2026-08-19 17:25:42 -07:00
ipmi ipmi: Fix use-after-free of cmd_rcvr in _ipmi_destroy_user() 2026-08-25 18:55:02 -05:00
tpm tpm: Disable TPM on null key name mismatch 2026-09-29 22:15:21 +03:00
xilinx_hwicap char: xilinx_hwicap: unregister class on init errors 2026-07-17 16:22:57 +02:00
xillybus char: xillybus: Remove redundant dev_err() 2026-07-17 16:23:18 +02:00
adi.c char/adi: Use min_t(size_t,,) in adi_read() + adi_write() 2025-10-22 07:53:49 +02:00
apm-emulation.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
bsr.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ds1620.c
dsp56k.c
hangcheck-timer.c hangcheck-timer: fix coding style spacing 2025-11-26 15:11:15 +01:00
hpet.c hpet: Check ACPI_COMPANION() against NULL at probe time 2026-05-23 13:47:34 +02:00
Kconfig char: applicom: remove low-quality, unused driver 2026-05-23 13:47:34 +02:00
lp.c
Makefile char: applicom: remove low-quality, unused driver 2026-05-23 13:47:34 +02:00
mem.c mm/vma: eliminate mmap_action->error_hook, introduce error_override 2026-06-04 14:45:00 -07:00
misc_minor_kunit.c initramfs_test: use test init/exit hooks to override init fs 2026-07-31 12:56:51 +02:00
misc.c char: Use list_del_init() in misc_deregister() to reinitialize list pointer 2025-09-06 19:43:18 +02:00
nsc_gpio.c char: remove unnecessary module_init/exit functions 2026-04-02 17:05:53 +02:00
nvram.c char/nvram: Remove redundant nvram_mutex 2026-05-23 13:47:34 +02:00
nwbutton.c
nwbutton.h
nwflash.c
pc8736x_gpio.c
powernv-op-panel.c char: powernv-op-panel: remove unnecessary reset of position pointer 2026-07-17 15:53:21 +02:00
ppdev.c ppdev: prevent overflow when setting port timeout 2026-07-17 15:53:18 +02:00
ps3flash.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
random.c random: vDSO: Remove ifdeffery 2026-03-11 15:22:49 +01:00
scx200_gpio.c
sonypi.c sonypi: Stop setting acpi_device_name/class() 2026-07-09 16:44:07 +03:00
tlclk.c tlclk: if sscanf() fails, fall back to 0, not random value 2026-07-17 14:53:45 +02:00
toshiba.c
ttyprintk.c
uv_mmtimer.c
virtio_console.c virtio_console: do not free control-out buffers on remove 2026-09-07 18:54:02 -04:00