[PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag

Lee Jones lee at kernel.org
Mon Nov 23 07:10:01 PST 2026


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 at vger.kernel.org
Signed-off-by: Lee Jones <lee at 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




More information about the linux-arm-kernel mailing list