mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 6.6.y] crypto: af_alg - limit RX SG extraction by receive buffer budget
@ 2026-10-21 17:54 Artem Dinaburg
  2026-10-21 20:55 ` Eric Biggers
  0 siblings, 1 reply; 2+ messages in thread
From: Artem Dinaburg @ 2026-10-21 17:54 UTC (permalink / raw)
  To: stable
  Cc: davem, herbert, ldy3087146292, linux-crypto, linux-kernel, n05ec,
	tomapufckgml, yifanwucs, yuantan098

From: Douya Le <ldy3087146292@gmail.com>

[ Upstream commit 8eceab19eba9dcbfd2a0daec72e1bf48aa100170 ]

Make af_alg_get_rsgl() limit each RX scatterlist extraction to the
remaining receive buffer budget.

af_alg_get_rsgl() currently uses af_alg_readable() only as a gate
before extracting data into the RX scatterlist. Limit each extraction
to the remaining af_alg_rcvbuf(sk) budget so that receive-side
accounting matches the amount of data attached to the request.

If skcipher cannot obtain enough RX space for at least one chunk while
more data remains to be processed, reject the recvmsg call instead of
rounding the request length down to zero.

Fixes: e870456d8e7c8d57c059ea479b5aadbb55ff4c3a ("crypto: algif_skcipher - overhaul memory management")
Reported-by: Yifan Wu <yifanwucs@gmail.com>
Reported-by: Juefei Pu <tomapufckgml@gmail.com>
Co-developed-by: Yuan Tan <yuantan098@gmail.com>
Signed-off-by: Yuan Tan <yuantan098@gmail.com>
Suggested-by: Xin Liu <bird@lzu.edu.cn>
Signed-off-by: Douya Le <ldy3087146292@gmail.com>
Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Assisted-by: LLM
[ Backport to 6.6.y: Add braces to the older block-size conditional so the
  new short-block error check and existing rounding remain under the same
  condition. ]
Signed-off-by: Artem Dinaburg <artem@trailofbits.com>
---
Hi,

Please consider this backport of the fix for CVE-2026-31677 to 6.6.y.

The code changes match upstream, with braces added to the older block-size
conditional. See the bracketed backport note above.

The complete fix is already present in 6.12.y, 6.18.y and 7.2.y.

Build-tested only as part of a cumulative 6.6.y series on x86_64
(allmodconfig, CONFIG_WERROR=y); no runtime testing.

Thanks,
Artem Dinaburg

 crypto/af_alg.c         |    2 ++
 crypto/algif_skcipher.c |    8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index e7fea668473d9ede47c7d0e2005c333d34147b29..e6e94b34e0afe78f4d2a8a60c6a194bd0a958beb 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -1207,6 +1207,8 @@ int af_alg_get_rsgl(struct sock *sk, struct msghdr *msg, int flags,
 
 		seglen = min_t(size_t, (maxsize - len),
 			       msg_data_left(msg));
+		/* Never pin more pages than the remaining RX accounting budget. */
+		seglen = min_t(size_t, seglen, af_alg_rcvbuf(sk));
 
 		if (list_empty(&areq->rsgl_list)) {
 			rsgl = &areq->first_rsgl;
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index b12df4544d0bbba3f3d156f0e279ac896cd81ec0..8729ef268d9d83cea537abaf23c6cdbb45f59ccd 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -82,8 +82,14 @@ 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)
+	if (ctx->more || len < ctx->used) {
+		if (len < bs) {
+			err = -EINVAL;
+			goto free;
+		}
+
 		len -= len % bs;
+	}
 
 	/*
 	 * Create a per request TX SGL for this request which tracks the

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 6.6.y] crypto: af_alg - limit RX SG extraction by receive buffer budget
  2026-10-21 17:54 [PATCH 6.6.y] crypto: af_alg - limit RX SG extraction by receive buffer budget Artem Dinaburg
@ 2026-10-21 20:55 ` Eric Biggers
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2026-10-21 20:55 UTC (permalink / raw)
  To: Artem Dinaburg
  Cc: stable, davem, herbert, ldy3087146292, linux-crypto,
	linux-kernel, n05ec, tomapufckgml, yifanwucs, yuantan098

On Wed, Oct 21, 2026 at 01:54:05PM -0400, Artem Dinaburg wrote:
> [ Backport to 6.6.y: Add braces to the older block-size conditional so the
>   new short-block error check and existing rounding remain under the same
>   condition. ]
> Signed-off-by: Artem Dinaburg <artem@trailofbits.com>

Seems this was already done in 7e345de2e69475430af85e09210795d8eb8e719c,
which is the same custom backport diff.  It was recently released in
6.6.y without any public discussion.  Fortunately the backport looks
okay, I think.  Odd that the stable maintainers are applying custom
backports to the crypto/ directory without Cc'ing linux-crypto, though.

- Eric

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-21 20:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 17:54 [PATCH 6.6.y] crypto: af_alg - limit RX SG extraction by receive buffer budget Artem Dinaburg
2026-10-21 20:55 ` Eric Biggers

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®