* [PATCH 1/8] crypto: cesa - clear the IRQ affinity hint before freeing the IRQ
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
@ 2026-11-28 4:40 ` Rosen Penev
2026-11-28 4:40 ` [PATCH 2/8] crypto: cesa - do not allow unbinding the device Rosen Penev
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rosen Penev @ 2026-11-28 4:40 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Rosen Penev,
Arnaud Ebalard, Boris Brezillon, Russell King, Romain Perier,
stable
Commit 8dc981ba2fad ("crypto: cesa - remove irq_set_affinity_hint")
dropped the calls that cleared the affinity hint on probe failure and
removal, on the grounds that the IRQs are devm managed. devm only calls
free_irq(), which does not clear the hint, and __free_irq() hits its
WARN_ON_ONCE(desc->affinity_hint) when it finds one still set. So
unbinding the device, or a probe that fails after the first engine's
IRQ has been requested, triggers that warning.
Clear the hint from a devm action registered right after the IRQ, so it
runs before devm frees the IRQ. Switch to irq_set_affinity_and_hint(),
which is what the deprecated irq_set_affinity_hint() wraps.
Fixes: 8dc981ba2fad ("crypto: cesa - remove irq_set_affinity_hint")
Cc: stable@vger.kernel.org
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/crypto/marvell/cesa/cesa.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/marvell/cesa/cesa.c b/drivers/crypto/marvell/cesa/cesa.c
index 564b09773507..ac4fe783735b 100644
--- a/drivers/crypto/marvell/cesa/cesa.c
+++ b/drivers/crypto/marvell/cesa/cesa.c
@@ -415,6 +415,13 @@ static void mv_cesa_release_sram(void *data)
cesa->sram_size, DMA_BIDIRECTIONAL, 0);
}
+static void mv_cesa_clear_affinity_hint(void *data)
+{
+ struct mv_cesa_engine *engine = data;
+
+ irq_update_affinity_hint(engine->irq, NULL);
+}
+
static int mv_cesa_probe(struct platform_device *pdev)
{
const struct mv_cesa_caps *caps = &orion_caps;
@@ -519,7 +526,16 @@ static int mv_cesa_probe(struct platform_device *pdev)
/* Set affinity */
cpu = cpumask_local_spread(engine->id, NUMA_NO_NODE);
- irq_set_affinity_hint(irq, get_cpu_mask(cpu));
+ irq_set_affinity_and_hint(irq, get_cpu_mask(cpu));
+
+ /*
+ * free_irq() warns if the hint is still set. Registered after
+ * the IRQ, so devm clears it before the IRQ is freed.
+ */
+ ret = devm_add_action_or_reset(dev, mv_cesa_clear_affinity_hint,
+ engine);
+ if (ret)
+ return ret;
crypto_init_queue(&engine->queue, CESA_CRYPTO_DEFAULT_MAX_QLEN);
atomic_set(&engine->load, 0);
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 2/8] crypto: cesa - do not allow unbinding the device
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
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 ` Rosen Penev
2026-11-28 4:40 ` [PATCH 3/8] crypto: cesa - hash the last full SRAM chunk before the padding Rosen Penev
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rosen Penev @ 2026-11-28 4:40 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Rosen Penev,
Arnaud Ebalard, Boris Brezillon, Russell King, Romain Perier,
stable
The algorithms are static and a transform holds a reference on the
module, not on the device. Unbinding the device through sysfs therefore
leaves every transform allocated earlier in place: crypto_unregister_*()
only stops new lookups and warns about the algorithms still in use,
while the driver drops the device pointer and devm frees the DMA pools,
the SRAM mappings and the engines. The next request on such a transform
then dereferences freed memory, and the algorithms' reference counts
are left inconsistent for a later rebind.
With the bind attributes suppressed, mv_cesa_remove() only runs when
the module is unloaded, which the transforms' module references keep
from happening while any of them exists.
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/cesa.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/crypto/marvell/cesa/cesa.c b/drivers/crypto/marvell/cesa/cesa.c
index ac4fe783735b..6dded0d44373 100644
--- a/drivers/crypto/marvell/cesa/cesa.c
+++ b/drivers/crypto/marvell/cesa/cesa.c
@@ -577,6 +577,7 @@ static struct platform_driver marvell_cesa = {
.driver = {
.name = "marvell-cesa",
.of_match_table = mv_cesa_of_match_table,
+ .suppress_bind_attrs = true,
},
};
module_platform_driver(marvell_cesa);
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 3/8] crypto: cesa - hash the last full SRAM chunk before the padding
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
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 ` Rosen Penev
2026-11-28 4:40 ` [PATCH 4/8] crypto: cesa - finish the HMAC outer hash when padding by hand Rosen Penev
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rosen Penev @ 2026-11-28 4:40 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Rosen Penev,
Arnaud Ebalard, Boris Brezillon, Russell King, Romain Perier,
stable
When a hash is longer than the engine's total length field (0xffff),
mv_cesa_ahash_dma_last_req() pads it by hand. The padding is placed in
SRAM right behind the outstanding data and the two are hashed by one
operation, or, if only part of the padding fits, in two.
If the outstanding data fills the SRAM payload exactly, none of the
padding fits behind it. That case adds no operation for the outstanding
data at all and transfers the padding to the start of the SRAM data
area, overwriting the last payload-sized chunk of the message before it
was hashed. Every message longer than 0xffff bytes whose last chunk ends
exactly at the payload size (1920 bytes with the default 2 KiB SRAM),
for example any one-shot digest of a multiple of 1920 bytes, gets a
wrong digest.
Hash the outstanding data with its own operation first, as was done
before the padding handling was rearranged.
Verified on an Armada 385 (WRT3200ACM) against the software hashes,
with random lengths up to 140000 bytes: about 10 of 40000 SHA1,
SHA256, HMAC-SHA1 and HMAC-SHA256 digests were wrong before, all of
them of that shape, and none of 60000 after.
Fixes: ab270e7055e0 ("crypto: marvell/cesa - rearrange handling for sw padded hashes")
Cc: stable@vger.kernel.org
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/crypto/marvell/cesa/hash.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index d2fe96d865bd..9fd3d5c32312 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -607,6 +607,16 @@ mv_cesa_ahash_dma_last_req(struct mv_cesa_tdma_chain *chain,
return op;
padoff += len;
+ } else if (frag_len) {
+ /*
+ * The outstanding data fills the SRAM payload, so none of the
+ * padding fits behind it. Hash that data on its own before the
+ * padding transfer below overwrites it.
+ */
+ op = mv_cesa_dma_add_frag(chain, &creq->op_tmpl, frag_len,
+ flags);
+ if (IS_ERR(op))
+ return op;
}
ret = mv_cesa_dma_add_data_transfer(chain,
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 4/8] crypto: cesa - finish the HMAC outer hash when padding by hand
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
` (2 preceding siblings ...)
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 ` Rosen Penev
2026-11-28 4:52 ` sashiko-bot
2026-11-28 4:40 ` [PATCH 5/8] crypto: cesa - keep the chained IV on the non-TDMA cipher path Rosen Penev
` (3 subsequent siblings)
7 siblings, 1 reply; 11+ messages in thread
From: Rosen Penev @ 2026-11-28 4:40 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Rosen Penev,
Arnaud Ebalard, Boris Brezillon, Russell King, Romain Perier,
stable
The engine applies the HMAC outer hash only when it finalises the
message itself, i.e. on a last or unfragmented operation that has data
and whose total length fits the descriptor field (0xffff). Otherwise
the driver pads the message by hand and runs the padding as a middle
fragment, which leaves the engine with a plain inner hash state. For
HMAC that is wrong twice over:
- the padding encodes the message length only, while the inner hash
also covers the ipad block, and
- the outer hash is never computed, so the result read back from the
IVDIG registers is H(ipad || m) instead of HMAC(k, m).
This hits every HMAC whose last request has no data left to hash, i.e.
any update()/final() sequence over a block-aligned length and any
finup() or digest() of an empty message, and every HMAC of 64 KiB or
more.
Count the ipad block in the manual padding of HMAC requests, and when
the result comes from the IVDIG registers on the last request of an
HMAC, finish the outer hash in software: import the opad state computed
at setkey time into a software hash, with one block already counted,
and hash the inner digest. Each HMAC transform allocates that software
hash at cra_init(). Select the software hashes so they are always
available.
Verified on an Armada 385 (WRT3200ACM) against the software HMACs,
single threaded with random lengths and update splits: about 0.5% of
HMAC-SHA1 and HMAC-SHA256 digests were wrong before, all of them with a
block-aligned total length, and none of about 195000 after, nor of
30000 more with lengths up to 140000 bytes. HMAC-MD5 was not tested:
the test kernel has no software MD5.
Fixes: db509a45339f ("crypto: marvell/cesa - add TDMA support")
Cc: stable@vger.kernel.org
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/crypto/marvell/Kconfig | 3 +
drivers/crypto/marvell/cesa/cesa.h | 9 +++
drivers/crypto/marvell/cesa/hash.c | 113 +++++++++++++++++++++++++++--
3 files changed, 119 insertions(+), 6 deletions(-)
diff --git a/drivers/crypto/marvell/Kconfig b/drivers/crypto/marvell/Kconfig
index aa269abb0499..965061abec3c 100644
--- a/drivers/crypto/marvell/Kconfig
+++ b/drivers/crypto/marvell/Kconfig
@@ -12,6 +12,9 @@ config CRYPTO_DEV_MARVELL_CESA
select CRYPTO_LIB_DES
select CRYPTO_SKCIPHER
select CRYPTO_HASH
+ select CRYPTO_MD5
+ select CRYPTO_SHA1
+ select CRYPTO_SHA256
select SRAM
select CRYPTO_DEV_MARVELL
help
diff --git a/drivers/crypto/marvell/cesa/cesa.h b/drivers/crypto/marvell/cesa/cesa.h
index 44351b252861..906d55fb6a3a 100644
--- a/drivers/crypto/marvell/cesa/cesa.h
+++ b/drivers/crypto/marvell/cesa/cesa.h
@@ -514,12 +514,15 @@ struct mv_cesa_hash_ctx {
* struct mv_cesa_hash_ctx - CESA hmac operation context
* @base: base context structure
* @iv: initialization vectors
+ * @outer: software hash used to finish the outer hash when the engine
+ * could not finalise the message itself
*
* HMAC context structure.
*/
struct mv_cesa_hmac_ctx {
struct mv_cesa_ctx base;
__be32 iv[16];
+ struct crypto_shash *outer;
};
/**
@@ -609,6 +612,10 @@ struct mv_cesa_ahash_dma_req {
* @src_nents: number of entries in the scatterlist
* @last_req: define whether the current operation is the last one
* or not
+ * @hmac: HMAC request: manual padding must account for the ipad
+ * block and the outer hash is finished in software
+ * @sw_outer: the driver padded the last request by hand, so the
+ * engine did not apply the HMAC outer hash
* @state: hash state
*/
struct mv_cesa_ahash_req {
@@ -624,6 +631,8 @@ struct mv_cesa_ahash_req {
int src_nents;
bool last_req;
bool algo_le;
+ bool hmac;
+ bool sw_outer;
u32 state[8];
};
diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index 9fd3d5c32312..f6894ed7c1cc 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -140,6 +140,14 @@ static int mv_cesa_ahash_pad_len(struct mv_cesa_ahash_req *creq)
static int mv_cesa_ahash_pad_req(struct mv_cesa_ahash_req *creq, u8 *buf)
{
unsigned int padlen;
+ u64 len = creq->len;
+
+ /* The HMAC inner hash also covers the ipad block. */
+ if (creq->hmac)
+ len += CESA_MAX_HASH_BLOCK_SIZE;
+
+ /* The engine will not apply the HMAC outer hash to this. */
+ creq->sw_outer = true;
buf[0] = 0x80;
/* Pad out to 56 mod 64 */
@@ -147,11 +155,11 @@ static int mv_cesa_ahash_pad_req(struct mv_cesa_ahash_req *creq, u8 *buf)
memset(buf + 1, 0, padlen - 1);
if (creq->algo_le) {
- __le64 bits = cpu_to_le64(creq->len << 3);
+ __le64 bits = cpu_to_le64(len << 3);
memcpy(buf + padlen, &bits, sizeof(bits));
} else {
- __be64 bits = cpu_to_be64(creq->len << 3);
+ __be64 bits = cpu_to_be64(len << 3);
memcpy(buf + padlen, &bits, sizeof(bits));
}
@@ -353,6 +361,59 @@ static int mv_cesa_ahash_process(struct crypto_async_request *req, u32 status)
return mv_cesa_ahash_std_process(ahashreq, status);
}
+/*
+ * The engine only applies the HMAC outer hash when it finalises the message
+ * itself. When the driver had to pad by hand instead (no data left for the
+ * last fragment, or a message longer than the engine's total length field),
+ * the IVDIG registers hold the inner digest. Finish the outer hash in
+ * software, starting from the opad state computed at setkey time.
+ */
+static void mv_cesa_ahmac_outer(struct ahash_request *req)
+{
+ struct mv_cesa_hmac_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ unsigned int digsize = crypto_ahash_digestsize(crypto_ahash_reqtfm(req));
+ SHASH_DESC_ON_STACK(desc, ctx->outer);
+ u8 inner[SHA256_DIGEST_SIZE];
+ union {
+ struct md5_state md5;
+ struct sha1_state sha1;
+ struct sha256_state sha256;
+ } st = {};
+ u32 *state;
+ u64 *count;
+ int i, ret;
+
+ switch (digsize) {
+ case MD5_DIGEST_SIZE:
+ state = st.md5.hash;
+ count = &st.md5.byte_count;
+ break;
+ case SHA1_DIGEST_SIZE:
+ state = st.sha1.state;
+ count = &st.sha1.count;
+ break;
+ default:
+ state = st.sha256.state;
+ count = &st.sha256.count;
+ break;
+ }
+
+ for (i = 0; i < digsize / 4; i++)
+ state[i] = be32_to_cpu(ctx->iv[8 + i]);
+ *count = CESA_MAX_HASH_BLOCK_SIZE;
+
+ memcpy(inner, req->result, digsize);
+ desc->tfm = ctx->outer;
+ ret = crypto_shash_import_core(desc, &st);
+ if (!ret)
+ ret = crypto_shash_finup(desc, inner, digsize, req->result);
+ WARN_ON_ONCE(ret);
+
+ shash_desc_zero(desc);
+ memzero_explicit(inner, sizeof(inner));
+ memzero_explicit(&st, sizeof(st));
+}
+
static void mv_cesa_ahash_complete(struct crypto_async_request *req)
{
struct ahash_request *ahashreq = ahash_request_cast(req);
@@ -394,6 +455,9 @@ static void mv_cesa_ahash_complete(struct crypto_async_request *req)
for (i = 0; i < digsize / 4; i++)
result[i] = cpu_to_be32(creq->state[i]);
}
+
+ if (creq->hmac && creq->sw_outer)
+ mv_cesa_ahmac_outer(ahashreq);
}
}
}
@@ -452,6 +516,14 @@ static void mv_cesa_ahash_init(struct ahash_request *req,
creq->op_tmpl = *tmpl;
creq->len = 0;
creq->algo_le = algo_le;
+
+ switch (mv_cesa_get_op_cfg(tmpl) & CESA_SA_DESC_CFG_MACM_MSK) {
+ case CESA_SA_DESC_CFG_MACM_HMAC_MD5:
+ case CESA_SA_DESC_CFG_MACM_HMAC_SHA1:
+ case CESA_SA_DESC_CFG_MACM_HMAC_SHA256:
+ creq->hmac = true;
+ break;
+ }
}
static inline int mv_cesa_ahash_cra_init(struct crypto_tfm *tfm)
@@ -1242,10 +1314,14 @@ static int mv_cesa_ahmac_setkey(const char *hash_alg_name,
return ret;
}
-static int mv_cesa_ahmac_cra_init(struct crypto_tfm *tfm)
+static int mv_cesa_ahmac_cra_init(struct crypto_tfm *tfm, const char *hash)
{
struct mv_cesa_hmac_ctx *ctx = crypto_tfm_ctx(tfm);
+ ctx->outer = crypto_alloc_shash(hash, 0, 0);
+ if (IS_ERR(ctx->outer))
+ return PTR_ERR(ctx->outer);
+
ctx->base.ops = &mv_cesa_ahash_req_ops;
crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
@@ -1253,6 +1329,28 @@ static int mv_cesa_ahmac_cra_init(struct crypto_tfm *tfm)
return 0;
}
+static int mv_cesa_ahmac_md5_cra_init(struct crypto_tfm *tfm)
+{
+ return mv_cesa_ahmac_cra_init(tfm, "md5");
+}
+
+static int mv_cesa_ahmac_sha1_cra_init(struct crypto_tfm *tfm)
+{
+ return mv_cesa_ahmac_cra_init(tfm, "sha1");
+}
+
+static int mv_cesa_ahmac_sha256_cra_init(struct crypto_tfm *tfm)
+{
+ return mv_cesa_ahmac_cra_init(tfm, "sha256");
+}
+
+static void mv_cesa_ahmac_cra_exit(struct crypto_tfm *tfm)
+{
+ struct mv_cesa_hmac_ctx *ctx = crypto_tfm_ctx(tfm);
+
+ crypto_free_shash(ctx->outer);
+}
+
static int mv_cesa_ahmac_md5_init(struct ahash_request *req)
{
struct mv_cesa_hmac_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
@@ -1318,7 +1416,8 @@ struct ahash_alg mv_ahmac_md5_alg = {
CRYPTO_ALG_KERN_DRIVER_ONLY,
.cra_blocksize = MD5_HMAC_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct mv_cesa_hmac_ctx),
- .cra_init = mv_cesa_ahmac_cra_init,
+ .cra_init = mv_cesa_ahmac_md5_cra_init,
+ .cra_exit = mv_cesa_ahmac_cra_exit,
.cra_module = THIS_MODULE,
}
}
@@ -1389,7 +1488,8 @@ struct ahash_alg mv_ahmac_sha1_alg = {
CRYPTO_ALG_KERN_DRIVER_ONLY,
.cra_blocksize = SHA1_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct mv_cesa_hmac_ctx),
- .cra_init = mv_cesa_ahmac_cra_init,
+ .cra_init = mv_cesa_ahmac_sha1_cra_init,
+ .cra_exit = mv_cesa_ahmac_cra_exit,
.cra_module = THIS_MODULE,
}
}
@@ -1460,7 +1560,8 @@ struct ahash_alg mv_ahmac_sha256_alg = {
CRYPTO_ALG_KERN_DRIVER_ONLY,
.cra_blocksize = SHA256_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct mv_cesa_hmac_ctx),
- .cra_init = mv_cesa_ahmac_cra_init,
+ .cra_init = mv_cesa_ahmac_sha256_cra_init,
+ .cra_exit = mv_cesa_ahmac_cra_exit,
.cra_module = THIS_MODULE,
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 4/8] crypto: cesa - finish the HMAC outer hash when padding by hand
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:52 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-28 4:52 UTC (permalink / raw)
To: Rosen Penev, linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Arnaud Ebalard,
Boris Brezillon, Russell King, Romain Perier
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] crypto: cesa - Fixes trailer cites TDMA commit instead of
f63601fd616a
--
commit 1b090efdccb0bcfaec213f4a5b0122cbc6cbc29d
Author: Rosen Penev <rosenp@gmail.com>
> crypto: cesa - finish the HMAC outer hash when padding by hand
>
> The engine applies the HMAC outer hash only when it finalises the
> message itself, i.e. on a last or unfragmented operation that has data
> and whose total length fits the descriptor field (0xffff). Otherwise
> the driver pads the message by hand and runs the padding as a middle
> fragment, which leaves the engine with a plain inner hash state. For
> HMAC that is wrong twice over:
>
> - the padding encodes the message length only, while the inner hash
> also covers the ipad block, and
> - the outer hash is never computed, so the result read back from the
> IVDIG registers is H(ipad || m) instead of HMAC(k, m).
>
> This hits every HMAC whose last request has no data left to hash, i.e.
> any update()/final() sequence over a block-aligned length and any
> finup() or digest() of an empty message, and every HMAC of 64 KiB or
> more.
>
> Count the ipad block in the manual padding of HMAC requests, and when
> the result comes from the IVDIG registers on the last request of an
> HMAC, finish the outer hash in software: import the opad state computed
> at setkey time into a software hash, with one block already counted,
> and hash the inner digest. Each HMAC transform allocates that software
> hash at cra_init(). Select the software hashes so they are always
> available.
>
> Verified on an Armada 385 (WRT3200ACM) against the software HMACs,
> single threaded with random lengths and update splits: about 0.5% of
> HMAC-SHA1 and HMAC-SHA256 digests were wrong before, all of them with a
> block-aligned total length, and none of about 195000 after, nor of
> 30000 more with lengths up to 140000 bytes. HMAC-MD5 was not tested:
> the test kernel has no software MD5.
>
> Fixes: db509a45339f ("crypto: marvell/cesa - add TDMA support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
[Severity: Low]
Should the Fixes tag reference f63601fd616a ("crypto: marvell/cesa - add a
new driver for Marvell's CESA") instead? mv_cesa_ahash_pad_req(), the
manual padding fallback in mv_cesa_ahash_std_step(), and the CESA_IVDIG
result readback for HMAC were all introduced in that initial driver commit
rather than in db509a45339f ("crypto: marvell/cesa - add TDMA support").
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128044050.722617-1-rosenp@gmail.com?part=4
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 5/8] crypto: cesa - keep the chained IV on the non-TDMA cipher path
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
` (3 preceding siblings ...)
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 ` Rosen Penev
2026-11-28 4:40 ` [PATCH 6/8] crypto: cesa - put the non-TDMA hash padding behind the data Rosen Penev
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Rosen Penev @ 2026-11-28 4:40 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Rosen Penev,
Arnaud Ebalard, Boris Brezillon, Russell King, Romain Perier,
stable
On engines without TDMA (Orion), a cipher request longer than the SRAM
payload is processed in several steps, and for CBC the engine leaves the
IV for the next step in the SRAM context area. Since commit 2786cee8e50b
("crypto: marvell - Move SRAM I/O operations to step functions"),
mv_cesa_skcipher_std_step() copies the whole operation, original IV
included, to SRAM at the start of every step, before the copy further
down that rightly writes the full operation for the first step only and
just the descriptor afterwards. Every step after the first therefore
restarts from the request IV, and every CBC request longer than 1920
bytes (with the default 2 KiB SRAM) gives a wrong result.
Drop the redundant copy.
Tested on an Armada 385 (WRT3200ACM) with TDMA disabled in a test build,
against the software implementations: CBC-AES and CBC-3DES results were
wrong for 77% of random lengths up to 8192 bytes, i.e. all of those over
1920 bytes, and correct for all of about 38000 after. ECB was always
correct.
Fixes: 2786cee8e50b ("crypto: marvell - Move SRAM I/O operations to step functions")
Cc: stable@vger.kernel.org
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/crypto/marvell/cesa/cipher.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/marvell/cesa/cipher.c b/drivers/crypto/marvell/cesa/cipher.c
index 3fe0fd9226cf..fb9ea9623746 100644
--- a/drivers/crypto/marvell/cesa/cipher.c
+++ b/drivers/crypto/marvell/cesa/cipher.c
@@ -91,11 +91,11 @@ static void mv_cesa_skcipher_std_step(struct skcipher_request *req)
size_t len = min_t(size_t, req->cryptlen - sreq->offset,
CESA_SA_SRAM_PAYLOAD_SIZE);
+ /*
+ * The op is copied to SRAM below, in full for the first chunk only:
+ * later chunks must keep the IV the engine chained there.
+ */
mv_cesa_adjust_op(engine, &sreq->op);
- if (engine->pool)
- memcpy(engine->sram_pool, &sreq->op, sizeof(sreq->op));
- else
- memcpy_toio(engine->sram, &sreq->op, sizeof(sreq->op));
len = mv_cesa_sg_copy_to_sram(engine, req->src, creq->src_nents,
CESA_SA_DATA_SRAM_OFFSET, len,
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 6/8] crypto: cesa - put the non-TDMA hash padding behind the data
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
` (4 preceding siblings ...)
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 ` Rosen Penev
2026-11-28 4:40 ` [PATCH 7/8] crypto: cesa - do not step empty hash operations on the non-TDMA path Rosen Penev
2026-11-28 4:40 ` [PATCH 8/8] crypto: cesa - finish long hashes " Rosen Penev
7 siblings, 0 replies; 11+ messages in thread
From: Rosen Penev @ 2026-11-28 4:40 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Rosen Penev,
Arnaud Ebalard, Boris Brezillon, Russell King, Romain Perier,
stable
Commit e62291c1d9f4 ("crypto: marvell/cesa - Fix sparse warnings")
changed mv_cesa_ahash_std_step() to build the hash padding in the cache
and copy it to SRAM, instead of building it in place right behind the
data. The length is advanced before the copy, so the padding lands one
padding length too far, and the engine hashes as many bytes of stale
SRAM in its place.
Copy the padding first, then account for it.
Fixes: e62291c1d9f4 ("crypto: marvell/cesa - Fix sparse warnings")
Cc: stable@vger.kernel.org
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/crypto/marvell/cesa/hash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index f6894ed7c1cc..6fcd78427b71 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -253,7 +253,6 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
new_cache_ptr);
} else {
i = mv_cesa_ahash_pad_req(creq, creq->cache);
- len += i;
if (engine->pool)
memcpy(engine->sram_pool + len +
CESA_SA_DATA_SRAM_OFFSET,
@@ -262,6 +261,7 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
memcpy_toio(engine->sram + len +
CESA_SA_DATA_SRAM_OFFSET,
creq->cache, i);
+ len += i;
}
if (frag_mode == CESA_SA_DESC_CFG_LAST_FRAG)
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 7/8] crypto: cesa - do not step empty hash operations on the non-TDMA path
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
` (5 preceding siblings ...)
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
2026-11-28 4:40 ` [PATCH 8/8] crypto: cesa - finish long hashes " Rosen Penev
7 siblings, 0 replies; 11+ messages in thread
From: Rosen Penev @ 2026-11-28 4:40 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Rosen Penev,
Arnaud Ebalard, Boris Brezillon, Russell King, Romain Perier,
stable
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
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 8/8] crypto: cesa - finish long hashes on the non-TDMA path
2026-11-28 4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
` (6 preceding siblings ...)
2026-11-28 4:40 ` [PATCH 7/8] crypto: cesa - do not step empty hash operations on the non-TDMA path Rosen Penev
@ 2026-11-28 4:40 ` Rosen Penev
2026-11-28 4:52 ` sashiko-bot
7 siblings, 1 reply; 11+ messages in thread
From: Rosen Penev @ 2026-11-28 4:40 UTC (permalink / raw)
To: linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Rosen Penev,
Arnaud Ebalard, Boris Brezillon, Russell King, Romain Perier,
stable
On engines without TDMA (Orion), the last request of a hash is finished
in mv_cesa_ahash_std_step() either by the engine, when the total length
fits the descriptor field (0xffff), or with padding built by the driver.
Three things go wrong there:
- The hand-made padding is only added inside the branch for the
last/unfragmented operations, which is only taken when the total
length fits the descriptor field. Hashes of 64 KiB or more are
therefore never padded.
- When the padding does not fit behind the data, the code keeps
len % 64 bytes as the amount to hash and carries 64 - padding length
bytes into the cache, rather than hashing the whole blocks and
carrying the partial one over to a step that adds the padding.
- mv_cesa_ahash_std_process() completes the last request as soon as
its source data is used up, so a carried-over block and its padding
would never be hashed anyway.
Enter the finishing code whenever the data of the last request is used
up, convert only last/unfragmented operations to middle/first ones when
padding by hand, carry the partial block over properly, and complete the
last request only once its final operation has been started.
Tested on an Armada 385 (WRT3200ACM) with TDMA disabled in a test build,
against the software implementations, with this and the two previous
patches: before them, single threaded with lengths up to 140000 bytes,
63% of MD5/SHA1/SHA256 digests were wrong and a 4 thread run hung; after
them, none of about 240000 hashes of up to 8192 or 140000 bytes, nor of
26000 operations of mixed cipher and hash load over 4 threads.
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/cesa.h | 3 +++
drivers/crypto/marvell/cesa/hash.c | 38 ++++++++++++++++++++----------
2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/drivers/crypto/marvell/cesa/cesa.h b/drivers/crypto/marvell/cesa/cesa.h
index 906d55fb6a3a..490d7b46cbfc 100644
--- a/drivers/crypto/marvell/cesa/cesa.h
+++ b/drivers/crypto/marvell/cesa/cesa.h
@@ -585,9 +585,12 @@ struct mv_cesa_skcipher_req {
/**
* struct mv_cesa_ahash_std_req - standard hash request
* @offset: current operation offset
+ * @final_issued: the last operation of the last request (finalised by the
+ * engine, or followed by the hand-made padding) has been started
*/
struct mv_cesa_ahash_std_req {
unsigned int offset;
+ bool final_issued;
};
/**
diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
index b51315cd01df..5e867e688ffa 100644
--- a/drivers/crypto/marvell/cesa/hash.c
+++ b/drivers/crypto/marvell/cesa/hash.c
@@ -174,6 +174,7 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
struct mv_cesa_engine *engine = creq->base.engine;
struct mv_cesa_op_ctx *op;
unsigned int new_cache_ptr = 0;
+ bool final;
u32 frag_mode;
size_t len;
unsigned int digsize;
@@ -221,16 +222,17 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
frag_mode = mv_cesa_get_op_cfg(op) & CESA_SA_DESC_CFG_FRAG_MSK;
- if (creq->last_req && sreq->offset == req->nbytes &&
- creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
+ /* All data of the last request is in SRAM: finish the hash. */
+ final = creq->last_req && sreq->offset == req->nbytes;
+
+ if (final && creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
if (frag_mode == CESA_SA_DESC_CFG_FIRST_FRAG)
frag_mode = CESA_SA_DESC_CFG_NOT_FRAG;
else if (frag_mode == CESA_SA_DESC_CFG_MID_FRAG)
frag_mode = CESA_SA_DESC_CFG_LAST_FRAG;
}
- if (frag_mode == CESA_SA_DESC_CFG_NOT_FRAG ||
- frag_mode == CESA_SA_DESC_CFG_LAST_FRAG) {
+ if (final) {
if (len &&
creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
mv_cesa_set_mac_op_total_len(op, creq->len);
@@ -238,8 +240,13 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
int trailerlen = mv_cesa_ahash_pad_len(creq) + 8;
if (len + trailerlen > CESA_SA_SRAM_PAYLOAD_SIZE) {
- len &= CESA_HASH_BLOCK_SIZE_MSK;
- new_cache_ptr = 64 - trailerlen;
+ /*
+ * No room for the padding: hash the whole
+ * blocks now and carry the partial one over
+ * to the next step, which adds the padding.
+ */
+ new_cache_ptr = len & CESA_HASH_BLOCK_SIZE_MSK;
+ len &= ~CESA_HASH_BLOCK_SIZE_MSK;
if (engine->pool)
memcpy(creq->cache,
engine->sram_pool +
@@ -262,15 +269,20 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
CESA_SA_DATA_SRAM_OFFSET,
creq->cache, i);
len += i;
+ sreq->final_issued = true;
}
if (frag_mode == CESA_SA_DESC_CFG_LAST_FRAG)
frag_mode = CESA_SA_DESC_CFG_MID_FRAG;
- else
+ else if (frag_mode == CESA_SA_DESC_CFG_NOT_FRAG)
frag_mode = CESA_SA_DESC_CFG_FIRST_FRAG;
}
}
+ if (frag_mode == CESA_SA_DESC_CFG_NOT_FRAG ||
+ frag_mode == CESA_SA_DESC_CFG_LAST_FRAG)
+ sreq->final_issued = true;
+
mv_cesa_set_mac_op_frag_len(op, len);
mv_cesa_update_op_cfg(op, frag_mode, CESA_SA_DESC_CFG_FRAG_MSK);
@@ -299,11 +311,12 @@ static int mv_cesa_ahash_std_process(struct ahash_request *req, u32 status)
struct mv_cesa_ahash_std_req *sreq = &creq->req.std;
unsigned int left;
- if (creq->last_req) {
- if (sreq->offset < (req->nbytes - creq->cache_ptr))
- return -EINPROGRESS;
- return 0;
- }
+ /*
+ * The last request may still hold a partial block carried over from
+ * the previous step, and always needs its final operation.
+ */
+ if (creq->last_req)
+ return sreq->final_issued ? 0 : -EINPROGRESS;
/*
* Less than a block left: keep it in the cache for the next request
@@ -331,6 +344,7 @@ static void mv_cesa_ahash_std_prepare(struct ahash_request *req)
struct mv_cesa_ahash_std_req *sreq = &creq->req.std;
sreq->offset = 0;
+ sreq->final_issued = false;
}
static void mv_cesa_ahash_dma_step(struct ahash_request *req)
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 8/8] crypto: cesa - finish long hashes on the non-TDMA path
2026-11-28 4:40 ` [PATCH 8/8] crypto: cesa - finish long hashes " Rosen Penev
@ 2026-11-28 4:52 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-28 4:52 UTC (permalink / raw)
To: Rosen Penev, linux-crypto, Herbert Xu
Cc: Srujana Challa, Bharat Bhushan, David S. Miller, Arnaud Ebalard,
Boris Brezillon, Russell King, Romain Perier
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] crypto: cesa: buffer overflow on creq->cache in
mv_cesa_ahash_std_step()
--
commit 819442c312cc2cf884cbbf9084155d8ab97dd609
Author: Rosen Penev <rosenp@gmail.com>
crypto: cesa - finish long hashes on the non-TDMA path
This commit fixes hash finalization on the non-TDMA path for messages of
64 KiB or more by entering the manual padding block whenever the last
request's source data is consumed, carrying partial blocks across steps,
and tracking final step emission via sreq->final_issued.
> diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
> index b51315cd01dfa..5e867e688ffa5 100644
> --- a/drivers/crypto/marvell/cesa/hash.c
> +++ b/drivers/crypto/marvell/cesa/hash.c
[ ... ]
> @@ -221,16 +222,17 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
>
> frag_mode = mv_cesa_get_op_cfg(op) & CESA_SA_DESC_CFG_FRAG_MSK;
>
> - if (creq->last_req && sreq->offset == req->nbytes &&
> - creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
> + /* All data of the last request is in SRAM: finish the hash. */
> + final = creq->last_req && sreq->offset == req->nbytes;
> +
> + if (final && creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
> if (frag_mode == CESA_SA_DESC_CFG_FIRST_FRAG)
> frag_mode = CESA_SA_DESC_CFG_NOT_FRAG;
> else if (frag_mode == CESA_SA_DESC_CFG_MID_FRAG)
> frag_mode = CESA_SA_DESC_CFG_LAST_FRAG;
> }
>
> - if (frag_mode == CESA_SA_DESC_CFG_NOT_FRAG ||
> - frag_mode == CESA_SA_DESC_CFG_LAST_FRAG) {
> + if (final) {
> if (len &&
> creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
> mv_cesa_set_mac_op_total_len(op, creq->len);
> @@ -238,8 +240,13 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
> int trailerlen = mv_cesa_ahash_pad_len(creq) + 8;
>
> if (len + trailerlen > CESA_SA_SRAM_PAYLOAD_SIZE) {
> - len &= CESA_HASH_BLOCK_SIZE_MSK;
> - new_cache_ptr = 64 - trailerlen;
> + /*
> + * No room for the padding: hash the whole
> + * blocks now and carry the partial one over
> + * to the next step, which adds the padding.
> + */
> + new_cache_ptr = len & CESA_HASH_BLOCK_SIZE_MSK;
> + len &= ~CESA_HASH_BLOCK_SIZE_MSK;
> if (engine->pool)
> memcpy(creq->cache,
> engine->sram_pool +
> @@ -262,15 +269,20 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
> CESA_SA_DATA_SRAM_OFFSET,
> creq->cache, i);
> len += i;
> + sreq->final_issued = true;
> }
[Severity: High]
Can mv_cesa_ahash_pad_req(creq, creq->cache) overflow creq->cache[] when
creq->len > CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX and (creq->len & 63) >= 56?
Previously, the manual padding branch was only reachable when len == 0
and creq->len <= 0xffff, which only occurred on block-aligned lengths
where padlen + 8 is 64 bytes. Now that long hashes enter this branch for
any remainder, a message with (creq->len & 63) in 56..63 has a padlen of
57..64 bytes, so mv_cesa_ahash_pad_req() writes 65..72 bytes (padlen plus
the 8-byte bit length) into creq->cache[CESA_MAX_HASH_BLOCK_SIZE], which
is only 64 bytes.
That overwrites the adjacent creq->cache_ptr and creq->len fields in
struct mv_cesa_ahash_req, and the subsequent memcpy() of i bytes reads
past creq->cache[] (triggering a FORTIFY_SOURCE panic when engine->pool
is used).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128044050.722617-1-rosenp@gmail.com?part=8
^ permalink raw reply [flat|nested] 11+ messages in thread