The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] crypto: caam: Add check for kcalloc() in test_len()
@ 2025-09-22 15:53 Guangshuo Li
  2025-09-23  9:20 ` kernel test robot
  2025-09-23 10:56 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Guangshuo Li @ 2025-09-22 15:53 UTC (permalink / raw)
  To: Horia Geantă, Pankaj Gupta, Gaurav Jain, Herbert Xu,
	David S. Miller, Victoria Milhoan (b42089), 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().

Fixes: 2be0d806e25e ("crypto: caam - add a test for the RNG")
Cc: stable@vger.kernel.org
---
changelog:
v2:
- Return -ENOMEM directly on allocation failure.

Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/crypto/caam/caamrng.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index b3d14a7f4dd1..357860ee532c 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -182,6 +182,9 @@ 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) {
+		return -ENOMEM;
+	}
 	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-23 10:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 15:53 [PATCH v2] crypto: caam: Add check for kcalloc() in test_len() Guangshuo Li
2025-09-23  9:20 ` kernel test robot
2025-09-23 10:56 ` kernel test robot

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