crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx
Subsystems (4)
PATCH 1/2 crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx
The bounce buffers are allocated with __get_free_pages() using BOUNCE_BUFFER_ORDER (order 2 = 4 pages), but both the allocation error path and nx842_crypto_free_ctx() release the buffers with free_page(). Use free_pages() with the matching order instead.
--- drivers/crypto/nx/nx-842.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/nx/nx-842.c +4 -4
@@ -116,8 +116,8 @@ void *nx842_crypto_alloc_ctx(struct nx842_driver *driver) ctx->dbounce = (u8 *)__get_free_pages (GFP_KERNEL ,BOUNCE_BUFFER_ORDER );if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {kfree (ctx->wmem); -free_page ((unsigned long )ctx->sbounce); -free_page ((unsigned long )ctx->dbounce); +free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); +free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER );kfree (ctx);return ERR_PTR (-ENOMEM ); }
@@ -131,8 +131,8 @@ void nx842_crypto_free_ctx(void *p)struct nx842_crypto_ctx *ctx = p;kfree (ctx->wmem); -free_page ((unsigned long )ctx->sbounce); -free_page ((unsigned long )ctx->dbounce); +free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); +free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER ); }EXPORT_SYMBOL_GPL (nx842_crypto_free_ctx);
PATCH 2/2 crypto: nx - fix context leak in nx842_crypto_free_ctx
Since the scomp conversion, nx842_crypto_alloc_ctx() allocates the context separately, but nx842_crypto_free_ctx() never releases it. Add the missing kfree(ctx) to nx842_crypto_free_ctx(), and reuse nx842_crypto_free_ctx() in the allocation error path.
--- drivers/crypto/nx/nx-842.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/crypto/nx/nx-842.c +2 -4
@@ -115,10 +115,7 @@ void *nx842_crypto_alloc_ctx(struct nx842_driver *driver) ctx->sbounce = (u8 *)__get_free_pages (GFP_KERNEL ,BOUNCE_BUFFER_ORDER ); ctx->dbounce = (u8 *)__get_free_pages (GFP_KERNEL ,BOUNCE_BUFFER_ORDER );if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) { -kfree (ctx->wmem); -free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); -free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER ); -kfree (ctx); +nx842_crypto_free_ctx (ctx);return ERR_PTR (-ENOMEM ); }
@@ -133,6 +130,7 @@ void nx842_crypto_free_ctx(void *p)kfree (ctx->wmem);free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER );free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER ); +kfree (ctx); }EXPORT_SYMBOL_GPL (nx842_crypto_free_ctx);
Re: [PATCH 2/2] crypto: nx - fix context leak in nx842_crypto_free_ctx
Quoted 5 lines · Thorsten Blum
Since the scomp conversion,
nx842_crypto_alloc_ctx()allocates the context separately, butnx842_crypto_free_ctx()never releases it. Add the missing kfree(ctx) tonx842_crypto_free_ctx(), and reusenx842_crypto_free_ctx()in the allocation error path.
Quoted 7 lines
Fixes 980b5705f4e7 ("crypto: nx - Migrate to scomp API")Signed-off-by Thorsten Blum <[email protected]>--- drivers/crypto/nx/nx-842.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Quoted 23 lines
drivers/crypto/nx/nx-842.c +2
-4@@ -115,10 +115,7 @@ void *nx842_crypto_alloc_ctx(struct nx842_driver *driver) ctx->sbounce = (u8 *)__get_free_pages (GFP_KERNEL ,BOUNCE_BUFFER_ORDER ); ctx->dbounce = (u8 *)__get_free_pages (GFP_KERNEL ,BOUNCE_BUFFER_ORDER );if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) { -kfree (ctx->wmem); -free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER ); -free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER ); -kfree (ctx); +nx842_crypto_free_ctx (ctx);return ERR_PTR (-ENOMEM ); }@@ -133,6 +130,7 @@ void nx842_crypto_free_ctx(void *p)kfree (ctx->wmem);free_pages ((unsigned long )ctx->sbounce,BOUNCE_BUFFER_ORDER );free_pages ((unsigned long )ctx->dbounce,BOUNCE_BUFFER_ORDER ); +kfree (ctx); }EXPORT_SYMBOL_GPL (nx842_crypto_free_ctx);
Herbert Xu
maintainerQuoted 11 lines · Thorsten Blum
The bounce buffers are allocated with
__get_free_pages()usingBOUNCE_BUFFER_ORDER(order 2 = 4 pages), but both the allocation error path andnx842_crypto_free_ctx()release the buffers withfree_page(). Usefree_pages()with the matching order instead.Fixes ed70b479c2c0 ("crypto: nx - add hardware 842 crypto comp alg")Signed-off-by Thorsten Blum <[email protected]>--- drivers/crypto/nx/nx-842.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
All 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