From: Herbert Xu Date: Tue, 16 Sep 2025 07:42:41 +0000 (+0800) Subject: crypto: af_alg - Set merge to zero early in af_alg_sendmsg X-Git-Tag: v6.17-rc7~14^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9574b2330dbd2b5459b74d3b5e9619d39299fc6f;p=thirdparty%2Fkernel%2Fstable.git crypto: af_alg - Set merge to zero early in af_alg_sendmsg If an error causes af_alg_sendmsg to abort, ctx->merge may contain a garbage value from the previous loop. This may then trigger a crash on the next entry into af_alg_sendmsg when it attempts to do a merge that can't be done. Fix this by setting ctx->merge to zero near the start of the loop. Fixes: 8ff590903d5 ("crypto: algif_skcipher - User-space interface for skcipher operations") Reported-by: Muhammad Alifa Ramdhan Reported-by: Bing-Jhong Billy Jheng Signed-off-by: Herbert Xu --- diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 0da7c1ac778a0..407f2c238f2c6 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -1019,6 +1019,8 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, continue; } + ctx->merge = 0; + if (!af_alg_writable(sk)) { err = af_alg_wait_for_wmem(sk, msg->msg_flags); if (err) @@ -1058,7 +1060,6 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, ctx->used += plen; copied += plen; size -= plen; - ctx->merge = 0; } else { do { struct page *pg;