mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kyle Zeng <kylebot@openai.com>
To: linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, herbert@gondor.apana.org.au,
	davem@davemloft.net, Kyle Zeng <kylebot@openai.com>,
	stable@vger.kernel.org
Subject: [PATCH] crypto: algif_skcipher - Fix receive iterator advancement
Date: Tue,  6 Oct 2026 15:05:23 -0700	[thread overview]
Message-ID: <20261006220523.31218-1-kylebot@openai.com> (raw)

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


                 reply	other threads:[~2026-10-06 22:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261006220523.31218-1-kylebot@openai.com \
    --to=kylebot@openai.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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

all inboxes | Powered by JetHome®