]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tpm: Use kfree_sensitive() to free auth session in tpm_dev_release()
authorGunnar Kudrjavets <gunnarku@amazon.com>
Thu, 9 Apr 2026 17:20:54 +0000 (17:20 +0000)
committerJarkko Sakkinen <jarkko@kernel.org>
Tue, 21 Apr 2026 15:54:28 +0000 (18:54 +0300)
tpm_dev_release() uses plain kfree() to free chip->auth, which contains
sensitive cryptographic material including HMAC session keys, nonces,
and passphrase data (struct tpm2_auth).

Every other code path that frees this structure uses kfree_sensitive()
to zero the memory before releasing it: both tpm2_end_auth_session()
and tpm_buf_check_hmac_response() do so. The tpm_dev_release() path
is the only one that does not, leaving key material in freed slab
memory until it is eventually overwritten.

Use kfree_sensitive() for consistency with the rest of the driver and
to ensure session keys are scrubbed during device teardown.

Cc: stable@vger.kernel.org # v6.10+
Fixes: 699e3efd6c64 ("tpm: Add HMAC session start and end functions")
Signed-off-by: Gunnar Kudrjavets <gunnarku@amazon.com>
Reviewed-by: Justinien Bouron <jbouron@amazon.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
drivers/char/tpm/tpm-chip.c

index 0719577e584dc40ef73b797d4aaf16e1556384db..12b7394b34bdce447af1f809698a9a3ad736c61f 100644 (file)
@@ -247,7 +247,7 @@ static void tpm_dev_release(struct device *dev)
        kfree(chip->work_space.context_buf);
        kfree(chip->work_space.session_buf);
 #ifdef CONFIG_TCG_TPM2_HMAC
-       kfree(chip->auth);
+       kfree_sensitive(chip->auth);
 #endif
        kfree(chip);
 }