FAILED: patch "[PATCH] crypto: qat - validate RSA CRT component lengths" failed to apply to 5.10-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x b3ac78756588059729b9195fcc9f4b37d54057a5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071550-slacking-pants-3db9@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From b3ac78756588059729b9195fcc9f4b37d54057a5 Mon Sep 17 00:00:00 2001
From: Giovanni Cabiddu <[email protected]>
Date: Thu, 28 May 2026 16:57:44 +0100
Subject: [PATCH] crypto: qat - validate RSA CRT component lengths
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.
drivers/crypto/intel/qat/qat_common/qat_asym_algs.c +5 -5
@@ -1085,7 +1085,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)
@@ -1096,7 +1096,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)
@@ -1107,7 +1107,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 );
@@ -1119,7 +1119,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 );
@@ -1131,7 +1131,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 );
Sasha Levin
maintainerPATCH 1/1 crypto: qat - validate RSA CRT component lengths
From: Giovanni Cabiddu <[email protected]>
[ 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.
--- drivers/crypto/qat/qat_common/qat_asym_algs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/crypto/qat/qat_common/qat_asym_algs.c +5 -5
@@ -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 );
Signature · 1 line
2.53.0