[2/4] crypto: caam - fix use-after-free KASAN issue for AEAD algorithms
diff mbox series

Message ID 1586087411-8505-3-git-send-email-iuliana.prodan@nxp.com
State New
Headers show
Series
  • crypto: caam - fix use-after-free KASAN issue
Related show

Commit Message

Iuliana Prodan April 5, 2020, 11:50 a.m. UTC
Here's the KASAN report:
BUG: KASAN: use-after-free in aead_crypt_done+0x60/0xd8
Read of size 1 at addr ffff00002303f014 by task swapper/0/0

CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.6.0-rc1-00163-gd88dd5c-dirty #18
Hardware name: LS1046A RDB Board (DT)
Call trace:
 dump_backtrace+0x0/0x260
 show_stack+0x14/0x20
 dump_stack+0xe8/0x144
 print_address_description.isra.11+0x64/0x348
 __kasan_report+0x11c/0x230
 kasan_report+0xc/0x18
 __asan_load1+0x5c/0x68
 aead_crypt_done+0x60/0xd8
 caam_jr_dequeue+0x390/0x608
...

Fixes: 1c2402266713 ("crypto: caam - add crypto_engine support for AEAD algorithms")
Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
---
 drivers/crypto/caam/caamalg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Horia Geantă April 6, 2020, 11:04 a.m. UTC | #1
On 4/5/2020 2:50 PM, Iuliana Prodan wrote:
> Here's the KASAN report:
> BUG: KASAN: use-after-free in aead_crypt_done+0x60/0xd8
> Read of size 1 at addr ffff00002303f014 by task swapper/0/0
> 
> CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.6.0-rc1-00163-gd88dd5c-dirty #18
This is no a public SHA1, you are probably running with patch 1/4
applied in the tree (and with a "dirty tree").

> Hardware name: LS1046A RDB Board (DT)
> Call trace:
>  dump_backtrace+0x0/0x260
>  show_stack+0x14/0x20
>  dump_stack+0xe8/0x144
>  print_address_description.isra.11+0x64/0x348
>  __kasan_report+0x11c/0x230
>  kasan_report+0xc/0x18
>  __asan_load1+0x5c/0x68
>  aead_crypt_done+0x60/0xd8
>  caam_jr_dequeue+0x390/0x608
> ...
You should provide full KASan log - shawdow bits etc.

> @@ -973,8 +973,6 @@ static void aead_crypt_done(struct device *jrdev, u32 *desc, u32 err,
>  
>  	aead_unmap(jrdev, edesc, req);
>  
> -	kfree(edesc);
> -
>  	/*
>  	 * If no backlog flag, the completion of the request is done
>  	 * by CAAM, not crypto engine.
> @@ -983,6 +981,8 @@ static void aead_crypt_done(struct device *jrdev, u32 *desc, u32 err,
>  		aead_request_complete(req, ecode);
>  	else
>  		crypto_finalize_aead_request(jrp->engine, req, ecode);
> +
> +	kfree(edesc);
I think it's better freeing all resources before calling
the completion callback, to avoid unnecessary memory strains.

Horia

Patch
diff mbox series

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 5538539..6d746ef 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -973,8 +973,6 @@  static void aead_crypt_done(struct device *jrdev, u32 *desc, u32 err,
 
 	aead_unmap(jrdev, edesc, req);
 
-	kfree(edesc);
-
 	/*
 	 * If no backlog flag, the completion of the request is done
 	 * by CAAM, not crypto engine.
@@ -983,6 +981,8 @@  static void aead_crypt_done(struct device *jrdev, u32 *desc, u32 err,
 		aead_request_complete(req, ecode);
 	else
 		crypto_finalize_aead_request(jrp->engine, req, ecode);
+
+	kfree(edesc);
 }
 
 static void skcipher_crypt_done(struct device *jrdev, u32 *desc, u32 err,