linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH next] crypto/ccp: sev-dev-tsm: fix use after free in sev_tsm_init_locked()
@ 2025-12-05 11:39 Dan Carpenter
  2025-12-09 17:05 ` Tom Lendacky
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2025-12-05 11:39 UTC (permalink / raw)
  To: Alexey Kardashevskiy
  Cc: Ashish Kalra, Tom Lendacky, John Allen, Herbert Xu,
	David S. Miller, Dan Williams, linux-crypto, linux-kernel,
	kernel-janitors

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)")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/crypto/ccp/sev-dev-tsm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/sev-dev-tsm.c b/drivers/crypto/ccp/sev-dev-tsm.c
index ea29cd5d0ff9..06e9f0bc153e 100644
--- a/drivers/crypto/ccp/sev-dev-tsm.c
+++ b/drivers/crypto/ccp/sev-dev-tsm.c
@@ -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)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH next] crypto/ccp: sev-dev-tsm: fix use after free in sev_tsm_init_locked()
  2025-12-05 11:39 [PATCH next] crypto/ccp: sev-dev-tsm: fix use after free in sev_tsm_init_locked() Dan Carpenter
@ 2025-12-09 17:05 ` Tom Lendacky
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Lendacky @ 2025-12-09 17:05 UTC (permalink / raw)
  To: Dan Carpenter, Alexey Kardashevskiy
  Cc: Ashish Kalra, John Allen, Herbert Xu, David S. Miller,
	Dan Williams, linux-crypto, linux-kernel, kernel-janitors

On 12/5/25 05:39, Dan Carpenter wrote:
> 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)")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>  drivers/crypto/ccp/sev-dev-tsm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev-tsm.c b/drivers/crypto/ccp/sev-dev-tsm.c
> index ea29cd5d0ff9..06e9f0bc153e 100644
> --- a/drivers/crypto/ccp/sev-dev-tsm.c
> +++ b/drivers/crypto/ccp/sev-dev-tsm.c
> @@ -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)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-09 17:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-05 11:39 [PATCH next] crypto/ccp: sev-dev-tsm: fix use after free in sev_tsm_init_locked() Dan Carpenter
2025-12-09 17:05 ` Tom Lendacky

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).