Skip to contentSkip to conversation

tpm: Use kfree_sensitive() to free auth session in tpm_dev_release()

PATCH Applied Gunnar Kudrjavets 2 participants 2 messages Apr 9 – Apr 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: Use kfree_sensitive() to free auth session in tpm_dev_release()

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.

Fixes 699e3efd6c64 ("tpm: Add HMAC session start and end functions")
---
 drivers/char/tpm/tpm-chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +1 -1
index 082b910ddf0d..17d9d71774ec 100644
@@ -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);
 }

base-commit: 03e5553f5fb99cb47c315e167a604a9c69e6f724

Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 1/1 Applied
#1 lore raw
Quoted 34 lines · Gunnar Kudrjavets

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.

Fixes 699e3efd6c64 ("tpm: Add HMAC session start and end functions")
---
 drivers/char/tpm/tpm-chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +1 -1
index 082b910ddf0d..17d9d71774ec 100644
@@ -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);
 }
Quoted 4 lines

base-commit: 03e5553f5fb99cb47c315e167a604a9c69e6f724

Signature · 1 line
2.47.3

Applied.

BR, Jarkko