crypto/ccp: Fix use-after-free on error path
Subsystems (3)
PATCH 1/1 crypto/ccp: Fix use-after-free on error path
In the error path of sev_tsm_init_locked(), the code dereferences 't' after it has been freed with kfree(). The pr_err() statement attempts to access t->tio_en and t->tio_init_done after the memory has been released.
Move the pr_err() call before kfree(t) to access the fields while the memory is still valid.
This issue reported by Smatch static analyser
--- drivers/crypto/ccp/sev-dev-tsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev-tsm.c +1 -1
@@ -378,9 +378,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.43.0
Quoted 5 lines · Alper Ak
In the error path of
sev_tsm_init_locked(), the code dereferences 't' after it has been freed withkfree(). Thepr_err()statement attempts to accesst->tio_enandt->tio_init_doneafter the memory has been released.
Quoted 7 lines
Move the
pr_err()call before kfree(t) to access the fields while the memory is still valid.This issue reported by Smatch static analyser
Fixes 4be423572da1 ("crypto/ccp: Implement SEV-TIO PCIe IDE (phase1)")Signed-off-by Alper Ak <[email protected]>
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@@ -378,9 +378,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)
Herbert Xu
maintainerQuoted 8 lines · Alper Ak
In the error path of
sev_tsm_init_locked(), the code dereferences 't' after it has been freed withkfree(). Thepr_err()statement attempts to accesst->tio_enandt->tio_init_doneafter the memory has been released.Move the
pr_err()call before kfree(t) to access the fields while the memory is still valid.
Quoted 7 lines
This issue reported by Smatch static analyser
Fixes 4be423572da1 ("crypto/ccp: Implement SEV-TIO PCIe IDE (phase1)")Signed-off-by Alper Ak <[email protected]>--- drivers/crypto/ccp/sev-dev-tsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt