From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Daehyeon Ko <4ncienth@gmail.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10.y] crypto: algif_skcipher - rewind rounded output bytes
Date: Tue, 10 Nov 2026 08:06:32 -0500 [thread overview]
Message-ID: <20261110130552.1648939-1-sashal@kernel.org> (raw)
In-Reply-To: <20261107061933-failed-5.10-2f90facc7b94@kernel.org>
From: Daehyeon Ko <4ncienth@gmail.com>
[ Upstream commit 2f90facc7b94934653eb7ebfadcc25d503b89196 ]
af_alg_get_rsgl() advances the receive iterator by the unrounded RX
scatterlist length. For a continuing skcipher request,
_skcipher_recvmsg() then rounds its local length down to a whole chunksize
without restoring the iterator.
A later chunk starts after bytes which the provider never wrote, while the
syscall returns only the processed length. When copy_splice_read()
supplies non-zeroed pages and publishes that return as a dense prefix, the
gap exposes stale bytes from a previous page lifetime.
With unprivileged xts(aes), a 31-byte MSG_MORE request followed by one
final byte advances a 47-byte destination while returning 32 bytes. A
hardened v7.2-rc5 image retained all 15 seeded stale bytes in 4,829 of
4,829 records. With init_on_alloc enabled, all 72,345 gap bytes observed
were zero.
Rewind the iterator by the tail excluded during rounding, before rejecting
a zero processed length. The crypto request uses only the rounded length;
af_alg_free_resources() releases the entire RX list before another receive
iteration.
The fixed target-like kernel returned byte-identical dense 48-byte output
in 4,771 of 4,771 rounds. The unmodified kernel returned the vulnerable
32-byte short record in 2,409 of 2,409 rounds.
Fixes: e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Daehyeon Ko <4ncienth@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ sashal: added the zero-length guard where no short-input check previously existed ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
crypto/algif_skcipher.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index 6a1a71284fe82..c037c3969e9d6 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -82,8 +82,17 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
* If more buffers are to be expected to be processed, process only
* full block size buffers.
*/
- if (ctx->more || len < ctx->used)
- len -= len % bs;
+ if (ctx->more || len < ctx->used) {
+ size_t excess = len % bs;
+
+ len -= excess;
+ iov_iter_revert(&msg->msg_iter, excess);
+
+ if (!len) {
+ err = -EINVAL;
+ goto free;
+ }
+ }
/*
* Create a per request TX SGL for this request which tracks the
--
2.53.0
prev parent reply other threads:[~2026-11-10 13:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 11:19 FAILED: patch "[PATCH] crypto: algif_skcipher - rewind rounded output bytes" failed to apply to 5.10-stable tree Sasha Levin
2026-11-10 13:06 ` Sasha Levin [this message]
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=20261110130552.1648939-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=4ncienth@gmail.com \
--cc=herbert@gondor.apana.org.au \
--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