[<prev] [next>] [day] [month] [year] [list]
Message-ID: <Z8rls0QkzOliECp_@earth.li>
Date: Fri, 7 Mar 2025 12:25:23 +0000
From: Jonathan McDowell <noodles@...th.li>
To: Peter Huewe <peterhuewe@....de>, Jarkko Sakkinen <jarkko@...nel.org>,
Jason Gunthorpe <jgg@...pe.ca>,
James Bottomley <James.Bottomley@...senpartnership.com>
Cc: linux-integrity@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] tpm: End any active auth session before shutdown
From: Jonathan McDowell <noodles@...a.com>
Lazy flushing of TPM auth sessions can interact badly with IMA + kexec,
resulting in loaded session handles being leaked across the kexec and
not cleaned up. Fix by ensuring any active auth session is ended before
the TPM is told about the shutdown, matching what is done when
suspending.
Before:
root@...ian-qemu-efi:~# tpm2_getcap handles-loaded-session
root@...ian-qemu-efi:~# tpm2_getcap handles-saved-session
root@...ian-qemu-efi:~# kexec --load --kexec-file-syscall …
root@...ian-qemu-efi:~# systemctl kexec
…
root@...ian-qemu-efi:~# tpm2_getcap handles-loaded-session
- 0x2000000
root@...ian-qemu-efi:~# tpm2_getcap handles-saved-session
root@...ian-qemu-efi:~#
(repeat kexec steps)
root@...ian-qemu-efi:~# tpm2_getcap handles-loaded-session
- 0x2000000
- 0x2000001
root@...ian-qemu-efi:~# tpm2_getcap handles-saved-session
root@...ian-qemu-efi:~#
After:
root@...ian-qemu-efi:~# tpm2_getcap handles-loaded-session
root@...ian-qemu-efi:~# tpm2_getcap handles-saved-session
root@...ian-qemu-efi:~# kexec --load --kexec-file-syscall …
root@...ian-qemu-efi:~# systemctl kexec
…
root@...ian-qemu-efi:~# tpm2_getcap handles-loaded-session
root@...ian-qemu-efi:~# tpm2_getcap handles-saved-session
root@...ian-qemu-efi:~#
Signed-off-by: Jonathan McDowell <noodles@...a.com>
---
drivers/char/tpm/tpm-chip.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 7df7abaf3e52..87f01269b9b5 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -300,6 +300,7 @@ int tpm_class_shutdown(struct device *dev)
down_write(&chip->ops_sem);
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
if (!tpm_chip_start(chip)) {
+ tpm2_end_auth_session(chip);
tpm2_shutdown(chip, TPM2_SU_CLEAR);
tpm_chip_stop(chip);
}
--
2.48.1
Powered by blists - more mailing lists