Skip to content

Commit d8695ee

Browse files
tobluxopsiff
authored andcommitted
crypto: nx - fix context leak in nx842_crypto_free_ctx
commit 344e6a4f7ff4756b9b3f75e0eb7eaec297e35540 upstream. 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: 980b570 ("crypto: nx - Migrate to scomp API") Cc: stable@vger.kernel.org Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit b94588f5a69718be2c942f4a851125f655e4e819) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 95bbf40 commit d8695ee

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

drivers/crypto/nx/nx-842.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ void *nx842_crypto_alloc_ctx(struct nx842_driver *driver)
115115
ctx->sbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
116116
ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
117117
if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {
118-
kfree(ctx->wmem);
119-
free_pages((unsigned long)ctx->sbounce, BOUNCE_BUFFER_ORDER);
120-
free_pages((unsigned long)ctx->dbounce, BOUNCE_BUFFER_ORDER);
121-
kfree(ctx);
118+
nx842_crypto_free_ctx(ctx);
122119
return ERR_PTR(-ENOMEM);
123120
}
124121

@@ -133,6 +130,7 @@ void nx842_crypto_free_ctx(void *p)
133130
kfree(ctx->wmem);
134131
free_pages((unsigned long)ctx->sbounce, BOUNCE_BUFFER_ORDER);
135132
free_pages((unsigned long)ctx->dbounce, BOUNCE_BUFFER_ORDER);
133+
kfree(ctx);
136134
}
137135
EXPORT_SYMBOL_GPL(nx842_crypto_free_ctx);
138136

0 commit comments

Comments
 (0)