* [PATCH] crypto: atmel: handle authenc requests without plaintext
@ 2026-09-22 5:17 Karl Mehltretter
2026-10-02 8:22 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Karl Mehltretter @ 2026-09-22 5:17 UTC (permalink / raw)
To: Herbert Xu, David S. Miller
Cc: Karl Mehltretter, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Cyrille Pitchen, linux-crypto, linux-arm-kernel,
linux-kernel
Authenc permits a nonempty associated-data string with no plaintext. The
Atmel driver accepts such a request, has SHA process the associated data,
and then unconditionally asks AES DMA to transfer zero bytes. The Atmel
DMA engines reject the zero-length descriptor, so the valid request fails,
normally with -ENOMEM.
Skip the AES transfer when textlen is zero and proceed directly to SHA
finalization.
Once an HMAC transform has cached its inner and outer states, SHA can
complete this path synchronously. The forced ahash completion callback
then invokes the AES finalizer through a void function and discards its
return value. This loses -EBADMSG for a mismatched tag and reports
successful decryption.
For synchronous SHA completion, release the SHA device without invoking
the ahash callback and call the AES finalizer directly. Its result then
propagates through the synchronous call chain. Keep the existing callback
path for asynchronous completion.
On a SAM9X75, the unpatched driver failed valid AAD-only requests and
returned success for a bad tag after the transform had been used once. With
this change, bad tags return -EBADMSG for both fresh and reused transforms.
Fixes: 89a82ef87e01 ("crypto: atmel-authenc - add support to authenc(hmac(shaX), Y(aes)) modes")
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
drivers/crypto/atmel-aes.c | 2 ++
drivers/crypto/atmel-sha.c | 14 ++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index 50d97cef75b89..89594b96e28ce 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -1826,6 +1826,8 @@ static int atmel_aes_authenc_transfer(struct atmel_aes_dev *dd, int err,
dd->is_async = true;
if (err)
return atmel_aes_complete(dd, err);
+ if (!rctx->textlen)
+ return atmel_aes_authenc_digest(dd);
/* Prepare src and dst scatter-lists to transfer cipher/plain texts. */
src = scatterwalk_ffwd(rctx->src, req->src, req->assoclen);
diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index 48f54b6155042..f1a37d315dd0f 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -2383,11 +2383,25 @@ static int atmel_sha_authenc_final_done(struct atmel_sha_dev *dd)
{
struct ahash_request *req = dd->req;
struct atmel_sha_authenc_reqctx *authctx = ahash_request_ctx(req);
+ atmel_aes_authenc_fn_t cb;
+ struct atmel_aes_dev *aes_dev;
size_t i, num_words = authctx->digestlen / sizeof(u32);
for (i = 0; i < num_words; ++i)
authctx->digest[i] = atmel_sha_read(dd, SHA_REG_DIGEST(i));
+ if (!dd->is_async) {
+ /*
+ * Return the AES finalizer's status directly for synchronous requests.
+ * The ahash callback cannot propagate it.
+ */
+ cb = authctx->cb;
+ aes_dev = authctx->aes_dev;
+ dd->force_complete = false;
+ (void)atmel_sha_complete(dd, 0);
+ return cb(aes_dev, 0, false);
+ }
+
return atmel_sha_complete(dd, 0);
}
base-commit: f0100363d8c374bd8e9ea7c9ba02744f0b802ca4
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] crypto: atmel: handle authenc requests without plaintext
2026-09-22 5:17 [PATCH] crypto: atmel: handle authenc requests without plaintext Karl Mehltretter
@ 2026-10-02 8:22 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2026-10-02 8:22 UTC (permalink / raw)
To: Karl Mehltretter
Cc: David S. Miller, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Cyrille Pitchen, linux-crypto, linux-arm-kernel,
linux-kernel
On Tue, Sep 22, 2026 at 07:17:04AM +0200, Karl Mehltretter wrote:
> Authenc permits a nonempty associated-data string with no plaintext. The
> Atmel driver accepts such a request, has SHA process the associated data,
> and then unconditionally asks AES DMA to transfer zero bytes. The Atmel
> DMA engines reject the zero-length descriptor, so the valid request fails,
> normally with -ENOMEM.
>
> Skip the AES transfer when textlen is zero and proceed directly to SHA
> finalization.
>
> Once an HMAC transform has cached its inner and outer states, SHA can
> complete this path synchronously. The forced ahash completion callback
> then invokes the AES finalizer through a void function and discards its
> return value. This loses -EBADMSG for a mismatched tag and reports
> successful decryption.
>
> For synchronous SHA completion, release the SHA device without invoking
> the ahash callback and call the AES finalizer directly. Its result then
> propagates through the synchronous call chain. Keep the existing callback
> path for asynchronous completion.
>
> On a SAM9X75, the unpatched driver failed valid AAD-only requests and
> returned success for a bad tag after the transform had been used once. With
> this change, bad tags return -EBADMSG for both fresh and reused transforms.
>
> Fixes: 89a82ef87e01 ("crypto: atmel-authenc - add support to authenc(hmac(shaX), Y(aes)) modes")
> Assisted-by: LLM
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
> drivers/crypto/atmel-aes.c | 2 ++
> drivers/crypto/atmel-sha.c | 14 ++++++++++++++
> 2 files changed, 16 insertions(+)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-02 8:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-22 5:17 [PATCH] crypto: atmel: handle authenc requests without plaintext Karl Mehltretter
2026-10-02 8:22 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®