mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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
  2026-11-27  7:12 ` [PATCH v2] " Guicai Ma
  0 siblings, 2 replies; 3+ 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	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27  7:12 UTC | newest]

Thread overview: 3+ 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
2026-11-27  7:12 ` [PATCH v2] " Guicai Ma

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®