From: QintaoShen <unSimple1993@163.com>
To: herbert@gondor.apana.org.au
Cc: davem@davemloft.net, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, QintaoShen <unSimple1993@163.com>
Subject: [PATCH v1] crypto: stm32: Check for NULL return of kmalloc_array()
Date: Thu, 24 Mar 2022 17:38:12 +0800 [thread overview]
Message-ID: <1648114692-11175-1-git-send-email-unSimple1993@163.com> (raw)
As the potential failure of memory allocation, kmalloc_array() may return
NULL and lead to NULL pointer dereference because of the usage of 'rctx->hw_context'.
Therefore, it is better to check the return value of kmalloc_array().
Signed-off-by: QintaoShen <unSimple1993@163.com>
---
drivers/crypto/stm32/stm32-hash.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c
index d33006d..f1a1a13 100644
--- a/drivers/crypto/stm32/stm32-hash.c
+++ b/drivers/crypto/stm32/stm32-hash.c
@@ -970,7 +970,8 @@ static int stm32_hash_export(struct ahash_request *req, void *out)
rctx->hw_context = kmalloc_array(3 + HASH_CSR_REGISTER_NUMBER,
sizeof(u32),
GFP_KERNEL);
-
+ if (!rctx->hw_context)
+ return -ENOMEM;
preg = rctx->hw_context;
*preg++ = stm32_hash_read(hdev, HASH_IMR);
--
2.7.4
next reply other threads:[~2022-03-24 9:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-24 9:38 QintaoShen [this message]
2022-03-25 4:16 ` [PATCH v1] crypto: stm32: Check for NULL return of kmalloc_array() 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=1648114692-11175-1-git-send-email-unSimple1993@163.com \
--to=unsimple1993@163.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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