Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Weili Qian <qianweili@huawei.com>
To: <herbert@gondor.apana.org.au>
Cc: <linux-kernel@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
	<liulongfang@huawei.com>
Subject: [PATCH 1/7] crypto: hisilicon/hpre - fix pointer dereference before length check
Date: Fri, 18 Sep 2026 20:27:20 +0800	[thread overview]
Message-ID: <20260918122726.3014899-2-qianweili@huawei.com> (raw)
In-Reply-To: <20260918122726.3014899-1-qianweili@huawei.com>

In hpre_rsa_drop_leading_zeros(), the loop condition dereferences *ptr
before checking *len, causing an out-of-bounds read when *len is zero.

Swap to while (*len && !**ptr) to test length first.

Fixes: c8b4b477079d ("crypto: hisilicon - add HiSilicon HPRE accelerator")
Cc: stable@vger.kernel.org
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
 drivers/crypto/hisilicon/hpre/hpre_crypto.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/hisilicon/hpre/hpre_crypto.c b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
index 09077abbf6ad..7894211b9972 100644
--- a/drivers/crypto/hisilicon/hpre/hpre_crypto.c
+++ b/drivers/crypto/hisilicon/hpre/hpre_crypto.c
@@ -720,7 +720,7 @@ static void hpre_dh_exit_tfm(struct crypto_kpp *tfm)
 
 static void hpre_rsa_drop_leading_zeros(const char **ptr, size_t *len)
 {
-	while (!**ptr && *len) {
+	while (*len && !**ptr) {
 		(*ptr)++;
 		(*len)--;
 	}
-- 
2.43.0


  reply	other threads:[~2026-09-18 12:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 12:27 [PATCH 0/7] crypto: hisilicon/hpre - misc fixes and cleanups Weili Qian
2026-09-18 12:27 ` Weili Qian [this message]
2026-09-18 12:27 ` [PATCH 2/7] crypto: hisilicon/hpre - remove dma_free_coherent on NULL req->dst in ECDH Weili Qian
2026-09-18 12:27 ` [PATCH 3/7] crypto: hisilicon/hpre - return -EOVERFLOW for small ECDH output buffer Weili Qian
2026-09-18 12:27 ` [PATCH 4/7] crypto: hisilicon/hpre - fix ECDH destination DMA mapping Weili Qian
2026-09-18 12:27 ` [PATCH 5/7] crypto: hisilicon/hpre - fix GFP flags for dma_alloc_coherent Weili Qian
2026-09-18 12:27 ` [PATCH 6/7] crypto: hisilicon/hpre - extract clusters num into inline function Weili Qian
2026-09-18 12:27 ` [PATCH 7/7] crypto: hisilicon/hpre - remove unused macros and struct fields Weili Qian
2026-09-23  8:51 ` [PATCH 0/7] crypto: hisilicon/hpre - misc fixes and cleanups Herbert Xu

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=20260918122726.3014899-2-qianweili@huawei.com \
    --to=qianweili@huawei.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liulongfang@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