crypto: af_alg - limit RX SG extraction by receive buffer budget
Subsystems (2)
PATCH 1/1 crypto: af_alg - limit RX SG extraction by receive buffer budget
From: Douya Le <[email protected]>
[ 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.
[ 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. ]
---
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(-)
crypto/af_alg.c +2 -0
@@ -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;
crypto/algif_skcipher.c +7 -1
@@ -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
Quoted 4 lines · Artem Dinaburg
[ 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 <[email protected]>
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