From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org
Subject: [Devel] [PATCH vz7] ms/crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg
Date: Wed, 18 Nov 2026 21:50:44 +0100 [thread overview]
Message-ID: <20261118-b4-prep-khorenko-vstor-154198-af_alg-concurrent-writes-v1-1-786b51d5872d@virtuozzo.com> (raw)
From: Herbert Xu <herbert@gondor.apana.org.au>
Issuing two writes to the same af_alg socket is bogus as the
data will be interleaved in an unpredictable fashion. Furthermore,
concurrent writes may create inconsistencies in the internal
socket state.
Disallow this by adding a new ctx->write field that indiciates
exclusive ownership for writing.
Fixes: 8ff590903d5 ("crypto: algif_skcipher - User-space interface for skcipher operations")
Reported-by: Muhammad Alifa Ramdhan <ramdhan@starlabs.sg>
Reported-by: Bing-Jhong Billy Jheng <billy@starlabs.sg>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit 1b34cbbf4f011a121ef7b2d7d6e6920a036d5285)
Backport notes:
- the check goes to skcipher_sendmsg() in algif_skcipher.c;
- write is a plain bool in struct skcipher_ctx, initialized in
skcipher_accept_parent_nokey().
af_alg_sendmsg() and struct af_alg_ctx came with ms commit 2d97591ef43d
("crypto: af_alg - consolidation of duplicate code") in v4.14. Here
each algif type still has its own sendmsg and context, and the code
upstream consolidated into af_alg_sendmsg() is skcipher_sendmsg().
skcipher_sendmsg() drops the socket lock in skcipher_wait_for_wmem().
A second writer can then fill the tail sgl and set ctx->merge, while
the first one appends an empty sgl and fails with EFAULT. The next
write takes the merge path with sg = &sgl->sg[-1] and copies user data
through a scatterlist built from the sgl header and the bytes before
it. hash_sendmsg() and hash_sendpage() hold the lock for the whole
write. skcipher_sendpage() only clears ctx->merge, so it is left as is,
as 5.10.y left af_alg_sendpage().
The flags here are bool and the context is private to this file, so
write is one more bool, not the 1-bit bitfield that ms commit
d0ca0df179c4 ("crypto: af_alg - Fix incorrect boolean values in
af_alg_ctx") had to turn back into bool. The context is not zeroed on
allocation, hence the explicit initialization.
RHEL7 kernel-3.10.0-1160.169.1.el7 has the same change in
algif_skcipher.c. The closest stable backport is 5.10.y commit
0f28c4adbc4a:
https://git.kernel.org/stable/c/0f28c4adbc4a97437874c9b669fd7958a8c6d6ce
CVE-2025-39964
https://virtuozzo.atlassian.net/browse/VSTOR-154198
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
CVE-2025-39964 fix for the vz7 kernel.
https://virtuozzo.atlassian.net/browse/VSTOR-154198
Assisted-by: LLM
---
crypto/algif_skcipher.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index ad4a88628f959..703687d0d9604 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -50,6 +50,7 @@ struct skcipher_ctx {
bool more;
bool merge;
bool enc;
+ bool write;
struct ablkcipher_request req;
};
@@ -284,6 +285,12 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
err = -EINVAL;
lock_sock(sk);
+ if (ctx->write) {
+ release_sock(sk);
+ return -EBUSY;
+ }
+ ctx->write = true;
+
if (!ctx->more && ctx->used)
goto unlock;
@@ -371,6 +378,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
unlock:
skcipher_data_wakeup(sk);
+ ctx->write = false;
release_sock(sk);
return copied ?: err;
@@ -726,6 +734,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk)
ctx->more = 0;
ctx->merge = 0;
ctx->enc = 0;
+ ctx->write = 0;
af_alg_init_completion(&ctx->completion);
ask->private = ctx;
---
base-commit: 78c10c447efc7633a8e4260fe7dc33e1cb4bb4d2
change-id: 20261109-b4-prep-khorenko-vstor-154198-af_alg-concurrent-writes-b278316d06a9
Best regards,
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next reply other threads:[~2026-11-18 20:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 20:50 Konstantin Khorenko [this message]
2026-11-18 21:17 ` Konstantin Khorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118-b4-prep-khorenko-vstor-154198-af_alg-concurrent-writes-v1-1-786b51d5872d@virtuozzo.com \
--to=khorenko@virtuozzo.com \
--cc=devel@openvz.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox