Linux cryptographic layer development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Jones" <lee@kernel.org>, "Haren Myneni" <haren@us.ibm.com>,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	"Shrikanth Hegde" <sshegde@linux.ibm.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Thorsten Blum" <blum@kernel.org>,
	"Bulent Abali" <abali@us.ibm.com>,
	"Robert Jennings" <rcj@linux.vnet.ibm.com>,
	"Seth Jennings" <sjenning@linux.vnet.ibm.com>,
	"Dan Streetman" <ddstreet@ieee.org>,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH 03/10] crypto: nx - Fix bounce buffer copy overflow in decompress()
Date: Mon, 23 Nov 2026 15:37:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-229585@kernel.org> (raw)
In-Reply-To: <20261123151055.2533735-4-lee@kernel.org>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] crypto: nx: out-of-bounds write in compress() [1]
--

commit 6d00d8097910c1ed1be4ad69177b9d0594c5365b
Author: Lee Jones <lee@kernel.org>

crypto: nx - Fix bounce buffer copy overflow in decompress()

This commit validates that the decompressed length does not exceed the
remaining destination buffer capacity before copying from ctx->dbounce
into p->out in decompress().

> diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
> index b4404a1389621..4f96c2b2397be 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);
> +	}

[Severity: Critical]
This problem wasn't introduced by this patch, but can compress() also
overflow p->out when copying from ctx->dbounce [1]?

When compress() jumps to the nospc fallback to use ctx->dbounce, it sets
dlen to min(p->oremain, BOUNCE_BUFFER_SIZE) and dskip to 0 without
subtracting hdrsize:

drivers/crypto/nx/nx-842.c:compress() {
	...
	if (dlen < c->minimum) {
nospc:
		dst = ctx->dbounce;
		dlen = min(p->oremain, BOUNCE_BUFFER_SIZE);
		dlen = round_down(dlen, c->multiple);
		dskip = 0;
		pr_debug("using comp dbounce buffer, len %x\n", dlen);
	}
	...
	dskip += hdrsize;

	if (dst == ctx->dbounce)
		memcpy(p->out + dskip, dst, dlen);
	...
}

After compression completes, dskip is incremented by hdrsize and dlen
bytes are copied to p->out + dskip.  If the compressed output reaches the
dlen limit, hdrsize + dlen exceeds p->oremain and memcpy() writes up to
hdrsize bytes past the end of p->out before update_param() checks the
remaining space.

[1] https://sashiko.dev/#/bug/linux-f0b43673-8815-4f13-a7d9-658940af36b2

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123151055.2533735-1-lee@kernel.org?part=3

  reply	other threads:[~2026-11-23 15:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 15:09 [PATCH 00/10] crypto: Assorted bug fixes across crypto drivers Lee Jones
2026-11-23 15:09 ` [PATCH 01/10] crypto: caam - Fix descriptor buffer overflow in caam_process_blob() Lee Jones
2026-11-23 15:09 ` [PATCH 02/10] crypto: marvell - Fix AEAD key buffer overflow for SHA-384/512 HMAC Lee Jones
2026-11-23 15:09 ` [PATCH 03/10] crypto: nx - Fix bounce buffer copy overflow in decompress() Lee Jones
2026-11-23 15:37   ` sashiko-bot [this message]
2026-11-23 15:09 ` [PATCH 04/10] crypto: sun8i-ss - Fix scatterlist array overflow for HMAC requests Lee Jones
2026-11-23 15:09 ` [PATCH 05/10] crypto: hisilicon/hpre - Fix buffer overflow on odd ECDH input size Lee Jones
2026-11-23 15:09 ` [PATCH 06/10] crypto: talitos - Remove duplicate IV unmap in AEAD encrypt path Lee Jones
2026-11-23 15:19   ` sashiko-bot
2026-11-23 15:09 ` [PATCH 07/10] crypto: safexcel - Check scatterlist errors before max() for in-place Lee Jones
2026-11-23 15:09 ` [PATCH 08/10] crypto: qce - Pass mapped scatterlist count to qce_dma_prep_sgs() Lee Jones
2026-11-23 15:10 ` [PATCH 09/10] crypto: qce - Terminate RX DMA channel if TX preparation fails Lee Jones
2026-11-23 15:10 ` [PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-229585@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=abali@us.ibm.com \
    --cc=blum@kernel.org \
    --cc=chleroy@kernel.org \
    --cc=davem@davemloft.net \
    --cc=ddstreet@ieee.org \
    --cc=haren@us.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=lee@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=rcj@linux.vnet.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sjenning@linux.vnet.ibm.com \
    --cc=sshegde@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox