From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 F04DE403EA1; Tue, 21 Jul 2026 23:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784674864; cv=none; b=Q6HBl66WQFOlq37Ul41EwmQzVI/Igg4kkWEK3Yf1oC+4ko2kQ22eBIaqUbsKt4J7vDTeOqQuMCJagDuVqU0+OnKmNuazuHA1alUu5u/IZZikht7R6s0B7wda3juOaA0DLNtzgELARCf1iJOteSwna84WMB3xk1TJg5CEuqI0n/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784674864; c=relaxed/simple; bh=S3lQx7mSzh410KFjMBzDvkTLuLa/EKdQgOChMgYLNxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VwXTOSNgAj5KcYFMn623SaKj1aIBhWboET2WZZpRfEgKZXdcj5uSdo+OP7H4AD5jGxemlgEnUCrKSCKFuosPLztn8TUAHZXqlk2YHDI58O2IJcJ4cyiPKlDdtK3UsIzy3Dd+9NVw7Rjfa+mVc+MbDJIe91hUtOiWg+nNo79CMa0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QqhAk0YO; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="QqhAk0YO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C0151F000E9; Tue, 21 Jul 2026 23:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784674862; bh=u/WYdVc1g+6Q62HFn48N1R5s4wohWZJwDpzRaf6etR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QqhAk0YOIWv7H2cinQVVJt91ph5LY53B7DbtS7Uo4jz1b12DIfoSsc0MmI0wRCDBJ wXpvn5RV0qOOqWWfSNM7uQrBRJQpTkVfXuMQdX8mahMpA7tcsTeMW02hdLi35rb05W M5l8QmlNEjMXMs8sKabqInZY2ys8hISTT3B8o71I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Giovanni Cabiddu , Ahsan Atta , Laurent M Coquerel , Herbert Xu , Sasha Levin Subject: [PATCH 5.10 682/699] crypto: qat - validate RSA CRT component lengths Date: Tue, 21 Jul 2026 17:27:21 +0200 Message-ID: <20260721152411.158112345@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152355.667394603@linuxfoundation.org> References: <20260721152355.667394603@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Giovanni Cabiddu [ Upstream commit b3ac78756588059729b9195fcc9f4b37d54057a5 ] The generic RSA key parser (rsa_helper.c) bounds each CRT component (p, q, dp, dq, qinv) by the modulus size n_sz, but qat_rsa_setkey_crt() allocates half-size DMA buffers (key_sz / 2) and right-aligns each component with: memcpy(dst + half_key_sz - len, src, len) When a CRT component is larger than half_key_sz the subtraction underflows and memcpy writes past the DMA buffer, causing memory corruption. Add a len > half_key_sz check next to the existing !len check for each of the five CRT components so the driver falls back to the non-CRT path instead of writing out of bounds. Fixes: 879f77e9071f ("crypto: qat - Add RSA CRT mode") Cc: stable@vger.kernel.org Signed-off-by: Giovanni Cabiddu Reviewed-by: Ahsan Atta Reviewed-by: Laurent M Coquerel Tested-by: Laurent M Coquerel Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -1030,7 +1030,7 @@ static void qat_rsa_setkey_crt(struct qa ptr = rsa_key->p; len = rsa_key->p_sz; qat_rsa_drop_leading_zeros(&ptr, &len); - if (!len) + if (!len || len > half_key_sz) goto err; ctx->p = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_p, GFP_KERNEL); if (!ctx->p) @@ -1041,7 +1041,7 @@ static void qat_rsa_setkey_crt(struct qa ptr = rsa_key->q; len = rsa_key->q_sz; qat_rsa_drop_leading_zeros(&ptr, &len); - if (!len) + if (!len || len > half_key_sz) goto free_p; ctx->q = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_q, GFP_KERNEL); if (!ctx->q) @@ -1052,7 +1052,7 @@ static void qat_rsa_setkey_crt(struct qa ptr = rsa_key->dp; len = rsa_key->dp_sz; qat_rsa_drop_leading_zeros(&ptr, &len); - if (!len) + if (!len || len > half_key_sz) goto free_q; ctx->dp = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_dp, GFP_KERNEL); @@ -1064,7 +1064,7 @@ static void qat_rsa_setkey_crt(struct qa ptr = rsa_key->dq; len = rsa_key->dq_sz; qat_rsa_drop_leading_zeros(&ptr, &len); - if (!len) + if (!len || len > half_key_sz) goto free_dp; ctx->dq = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_dq, GFP_KERNEL); @@ -1076,7 +1076,7 @@ static void qat_rsa_setkey_crt(struct qa ptr = rsa_key->qinv; len = rsa_key->qinv_sz; qat_rsa_drop_leading_zeros(&ptr, &len); - if (!len) + if (!len || len > half_key_sz) goto free_dq; ctx->qinv = dma_alloc_coherent(dev, half_key_sz, &ctx->dma_qinv, GFP_KERNEL);