* [PATCH] crypto: af_alg - wake up waiters on zero-length final message
@ 2026-11-20 8:32 Guicai Ma
2026-11-27 4:45 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Guicai Ma @ 2026-11-20 8:32 UTC (permalink / raw)
To: Herbert Xu, David S . Miller; +Cc: linux-crypto, linux-kernel, Guicai Ma
af_alg_data_wakeup() returns early whenever ctx->used is zero, whereas
af_alg_wait_for_data() waits for:
ctx->init && (!ctx->more || (min && ctx->used >= min))
When a reader is blocked in recvmsg() and a sender submits a zero-length
final message (no MSG_MORE), such as an empty gcm(aes) AEAD encryption
or an empty send to finish a MSG_MORE stream, af_alg_sendmsg() sets
ctx->init = true and ctx->more = false while ctx->used remains 0.
af_alg_data_wakeup() then bails out on !ctx->used, leaving the reader
blocked indefinitely.
Only skip the wakeup if the context is not initialized yet or more data
is still expected with nothing queued.
Fixes: 2d97591ef43d ("crypto: af_alg - consolidation of duplicate code")
Cc: stable@vger.kernel.org
Signed-off-by: Guicai Ma <maguicai@kylinos.cn>
---
Verified with a two-threaded AF_ALG test (zero-length final sendmsg
on gcm(aes) and ecb(aes) while recvmsg() is blocked): recvmsg() hangs
before this patch and completes immediately after.
crypto/af_alg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 7524070f26d8..9b4f8c1d2e3a 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -938,7 +938,7 @@ static void af_alg_data_wakeup(struct sock *sk)
struct af_alg_ctx *ctx = ask->private;
struct socket_wq *wq;
- if (!ctx->used)
+ if (!ctx->init || (ctx->more && !ctx->used))
return;
rcu_read_lock();
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] crypto: af_alg - wake up waiters on zero-length final message
2026-11-20 8:32 [PATCH] crypto: af_alg - wake up waiters on zero-length final message Guicai Ma
@ 2026-11-27 4:45 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2026-11-27 4:45 UTC (permalink / raw)
To: Guicai Ma; +Cc: David S . Miller, linux-crypto, linux-kernel
On Fri, Nov 20, 2026 at 03:32:44AM -0500, Guicai Ma wrote:
>
> diff --git a/crypto/af_alg.c b/crypto/af_alg.c
> index 7524070f26d8..9b4f8c1d2e3a 100644
> --- a/crypto/af_alg.c
> +++ b/crypto/af_alg.c
> @@ -938,7 +938,7 @@ static void af_alg_data_wakeup(struct sock *sk)
> struct af_alg_ctx *ctx = ask->private;
> struct socket_wq *wq;
>
> - if (!ctx->used)
> + if (!ctx->init || (ctx->more && !ctx->used))
Good catch. However, this is still slightly out-of-sync with the
waiting side's condition:
> ctx->init && (!ctx->more || (min && ctx->used >= min))
How about putting that whole thing into a helper and have both sides
use it to ensure that this never happens again?
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 4:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 8:32 [PATCH] crypto: af_alg - wake up waiters on zero-length final message Guicai Ma
2026-11-27 4:45 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox