* [Devel] [PATCH vz7] ms/crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg
@ 2026-11-18 20:50 Konstantin Khorenko
2026-11-18 21:17 ` Konstantin Khorenko
0 siblings, 1 reply; 2+ messages in thread
From: Konstantin Khorenko @ 2026-11-18 20:50 UTC (permalink / raw)
To: Konstantin Khorenko; +Cc: devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Devel] [PATCH vz7] ms/crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg
2026-11-18 20:50 [Devel] [PATCH vz7] ms/crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg Konstantin Khorenko
@ 2026-11-18 21:17 ` Konstantin Khorenko
0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Khorenko @ 2026-11-18 21:17 UTC (permalink / raw)
To: Konstantin Khorenko; +Cc: devel
On Wed, 18 Nov 2026 21:50:44 +0100, Konstantin Khorenko wrote:
> ms/crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg
Applied to branch-rh7-3.10.0-1160.129.1.vz7.226.x-ovz, will be released in rh7-3.10.0-1160.129.1.vz7.226.6, thanks!
[1/1] ms/crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/cea7bc6d26d6
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 21:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 20:50 [Devel] [PATCH vz7] ms/crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg Konstantin Khorenko
2026-11-18 21:17 ` Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox