* [PATCH] crypto: algif_skcipher - Fix receive iterator advancement
@ 2026-10-06 22:05 Kyle Zeng
0 siblings, 0 replies; only message in thread
From: Kyle Zeng @ 2026-10-06 22:05 UTC (permalink / raw)
To: linux-crypto; +Cc: linux-kernel, herbert, davem, Kyle Zeng, stable
af_alg_get_rsgl() advances the receive iterator by the full RX scatterlist
length. A non-final skcipher request then rounds that length down to a
multiple of the cipher's chunksize without returning the unused suffix
to the iterator. If the receive loop processes another request, it
writes past that suffix even though the returned byte count includes
only the processed lengths. The socket splice fallback can consequently
publish uninitialized bytes from its newly allocated pages.
Save the iterator before gathering the RX scatterlist. After processing
the request and releasing its resources, restore the iterator and advance
it only by the successfully processed length. This also leaves the
iterator unchanged if gathering or processing the request fails. Keep
the existing cipher request lengths, continuation flags and scatterlist
cleanup unchanged.
Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-6-astra
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
crypto/algif_skcipher.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index 1e61fe6e24b9..21d077a54dd5 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -107,6 +107,7 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
struct alg_sock *pask = alg_sk(psk);
struct af_alg_ctx *ctx = ask->private;
struct crypto_skcipher *tfm = pask->private;
+ struct iov_iter saved_iter = msg->msg_iter;
unsigned int bs = crypto_skcipher_chunksize(tfm);
struct af_alg_async_req *areq;
unsigned cflags = 0;
@@ -193,6 +194,11 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
free:
af_alg_free_resources(areq);
+ /* The RX SGL may be longer than the request actually processed. */
+ msg->msg_iter = saved_iter;
+ if (!err)
+ iov_iter_advance(&msg->msg_iter, len);
+
return err ? err : len;
}
base-commit: fd179f8a05be3ccae366b9b96e176b51fbe54aab
--
2.53.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-06 22:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-06 22:05 [PATCH] crypto: algif_skcipher - Fix receive iterator advancement Kyle Zeng
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®