public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] crypto: stm32: Check for NULL return of kmalloc_array()
@ 2022-03-24  9:38 QintaoShen
  2022-03-25  4:16 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: QintaoShen @ 2022-03-24  9:38 UTC (permalink / raw)
  To: herbert; +Cc: davem, linux-crypto, linux-kernel, QintaoShen

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-25  4:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-24  9:38 [PATCH v1] crypto: stm32: Check for NULL return of kmalloc_array() QintaoShen
2022-03-25  4:16 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox