public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx
@ 2026-03-11 15:56 Thorsten Blum
  2026-03-11 15:56 ` [PATCH 2/2] crypto: nx - fix context leak in nx842_crypto_free_ctx Thorsten Blum
  2026-03-21  8:49 ` [PATCH 1/2] crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx Herbert Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-03-11 15:56 UTC (permalink / raw)
  To: Haren Myneni, Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy (CS GROUP), Herbert Xu,
	David S. Miller, Dan Streetman
  Cc: Thorsten Blum, stable, linuxppc-dev, linux-crypto, linux-kernel

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.

Fixes: ed70b479c2c0 ("crypto: nx - add hardware 842 crypto comp alg")
Cc: stable@vger.kernel.org
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/crypto/nx/nx-842.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index b61f2545e165..661568ce47f0 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -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);
 

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

* [PATCH 2/2] crypto: nx - fix context leak in nx842_crypto_free_ctx
  2026-03-11 15:56 [PATCH 1/2] crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx Thorsten Blum
@ 2026-03-11 15:56 ` Thorsten Blum
  2026-03-12  8:24   ` Ard Biesheuvel
  2026-03-21  8:49 ` [PATCH 1/2] crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx Herbert Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-03-11 15:56 UTC (permalink / raw)
  To: Haren Myneni, Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy (CS GROUP), Herbert Xu,
	David S. Miller, Ard Biesheuvel
  Cc: Thorsten Blum, stable, linuxppc-dev, linux-crypto, linux-kernel

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.

Fixes: 980b5705f4e7 ("crypto: nx - Migrate to scomp API")
Cc: stable@vger.kernel.org
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/crypto/nx/nx-842.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index 661568ce47f0..a61208cbcd27 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -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);
 

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

* Re: [PATCH 2/2] crypto: nx - fix context leak in nx842_crypto_free_ctx
  2026-03-11 15:56 ` [PATCH 2/2] crypto: nx - fix context leak in nx842_crypto_free_ctx Thorsten Blum
@ 2026-03-12  8:24   ` Ard Biesheuvel
  0 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-03-12  8:24 UTC (permalink / raw)
  To: Thorsten Blum, Haren Myneni, Madhavan Srinivasan,
	Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
	Herbert Xu, David S. Miller
  Cc: stable, linuxppc-dev, linux-crypto, linux-kernel



On Wed, 11 Mar 2026, at 16:56, Thorsten Blum wrote:
> 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.
>
> Fixes: 980b5705f4e7 ("crypto: nx - Migrate to scomp API")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/crypto/nx/nx-842.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

> diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
> index 661568ce47f0..a61208cbcd27 100644
> --- a/drivers/crypto/nx/nx-842.c
> +++ b/drivers/crypto/nx/nx-842.c
> @@ -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);

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

* Re: [PATCH 1/2] crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx
  2026-03-11 15:56 [PATCH 1/2] crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx Thorsten Blum
  2026-03-11 15:56 ` [PATCH 2/2] crypto: nx - fix context leak in nx842_crypto_free_ctx Thorsten Blum
@ 2026-03-21  8:49 ` Herbert Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2026-03-21  8:49 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Haren Myneni, Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy (CS GROUP), David S. Miller,
	Dan Streetman, stable, linuxppc-dev, linux-crypto, linux-kernel

On Wed, Mar 11, 2026 at 04:56:47PM +0100, Thorsten Blum wrote:
> 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.
> 
> Fixes: ed70b479c2c0 ("crypto: nx - add hardware 842 crypto comp alg")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/crypto/nx/nx-842.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2026-03-21  8:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 15:56 [PATCH 1/2] crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx Thorsten Blum
2026-03-11 15:56 ` [PATCH 2/2] crypto: nx - fix context leak in nx842_crypto_free_ctx Thorsten Blum
2026-03-12  8:24   ` Ard Biesheuvel
2026-03-21  8:49 ` [PATCH 1/2] crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox