Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: Srujana Challa <schalla@marvell.com>,
	Bharat Bhushan <bbhushan2@marvell.com>,
	"David S. Miller" <davem@davemloft.net>,
	Rosen Penev <rosenp@gmail.com>,
	Arnaud Ebalard <arno@natisbad.org>,
	Boris Brezillon <bbrezillon@kernel.org>,
	Russell King <rmk+kernel@arm.linux.org.uk>,
	Romain Perier <romain.perier@free-electrons.com>,
	stable@vger.kernel.org
Subject: [PATCH 7/8] crypto: cesa - do not step empty hash operations on the non-TDMA path
Date: Fri, 27 Nov 2026 20:40:49 -0800	[thread overview]
Message-ID: <20261128044050.722617-8-rosenp@gmail.com> (raw)
In-Reply-To: <20261128044050.722617-1-rosenp@gmail.com>

On engines without TDMA (Orion), mv_cesa_ahash_std_step() trims each
step of a non-final update to whole blocks and leaves the partial tail
for the next request. mv_cesa_ahash_std_process() asks for another step
as long as source bytes are left, so when an update fills its last
SRAM-sized step exactly and fewer than a block's worth of bytes remain,
it steps once more: that step trims its data to nothing and starts a
zero-length MAC operation, which corrupts the hash state. Multi-part
hashes whose update ends that way are wrong, one-shot digests are not
affected.

Once less than a block is left on a non-final request, complete it and
leave the remaining bytes to the cache, as for the last step.

Fixes: f63601fd616a ("crypto: marvell/cesa - add a new driver for Marvell's CESA")
Cc: stable@vger.kernel.org
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/crypto/marvell/cesa/hash.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index 6fcd78427b71..b51315cd01df 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -297,10 +297,23 @@ static int mv_cesa_ahash_std_process(struct ahash_request *req, u32 status)
 {
 	struct mv_cesa_ahash_req *creq = ahash_request_ctx(req);
 	struct mv_cesa_ahash_std_req *sreq = &creq->req.std;
+	unsigned int left;
 
-	if (sreq->offset < (req->nbytes - creq->cache_ptr))
+	if (creq->last_req) {
+		if (sreq->offset < (req->nbytes - creq->cache_ptr))
+			return -EINPROGRESS;
+		return 0;
+	}
+
+	/*
+	 * Less than a block left: keep it in the cache for the next request
+	 * rather than stepping a zero-length operation.
+	 */
+	left = req->nbytes - sreq->offset;
+	if (left >= CESA_MAX_HASH_BLOCK_SIZE)
 		return -EINPROGRESS;
 
+	creq->cache_ptr = left;
 	return 0;
 }
 
-- 
2.56.1


  parent reply	other threads:[~2026-11-28  4:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261128044050.722617-1-rosenp@gmail.com>
2026-11-28  4:40 ` [PATCH 1/8] crypto: cesa - clear the IRQ affinity hint before freeing the IRQ Rosen Penev
2026-11-28  4:40 ` [PATCH 2/8] crypto: cesa - do not allow unbinding the device Rosen Penev
2026-11-28  4:40 ` [PATCH 3/8] crypto: cesa - hash the last full SRAM chunk before the padding Rosen Penev
2026-11-28  4:40 ` [PATCH 4/8] crypto: cesa - finish the HMAC outer hash when padding by hand Rosen Penev
2026-11-28  4:40 ` [PATCH 5/8] crypto: cesa - keep the chained IV on the non-TDMA cipher path Rosen Penev
2026-11-28  4:40 ` [PATCH 6/8] crypto: cesa - put the non-TDMA hash padding behind the data Rosen Penev
2026-11-28  4:40 ` Rosen Penev [this message]
2026-11-28  4:40 ` [PATCH 8/8] crypto: cesa - finish long hashes on the non-TDMA path Rosen Penev

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=20261128044050.722617-8-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=arno@natisbad.org \
    --cc=bbhushan2@marvell.com \
    --cc=bbrezillon@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=romain.perier@free-electrons.com \
    --cc=schalla@marvell.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