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 97262171AF for ; Tue, 21 Jul 2026 01:27:57 +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=1784597278; cv=none; b=E5qItUZa60IztEyzbZgZnq4lsIYTypvMSVu//PJ6SiXvIonpygTFGxsEgvoyyjj/HEfy8Y7rdedlcFNNfZKp69zKBQ7lWkqLCHNfcuUFT30r8N1TcUORPOYjBtQ0hSjczhTb7fSG5OAuckTjWq3J+WvZU7LVAbIkkERCw77sCxs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784597278; c=relaxed/simple; bh=fQ8r+WbeDDTWfDE6J5Li+XE6kUQKrG7zx/84okWEFRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qnI2wnwgeyv1SxIxJ4QCi6NMCq8Yn1A3m8QhWKNmCYsjFrDrHfuhT4tCmFstYj7PGiDR2AVhiuJumuUGbt/Zzf7HFJuHHGssgtSqn6hb4wG/XqILzfKLuXvabk3ysNubnnjIc8wObGBaq/eXD7qI6ggbWcF+wfrvgzJhWpTmTxE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jqWg8aBB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jqWg8aBB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 969501F000E9; Tue, 21 Jul 2026 01:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784597277; bh=FCXuljHWPYTbFtlXX8blkJOSxMwiVs6cXvyW57mklG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jqWg8aBBB/5TGClqOZc0G4rL9H+7xB4vgiKmkQfpVeNerYsJmjY1vR7kLZnzkSybN J+DLjyLHAdkGTwuCeIRIS5DLeBIKJ4RWr4DwlDtNEqFk5GdDWNop1I65etA24C7iro cIRd77oOW55BuuC7hn5rCZiy2qqD+XxeO+YX5RKSfY+pOMp6VDLooKfW/nqX5B7fWw Klpm4/Lva2WFEZ6vAPxtaHhdwhSEbkHe2W6fgD2pbby4AW8VKS3OQJ/SVCGk0EgQNI ElPb9Ri1o7FYyCsuw1M/NsDHajJG1D0nIWaY8NFZw2m0n4+PXLDYkwG2oOpcqWp5Zj wiVVOuKl5YzWg== From: Sasha Levin To: stable@vger.kernel.org Cc: Giovanni Cabiddu , Ahsan Atta , Laurent M Coquerel , Herbert Xu , Sasha Levin Subject: [PATCH 5.10.y] crypto: qat - validate RSA CRT component lengths Date: Mon, 20 Jul 2026 21:27:55 -0400 Message-ID: <20260721012755.3458522-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026071550-slacking-pants-3db9@gregkh> References: <2026071550-slacking-pants-3db9@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto/qat/qat_common/qat_asym_algs.c index 846569ec906653..63e55698384559 100644 --- 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 qat_rsa_ctx *ctx, struct rsa_key *rsa_key) 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 qat_rsa_ctx *ctx, struct rsa_key *rsa_key) 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 qat_rsa_ctx *ctx, struct rsa_key *rsa_key) 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 qat_rsa_ctx *ctx, struct rsa_key *rsa_key) 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 qat_rsa_ctx *ctx, struct rsa_key *rsa_key) 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); -- 2.53.0