[PATCH 03/10] crypto: nx - Fix bounce buffer copy overflow in decompress()

From: Lee Jones

Date: Mon Nov 23 2026 - 10:11:34 EST


When decompress() falls back to software 842 decompression and the
remaining destination capacity p->oremain is smaller than required_len,
it redirects decompression into the bounce buffer ctx->dbounce with
dlen set to BOUNCE_BUFFER_SIZE.

After sw842_decompress() completes and ignore bytes are subtracted,
decompress() copies dlen bytes from ctx->dbounce into p->out via
memcpy() before update_param() validates that dlen does not exceed
p->oremain. A crafted compressed stream whose decompressed output
exceeds p->oremain therefore overflows the caller's destination buffer
by up to BOUNCE_BUFFER_SIZE bytes.

Validate that dlen does not exceed p->oremain and return -ENOSPC before
copying out of ctx->dbounce.

Fixes: ed70b479c2c0 ("crypto: nx - add hardware 842 crypto comp alg")
Closes: https://sashiko.dev/#/bug/linux-7309787b-8efe-4919-bb31-c4d9eceb9c0f
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/crypto/nx/nx-842.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index b4404a138962..4f96c2b2397b 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -427,8 +427,11 @@ static int decompress(struct nx842_crypto_ctx *ctx,
if (ignore)
pr_debug("ignoring last %x bytes\n", ignore);

- if (dst == ctx->dbounce)
+ if (dst == ctx->dbounce) {
+ if (dlen > p->oremain)
+ return -ENOSPC;
memcpy(p->out, dst, dlen);
+ }

pr_debug("decompress slen %x padding %x dlen %x ignore %x\n",
slen, padding, dlen, ignore);
--
2.56.1.750.gf70dc682cf-goog