All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	Thorsten Blum <blum@kernel.org>,
	Nicolas Royer <nicolas@eukrea.com>,
	Tudor Ambarus <tudor.ambarus@linaro.org>,
	linux-crypto@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag
Date: Mon, 23 Nov 2026 15:10:01 +0000	[thread overview]
Message-ID: <20261123151055.2533735-11-lee@kernel.org> (raw)
In-Reply-To: <20261123151055.2533735-1-lee@kernel.org>

In atmel_tdes_finish_req(), dd->flags clears TDES_FLAGS_BUSY without
holding dd->lock and before calling
atmel_tdes_set_iv_as_last_ciphertext_block().

As soon as TDES_FLAGS_BUSY is cleared, a concurrent
atmel_tdes_handle_queue() caller on another CPU can dequeue the next
request and overwrite dd->req (as well as modify dd->flags).  When
atmel_tdes_set_iv_as_last_ciphertext_block() then reads dd->req, it
overwrites the newly dequeued request's IV with the previous request's
ciphertext and leaves the completed request's output IV un-updated.

Update the output IV before clearing TDES_FLAGS_BUSY, and clear
TDES_FLAGS_BUSY under dd->lock to serialise flag updates with
atmel_tdes_handle_queue().

Fixes: 61b0dd664fa1 ("crypto: atmel-tdes - Set the IV after {en,de}crypt")
Closes: https://sashiko.dev/#/bug/linux-d6fd6f42-d6fc-47d0-86d5-f428e2203a64
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/crypto/atmel-tdes.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c
index c86d06169ab9..392a2a3a8b85 100644
--- a/drivers/crypto/atmel-tdes.c
+++ b/drivers/crypto/atmel-tdes.c
@@ -504,14 +504,17 @@ static void atmel_tdes_finish_req(struct atmel_tdes_dev *dd, int err)
 {
 	struct skcipher_request *req = dd->req;
 	struct atmel_tdes_reqctx *rctx = skcipher_request_ctx(req);
+	unsigned long flags;
 
 	clk_disable_unprepare(dd->iclk);
 
-	dd->flags &= ~TDES_FLAGS_BUSY;
-
 	if (!err && (rctx->mode & TDES_FLAGS_OPMODE_MASK) != TDES_FLAGS_ECB)
 		atmel_tdes_set_iv_as_last_ciphertext_block(dd);
 
+	spin_lock_irqsave(&dd->lock, flags);
+	dd->flags &= ~TDES_FLAGS_BUSY;
+	spin_unlock_irqrestore(&dd->lock, flags);
+
 	skcipher_request_complete(req, err);
 }
 
-- 
2.56.1.750.gf70dc682cf-goog


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

Thread overview: 19+ 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-30 10:26   ` Sahil Malhotra
2026-11-30 14:38     ` 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
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-24  7:39   ` liulongfang
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-26 16:47   ` Antoine Tenart
2026-11-23 15:09 ` [PATCH 08/10] crypto: qce - Pass mapped scatterlist count to qce_dma_prep_sgs() Lee Jones
2026-11-24 12:49   ` Bartosz Golaszewski
2026-11-23 15:10 ` [PATCH 09/10] crypto: qce - Terminate RX DMA channel if TX preparation fails Lee Jones
2026-11-24 12:49   ` Bartosz Golaszewski
2026-11-23 15:10 ` Lee Jones [this message]

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-11-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=blum@kernel.org \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=nicolas@eukrea.com \
    --cc=stable@vger.kernel.org \
    --cc=tudor.ambarus@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.