* [PATCH] crypto: caam - handle empty message in ahash_finup_first
@ 2026-11-19 23:59 Sebastian Krzyszkowiak
2026-11-27 5:15 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Krzyszkowiak @ 2026-11-19 23:59 UTC (permalink / raw)
To: Horia Geantă, Pankaj Gupta, Sahil Malhotra, Herbert Xu,
David S. Miller
Cc: kernel, linux-crypto, stable, Sebastian Krzyszkowiak
Since commit 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API"),
crypto_ahash_final calls crypto_ahash_finup with req->nbytes == 0.
This leads to an oops on an empty message to hash when ahash_edesc_add_src
calls sg_dma_address(req->src) if the caller passes NULL as req->src:
Unable to handle kernel NULL pointer dereference at virtual
address 0000000000000010
Call trace:
ahash_edesc_add_src+0x40/0x390 (P)
ahash_digest+0xcc/0x250
ahash_finup_first+0x18/0x30
ahash_finup+0x24/0x38
ahash_do_req_chain+0xc0/0x1b0
crypto_ahash_finup+0x168/0x200
hash_recvmsg+0xb0/0x1f0 [algif_hash]
It can be reproduced on i.MX 8M Quad with the following Python snippet:
import socket
s = socket.socket(socket.AF_ALG, socket.SOCK_SEQPACKET, 0)
s.bind(("hash", "sha256"))
op, _ = s.accept()
print(op.recv(32).hex())
The oops was observed being triggered by iwd.
ahash_finup_first runs only when nothing has been hashed yet, so handle
the empty-message case by routing it to ahash_final_no_ctx.
Fixes: 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API")
Cc: stable@vger.kernel.org
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
---
drivers/crypto/caam/caamalg_qi2.c | 3 +++
drivers/crypto/caam/caamhash.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c
index ef67122bef57..d449634a9bfb 100644
--- a/drivers/crypto/caam/caamalg_qi2.c
+++ b/drivers/crypto/caam/caamalg_qi2.c
@@ -4331,6 +4331,9 @@ static int ahash_update_first(struct ahash_request *req)
static int ahash_finup_first(struct ahash_request *req)
{
+ if (!req->nbytes)
+ return ahash_final_no_ctx(req);
+
return ahash_digest(req);
}
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 3cd71810380f..5794c26e0efb 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1499,6 +1499,9 @@ static int ahash_update_first(struct ahash_request *req)
static int ahash_finup_first(struct ahash_request *req)
{
+ if (!req->nbytes)
+ return ahash_final_no_ctx(req);
+
return ahash_digest(req);
}
---
base-commit: d785d132202e8e8e93335ebf74ad5b29fca0951f
change-id: 20261120-caam-empty-96490ae60cae
Best regards,
--
Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] crypto: caam - handle empty message in ahash_finup_first
2026-11-19 23:59 [PATCH] crypto: caam - handle empty message in ahash_finup_first Sebastian Krzyszkowiak
@ 2026-11-27 5:15 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2026-11-27 5:15 UTC (permalink / raw)
To: Sebastian Krzyszkowiak
Cc: Horia Geantă, Pankaj Gupta, Sahil Malhotra, David S. Miller,
kernel, linux-crypto, stable
On Fri, Nov 20, 2026 at 12:59:57AM +0100, Sebastian Krzyszkowiak wrote:
> Since commit 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API"),
> crypto_ahash_final calls crypto_ahash_finup with req->nbytes == 0.
> This leads to an oops on an empty message to hash when ahash_edesc_add_src
> calls sg_dma_address(req->src) if the caller passes NULL as req->src:
>
> Unable to handle kernel NULL pointer dereference at virtual
> address 0000000000000010
> Call trace:
> ahash_edesc_add_src+0x40/0x390 (P)
> ahash_digest+0xcc/0x250
> ahash_finup_first+0x18/0x30
> ahash_finup+0x24/0x38
> ahash_do_req_chain+0xc0/0x1b0
> crypto_ahash_finup+0x168/0x200
> hash_recvmsg+0xb0/0x1f0 [algif_hash]
>
> It can be reproduced on i.MX 8M Quad with the following Python snippet:
>
> import socket
> s = socket.socket(socket.AF_ALG, socket.SOCK_SEQPACKET, 0)
> s.bind(("hash", "sha256"))
> op, _ = s.accept()
> print(op.recv(32).hex())
>
> The oops was observed being triggered by iwd.
>
> ahash_finup_first runs only when nothing has been hashed yet, so handle
> the empty-message case by routing it to ahash_final_no_ctx.
>
> Fixes: 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
> ---
> drivers/crypto/caam/caamalg_qi2.c | 3 +++
> drivers/crypto/caam/caamhash.c | 3 +++
> 2 files changed, 6 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-11-27 5:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 23:59 [PATCH] crypto: caam - handle empty message in ahash_finup_first Sebastian Krzyszkowiak
2026-11-27 5:15 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox