Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] crypto: caam: Add check for kcalloc() in test_len()
@ 2025-09-18 10:15 Guangshuo Li
  2025-09-18 10:48 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Guangshuo Li @ 2025-09-18 10:15 UTC (permalink / raw)
  To: Horia Geantă, Pankaj Gupta, Gaurav Jain, Herbert Xu,
	David S. Miller, Dan Douglass, Meenakshi Aggarwal, linux-crypto,
	linux-kernel
  Cc: Guangshuo Li, stable

As kcalloc() may fail, check its return value to avoid a NULL pointer
dereference when passing the buffer to rng->read() and
print_hex_dump_debug().

Fixes: 2be0d806e25e ("crypto: caam - add a test for the RNG")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/crypto/caam/caamrng.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index e0adb326f496..d887ecf6f99d 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -183,7 +183,6 @@ static inline void test_len(struct hwrng *rng, size_t len, bool wait)
 	buf = kcalloc(CAAM_RNG_MAX_FIFO_STORE_SIZE, sizeof(u8), GFP_KERNEL);
 
 	if (!buf) {
-		dev_err(dev, "RNG buffer allocation failed\n");
 		return;
 	}
 	while (len > 0) {
-- 
2.43.0


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

* Re: [PATCH] crypto: caam: Add check for kcalloc() in test_len()
  2025-09-18 10:15 [PATCH] crypto: caam: Add check for kcalloc() in test_len() Guangshuo Li
@ 2025-09-18 10:48 ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2025-09-18 10:48 UTC (permalink / raw)
  To: Guangshuo Li
  Cc: Horia Geantă, Pankaj Gupta, Gaurav Jain, Herbert Xu,
	David S. Miller, Dan Douglass, Meenakshi Aggarwal, linux-crypto,
	linux-kernel, stable

On Thu, Sep 18, 2025 at 06:15:27PM +0800, Guangshuo Li wrote:
> As kcalloc() may fail, check its return value to avoid a NULL pointer
> dereference when passing the buffer to rng->read() and
> print_hex_dump_debug().

But that is not what this patch does :(

> Fixes: 2be0d806e25e ("crypto: caam - add a test for the RNG")
> Cc: stable@vger.kernel.org

No need for stable here.

> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  drivers/crypto/caam/caamrng.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> index e0adb326f496..d887ecf6f99d 100644
> --- a/drivers/crypto/caam/caamrng.c
> +++ b/drivers/crypto/caam/caamrng.c
> @@ -183,7 +183,6 @@ static inline void test_len(struct hwrng *rng, size_t len, bool wait)
>  	buf = kcalloc(CAAM_RNG_MAX_FIFO_STORE_SIZE, sizeof(u8), GFP_KERNEL);
>  
>  	if (!buf) {
> -		dev_err(dev, "RNG buffer allocation failed\n");
>  		return;
>  	}

checkpatch should show that you can remove the { } now, right?

thanks,

greg k-h

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

* [PATCH] crypto: caam: Add check for kcalloc() in test_len()
@ 2025-09-18 12:55 Guangshuo Li
  0 siblings, 0 replies; 3+ messages in thread
From: Guangshuo Li @ 2025-09-18 12:55 UTC (permalink / raw)
  To: Horia Geantă, Pankaj Gupta, Gaurav Jain, Herbert Xu,
	David S. Miller, Meenakshi Aggarwal, Dan Douglass, linux-crypto,
	linux-kernel
  Cc: Guangshuo Li, stable

As kcalloc() may fail, check its return value to avoid a NULL pointer
dereference when passing the buffer to rng->read() and
print_hex_dump_debug().

Fixes: 2be0d806e25e ("crypto: caam - add a test for the RNG")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/crypto/caam/caamrng.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index b3d14a7f4dd1..003c5e37acbe 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -181,7 +181,8 @@ static inline void test_len(struct hwrng *rng, size_t len, bool wait)
 	struct device *dev = ctx->ctrldev;
 
 	buf = kcalloc(CAAM_RNG_MAX_FIFO_STORE_SIZE, sizeof(u8), GFP_KERNEL);
-
+	if (!buf)
+		return;
 	while (len > 0) {
 		read_len = rng->read(rng, buf, len, wait);
 
-- 
2.43.0


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

end of thread, other threads:[~2025-09-18 12:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 10:15 [PATCH] crypto: caam: Add check for kcalloc() in test_len() Guangshuo Li
2025-09-18 10:48 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2025-09-18 12:55 Guangshuo Li

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