From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72BC8344021; Mon, 20 Apr 2026 16:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776701465; cv=none; b=tM6ReI/GICZWkD3oYsjss4AFtTTg160IC3QyfREeF00Bu02Tx0bgb+L/w87TVeetqKwfeG23njCsCDm7U4yvW5o1iqfJ6w/NbYcr+VTGoweLJW++ADgqj44ZxlyK8cecQcEVaqebyxfCrIPGzDbxV4ESanGLofnO+bjoJ1U38vQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776701465; c=relaxed/simple; bh=OwEjorOTkfs/la0cu2sQQRm7zCVUZ7YuDMHxjVzSrgo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RHFL1fBlWfu6xnCejkh3T0LVZJvIZ2Efs6s9rR6YIARynuaRuUGBw1qXwMJnTQEIVEIhDpb4iiMwE+MpjCRaDmkokwGeLDRKFr0N4xmLt/I8qogAgH6Fgc2T2KBH+dPxncUVowmQPhhJYz9dOCT/HuOWvE7r5UA3fIqvP6VRs6I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wFihApzm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="wFihApzm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08845C19425; Mon, 20 Apr 2026 16:11:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776701465; bh=OwEjorOTkfs/la0cu2sQQRm7zCVUZ7YuDMHxjVzSrgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wFihApzml/HgzS0MRuO2ZP7crkRvttQJ5glTqb1kaSbRTHEJcnAQwWkGb0IRKQC6Y Xh2KLI1U2m+dMOIPrtf5kJm8sM79t3IpJBxU/63pHzURhKu2aLV45UgQq8wJSiK2hs FwspFuzgcIrICDZWEUcorGaNg3Gkp5lThjpnjmLk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yifan Wu , Juefei Pu , Yuan Tan , Xin Liu , Douya Le , Ren Wei , Herbert Xu , Sasha Levin Subject: [PATCH 6.12 081/162] crypto: af_alg - limit RX SG extraction by receive buffer budget Date: Mon, 20 Apr 2026 17:41:53 +0200 Message-ID: <20260420153929.969960609@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260420153927.006696811@linuxfoundation.org> References: <20260420153927.006696811@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Douya Le [ 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 Reported-by: Juefei Pu Co-developed-by: Yuan Tan Signed-off-by: Yuan Tan Suggested-by: Xin Liu Signed-off-by: Douya Le Signed-off-by: Ren Wei Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/af_alg.c | 2 ++ crypto/algif_skcipher.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 78e995dddf879..0530dc85e4f87 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -1258,6 +1258,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 125d395c5e009..3549ad1cc42e6 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -130,6 +130,11 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg, * full block size buffers. */ if (ctx->more || len < ctx->used) { + if (len < bs) { + err = -EINVAL; + goto free; + } + len -= len % bs; cflags |= CRYPTO_SKCIPHER_REQ_NOTFINAL; } -- 2.53.0