[PATCH 07/10] crypto: safexcel - Check scatterlist errors before max() for in-place
From: Lee Jones
Date: Mon Nov 23 2026 - 10:13:18 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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