From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Zhiqi Song <songzhiqi1@huawei.com>,
Longfang Liu <liulongfang@huawei.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Weili Qian <qianweili@huawei.com>, Zaibo Xu <xuzaibo@huawei.com>,
Meng Yu <yumeng18@huawei.com>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 05/10] crypto: hisilicon/hpre - Fix buffer overflow on odd ECDH input size
Date: Mon, 23 Nov 2026 15:09:56 +0000 [thread overview]
Message-ID: <20261123151055.2533735-6-lee@kernel.org> (raw)
In-Reply-To: <20261123151055.2533735-1-lee@kernel.org>
hpre_ecdh_src_data_init() validates the input public key length using
ctx->key_sz - (len >> 1) < 0 before copying len bytes into the upper
half (offset ctx->key_sz << 1) of a (ctx->key_sz << 2)-byte coherent
DMA buffer.
Because len >> 1 truncates the least significant bit, an odd input
length of (ctx->key_sz << 1) + 1 (such as 65 bytes for NIST P-256)
evaluates shift to 0, bypasses the bounds check, and writes one byte
past the end of the coherent DMA allocation in
scatterwalk_map_and_copy(). A zero length when ctx->key_sz is unset
similarly bypasses the check.
Reject zero, odd, or oversized lengths explicitly before computing the
coordinate offset.
Fixes: 05e7b906aa7c ("crypto: hisilicon/hpre - add 'ECDH' algorithm")
Closes: https://sashiko.dev/#/bug/linux-42c6cdd1-7f7e-4071-bb2f-a4db5935267e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/crypto/hisilicon/hpre/hpre_crypto.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/hisilicon/hpre/hpre_crypto.c b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
index 66a276786a7d..78ae987d338a 100644
--- a/drivers/crypto/hisilicon/hpre/hpre_crypto.c
+++ b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
@@ -1484,9 +1484,10 @@ static int hpre_ecdh_src_data_init(struct hpre_asym_request *hpre_req,
int shift;
/* Src_data include gx and gy. */
+ if (unlikely(!len || (len & 1) || len > (ctx->key_sz << 1)))
+ return -EINVAL;
+
shift = ctx->key_sz - (len >> 1);
- if (unlikely(shift < 0))
- return -EINVAL;
ptr = dma_alloc_coherent(dev, ctx->key_sz << 2, &dma, gfp);
if (unlikely(!ptr))
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 15:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261123151055.2533735-1-lee@kernel.org>
2026-11-23 15:09 ` [PATCH 01/10] crypto: caam - Fix descriptor buffer overflow in caam_process_blob() Lee Jones
2026-11-23 15:09 ` [PATCH 02/10] crypto: marvell - Fix AEAD key buffer overflow for SHA-384/512 HMAC Lee Jones
2026-11-23 15:09 ` [PATCH 03/10] crypto: nx - Fix bounce buffer copy overflow in decompress() Lee Jones
2026-11-23 15:09 ` [PATCH 04/10] crypto: sun8i-ss - Fix scatterlist array overflow for HMAC requests Lee Jones
2026-11-23 15:09 ` Lee Jones [this message]
2026-11-23 15:09 ` [PATCH 06/10] crypto: talitos - Remove duplicate IV unmap in AEAD encrypt path Lee Jones
2026-11-23 15:09 ` [PATCH 07/10] crypto: safexcel - Check scatterlist errors before max() for in-place Lee Jones
2026-11-23 15:09 ` [PATCH 08/10] crypto: qce - Pass mapped scatterlist count to qce_dma_prep_sgs() Lee Jones
2026-11-23 15:10 ` [PATCH 09/10] crypto: qce - Terminate RX DMA channel if TX preparation fails Lee Jones
2026-11-23 15:10 ` [PATCH 10/10] crypto: atmel-tdes - Update output IV before clearing busy flag Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123151055.2533735-6-lee@kernel.org \
--to=lee@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=qianweili@huawei.com \
--cc=songzhiqi1@huawei.com \
--cc=stable@vger.kernel.org \
--cc=xuzaibo@huawei.com \
--cc=yumeng18@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox