[PATCH] crypto: af_alg - wake up waiters on zero-length final message
From: Guicai Ma
Date: Fri Nov 20 2026 - 03:33:01 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Guicai Ma <maguicai@xxxxxxxxxx>
---
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();