]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: caam - Add check for kcalloc() in test_len()
authorGuangshuo Li <lgs201920130244@gmail.com>
Tue, 23 Sep 2025 12:44:18 +0000 (20:44 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 17 Oct 2025 08:03:57 +0000 (16:03 +0800)
As kcalloc() may fail, check its return value to avoid a NULL pointer
dereference when passing the buffer to rng->read(). On allocation
failure, log the error and return since test_len() returns void.

Fixes: 2be0d806e25e ("crypto: caam - add a test for the RNG")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/caam/caamrng.c

index b3d14a7f4dd1470ba3def1243e182883ff777761..0eb43c8625164f48081122471c283951fdd552a1 100644 (file)
@@ -181,7 +181,9 @@ 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);