From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Antoine Tenart <atenart@kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Aleksander Jan Bajkowski <olek2@wp.pl>,
Pascal van Leeuwen <pvanleeuwen@insidesecure.com>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 07/10] crypto: safexcel - Check scatterlist errors before max() for in-place
Date: Mon, 23 Nov 2026 15:09:58 +0000 [thread overview]
Message-ID: <20261123151055.2533735-8-lee@kernel.org> (raw)
In-Reply-To: <20261123151055.2533735-1-lee@kernel.org>
In safexcel_send_req(), sg_nents_for_len() returns -EINVAL when a
scatterlist is shorter than the required payload length. For in-place
requests (src == dst), the driver combines sreq->nr_src and
sreq->nr_dst using max() before checking for errors.
When an in-place AEAD encryption request provides a scatterlist large
enough for totlen_src (sreq->nr_src > 0) but too short for the
appended authentication tag in totlen_dst (sreq->nr_dst == -EINVAL),
max() selects the positive sreq->nr_src and discards -EINVAL. The
driver then maps only the undersized buffer while programming the
engine token to emit totlen_dst bytes.
Check both sreq->nr_src and sreq->nr_dst for negative error values
before combining them with max().
Fixes: 19b347b32bb1 ("crypto: inside-secure - fix scatter/gather list to descriptor conversion")
Closes: https://sashiko.dev/#/bug/linux-78f87af5-af5e-439c-bb52-de4c8c53fdee
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/inside-secure/safexcel_cipher.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c
index b031cb9652ec..e7816f6ddeaa 100644
--- a/drivers/crypto/inside-secure/safexcel_cipher.c
+++ b/drivers/crypto/inside-secure/safexcel_cipher.c
@@ -736,14 +736,13 @@ static int safexcel_send_req(struct crypto_async_request *base, int ring,
queued = totlen_src;
if (src == dst) {
- sreq->nr_src = max(sreq->nr_src, sreq->nr_dst);
- sreq->nr_dst = sreq->nr_src;
- if (unlikely((totlen_src || totlen_dst) &&
- (sreq->nr_src <= 0))) {
+ if (unlikely(sreq->nr_src < 0 || sreq->nr_dst < 0)) {
dev_err(priv->dev, "In-place buffer not large enough (need %d bytes)!",
max(totlen_src, totlen_dst));
return -EINVAL;
}
+ sreq->nr_src = max(sreq->nr_src, sreq->nr_dst);
+ sreq->nr_dst = sreq->nr_src;
if (sreq->nr_src > 0 &&
!dma_map_sg(priv->dev, src, sreq->nr_src, DMA_BIDIRECTIONAL))
return -EIO;
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 15:11 UTC|newest]
Thread overview: 11+ 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: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:09 ` Lee Jones [this message]
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=20261123151055.2533735-8-lee@kernel.org \
--to=lee@kernel.org \
--cc=atenart@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olek2@wp.pl \
--cc=pvanleeuwen@insidesecure.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®