* [PATCH] tpm: End any active auth session before shutdown
@ 2025-03-07 12:25 Jonathan McDowell
2025-03-19 14:37 ` Jonathan McDowell
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan McDowell @ 2025-03-07 12:25 UTC (permalink / raw)
To: Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe, James Bottomley
Cc: linux-integrity, linux-kernel
From: Jonathan McDowell <noodles@meta.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@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
root@debian-qemu-efi:~# kexec --load --kexec-file-syscall …
root@debian-qemu-efi:~# systemctl kexec
…
root@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
- 0x2000000
root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
root@debian-qemu-efi:~#
(repeat kexec steps)
root@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
- 0x2000000
- 0x2000001
root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
root@debian-qemu-efi:~#
After:
root@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
root@debian-qemu-efi:~# kexec --load --kexec-file-syscall …
root@debian-qemu-efi:~# systemctl kexec
…
root@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
root@debian-qemu-efi:~#
Signed-off-by: Jonathan McDowell <noodles@meta.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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tpm: End any active auth session before shutdown
2025-03-07 12:25 [PATCH] tpm: End any active auth session before shutdown Jonathan McDowell
@ 2025-03-19 14:37 ` Jonathan McDowell
2025-03-20 16:21 ` Jarkko Sakkinen
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan McDowell @ 2025-03-19 14:37 UTC (permalink / raw)
To: Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe, James Bottomley
Cc: linux-integrity, linux-kernel
Gentle poke about this patch, which I haven't seen any feedback for.
It's causing us a problem in terms of having a string of kexecs result
in the kernel no longer being able to talk to the TPM with an HMAC
session, and the rng random data fetches from the TPM then failing.
On Fri, Mar 07, 2025 at 12:25:23PM +0000, Jonathan McDowell wrote:
>From: Jonathan McDowell <noodles@meta.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@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
>root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
>root@debian-qemu-efi:~# kexec --load --kexec-file-syscall …
>root@debian-qemu-efi:~# systemctl kexec
>…
>root@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
>- 0x2000000
>root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
>root@debian-qemu-efi:~#
>(repeat kexec steps)
>root@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
>- 0x2000000
>- 0x2000001
>root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
>root@debian-qemu-efi:~#
>
>After:
>
>root@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
>root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
>root@debian-qemu-efi:~# kexec --load --kexec-file-syscall …
>root@debian-qemu-efi:~# systemctl kexec
>…
>root@debian-qemu-efi:~# tpm2_getcap handles-loaded-session
>root@debian-qemu-efi:~# tpm2_getcap handles-saved-session
>root@debian-qemu-efi:~#
>
>Signed-off-by: Jonathan McDowell <noodles@meta.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
>
>
J.
--
I've got a trigger inside.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tpm: End any active auth session before shutdown
2025-03-19 14:37 ` Jonathan McDowell
@ 2025-03-20 16:21 ` Jarkko Sakkinen
0 siblings, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2025-03-20 16:21 UTC (permalink / raw)
To: Jonathan McDowell
Cc: Peter Huewe, Jason Gunthorpe, James Bottomley, linux-integrity,
linux-kernel
On Wed, Mar 19, 2025 at 02:37:28PM +0000, Jonathan McDowell wrote:
> Gentle poke about this patch, which I haven't seen any feedback for. It's
> causing us a problem in terms of having a string of kexecs result in the
> kernel no longer being able to talk to the TPM with an HMAC session, and the
> rng random data fetches from the TPM then failing.
Sorry, this was unintentional!
I applied the patch to my master branch now.
BR, Jarkko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-20 16:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-07 12:25 [PATCH] tpm: End any active auth session before shutdown Jonathan McDowell
2025-03-19 14:37 ` Jonathan McDowell
2025-03-20 16:21 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).