FAILED: patch "[PATCH] crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg" failed to apply to 6.1-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 1b34cbbf4f011a121ef7b2d7d6e6920a036d5285
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025092107-making-cough-9671@gregkh' --subject-prefix 'PATCH 6.1.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 1b34cbbf4f011a121ef7b2d7d6e6920a036d5285 Mon Sep 17 00:00:00 2001
From: Herbert Xu <[email protected]>
Date: Tue, 16 Sep 2025 17:20:59 +0800
Subject: [PATCH] crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg
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.
crypto/af_alg.c +7 -0
@@ -970,6 +970,12 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, }lock_sock (sk); +if (ctx->write) { +release_sock (sk); +return -EBUSY ; + } + ctx->write = true; +if (ctx->init && !ctx->more) {if (ctx->used) { err = -EINVAL ;
@@ -1105,6 +1111,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, unlock:af_alg_data_wakeup (sk); + ctx->write = false;release_sock (sk);return copied ?: err;
include/crypto/if_alg.h +6 -4
@@ -135,6 +135,7 @@ struct af_alg_async_req {* SG? * @enc: Cryptographic operation to be performed when * recvmsg is invoked. +* @write: True if we are in the middle of a write. * @init: True if metadata has been sent. * @len: Length of memory allocated for this data structure. * @inflight: Non-zero when AIO requests are in flight.
@@ -151,10 +152,11 @@ struct af_alg_ctx {size_t used;atomic_t rcvused; -bool more; -bool merge; -bool enc; -bool init; + u32 more:1, + merge:1, + enc:1, + write:1, + init:1;unsigned int len;
Sasha Levin
maintainerPATCH 1/2 crypto: af_alg: Convert af_alg_sendpage() to use MSG_SPLICE_PAGES
From: David Howells <[email protected]>
[ Upstream commit fb800fa4c1f5aee1238267252e88a7837e645c02 ]
Convert af_alg_sendpage() to use sendmsg() with MSG_SPLICE_PAGES rather than directly splicing in the pages itself.
This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction.
--- crypto/af_alg.c | 52 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-)
crypto/af_alg.c +8 -44
@@ -988,53 +988,17 @@ EXPORT_SYMBOL_GPL(af_alg_sendmsg);ssize_t af_alg_sendpage (struct socket *sock,struct page *page,int offset,size_t size,int flags) { -struct sock *sk = sock->sk; -struct alg_sock *ask =alg_sk (sk); -struct af_alg_ctx *ctx = ask->private; -struct af_alg_tsgl *sgl; -int err = -EINVAL ; +struct bio_vec bvec; +struct msghdr msg = { + .msg_flags = flags |MSG_SPLICE_PAGES , + };if (flags &MSG_SENDPAGE_NOTLAST ) - flags |=MSG_MORE ; - -lock_sock (sk); -if (!ctx->more && ctx->used) - goto unlock; - -if (!size) - goto done; - -if (!af_alg_writable (sk)) { - err =af_alg_wait_for_wmem (sk, flags); -if (err) - goto unlock; - } - - err =af_alg_alloc_tsgl (sk); -if (err) - goto unlock; - - ctx->merge =0 ; - sgl = list_entry(ctx->tsgl_list.prev, struct af_alg_tsgl, list); - -if (sgl->cur) -sg_unmark_end (sgl->sg + sgl->cur -1 ); - -sg_mark_end (sgl->sg + sgl->cur); - -get_page (page); -sg_set_page (sgl->sg + sgl->cur, page, size, offset); - sgl->cur++; - ctx->used += size; - -done: - ctx->more = flags &MSG_MORE ; - -unlock: -af_alg_data_wakeup (sk); -release_sock (sk); + msg.msg_flags |=MSG_MORE ; -return err ?: size; +bvec_set_page (&bvec, page, size, offset); +iov_iter_bvec (&msg.msg_iter,ITER_SOURCE , &bvec,1 , size); +return sock_sendmsg (sock, &msg); }EXPORT_SYMBOL_GPL (af_alg_sendpage);
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 2/2 crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg
From: Herbert Xu <[email protected]>
[ Upstream commit 1b34cbbf4f011a121ef7b2d7d6e6920a036d5285 ]
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.
--- crypto/af_alg.c | 7 +++++++ include/crypto/if_alg.h | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-)
crypto/af_alg.c +7 -0
@@ -859,6 +859,12 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, }lock_sock (sk); +if (ctx->write) { +release_sock (sk); +return -EBUSY ; + } + ctx->write = true; +if (ctx->init && !ctx->more) {if (ctx->used) { err = -EINVAL ;
@@ -969,6 +975,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, unlock:af_alg_data_wakeup (sk); + ctx->write = false;release_sock (sk);return copied ?: err;
include/crypto/if_alg.h +6 -4
@@ -136,6 +136,7 @@ struct af_alg_async_req {* SG? * @enc: Cryptographic operation to be performed when * recvmsg is invoked. +* @write: True if we are in the middle of a write. * @init: True if metadata has been sent. * @len: Length of memory allocated for this data structure. * @inflight: Non-zero when AIO requests are in flight.
@@ -151,10 +152,11 @@ struct af_alg_ctx {size_t used;atomic_t rcvused; -bool more; -bool merge; -bool enc; -bool init; + u32 more:1, + merge:1, + enc:1, + write:1, + init:1;unsigned int len;
Signature · 1 line
2.51.0