Skip to content

Commit 506b5dd

Browse files
tobluxopsiff
authored andcommitted
crypto: nx - fix bounce buffer leaks in nx842_crypto_{alloc,free}_ctx
[ Upstream commit adb3faf2db1a66d0f015b44ac909a32dfc7f2f9c ] 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: ed70b47 ("crypto: nx - add hardware 842 crypto comp alg") Cc: stable@vger.kernel.org Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 6923cde8dc1d501e79b312139819c88b54463803) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent c88e4e1 commit 506b5dd

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/crypto/nx/nx-842.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ void *nx842_crypto_alloc_ctx(struct nx842_driver *driver)
116116
ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
117117
if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {
118118
kfree(ctx->wmem);
119-
free_page((unsigned long)ctx->sbounce);
120-
free_page((unsigned long)ctx->dbounce);
119+
free_pages((unsigned long)ctx->sbounce, BOUNCE_BUFFER_ORDER);
120+
free_pages((unsigned long)ctx->dbounce, BOUNCE_BUFFER_ORDER);
121121
kfree(ctx);
122122
return ERR_PTR(-ENOMEM);
123123
}
@@ -131,8 +131,8 @@ void nx842_crypto_free_ctx(void *p)
131131
struct nx842_crypto_ctx *ctx = p;
132132

133133
kfree(ctx->wmem);
134-
free_page((unsigned long)ctx->sbounce);
135-
free_page((unsigned long)ctx->dbounce);
134+
free_pages((unsigned long)ctx->sbounce, BOUNCE_BUFFER_ORDER);
135+
free_pages((unsigned long)ctx->dbounce, BOUNCE_BUFFER_ORDER);
136136
}
137137
EXPORT_SYMBOL_GPL(nx842_crypto_free_ctx);
138138

0 commit comments

Comments
 (0)