Skip to contentSkip to conversation

crypto/ccp: sev-dev-tsm: fix use after free in sev_tsm_init_locked()

PATCH In review Dan Carpenter 2 participants 2 messages Dec 5, 2025 – Dec 9, 2025

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

PATCH 1/1 crypto/ccp: sev-dev-tsm: fix use after free in sev_tsm_init_locked()

This code frees "t" and then dereferences it on the next line to print the error code. Re-order the code to avoid the use after free.

Fixes 3532f6154971 ("crypto/ccp: Implement SEV-TIO PCIe IDE (phase1)")
---
 drivers/crypto/ccp/sev-dev-tsm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev-tsm.c +1 -1
index ea29cd5d0ff9..06e9f0bc153e 100644
@@ -391,9 +391,9 @@ void sev_tsm_init_locked(struct sev_device *sev, void *tio_status_page)
 	return;
 
 error_exit:
-	kfree(t);
 	pr_err("Failed to enable SEV-TIO: ret=%d en=%d initdone=%d SEV=%d\n",
 	       ret, t->tio_en, t->tio_init_done, boot_cpu_has(X86_FEATURE_SEV));
+	kfree(t);
 }
 
 void sev_tsm_uninit(struct sev_device *sev)
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

This code frees "t" and then dereferences it on the next line to print the error code. Re-order the code to avoid the use after free.

Fixes 3532f6154971 ("crypto/ccp: Implement SEV-TIO PCIe IDE (phase1)")
Quoted 19 lines
---
 drivers/crypto/ccp/sev-dev-tsm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev-tsm.c +1 -1
index ea29cd5d0ff9..06e9f0bc153e 100644
@@ -391,9 +391,9 @@ void sev_tsm_init_locked(struct sev_device *sev, void *tio_status_page)
 	return;
 
 error_exit:
-	kfree(t);
 	pr_err("Failed to enable SEV-TIO: ret=%d en=%d initdone=%d SEV=%d\n",
 	       ret, t->tio_en, t->tio_init_done, boot_cpu_has(X86_FEATURE_SEV));
+	kfree(t);
 }
 
 void sev_tsm_uninit(struct sev_device *sev)