Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: caam - Add check for kcalloc() in test_len()

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>

authored by

Guangshuo Li and committed by
Herbert Xu
7cf6e0b6 59682835

+3 -1
+3 -1
drivers/crypto/caam/caamrng.c
··· 181 181 struct device *dev = ctx->ctrldev; 182 182 183 183 buf = kcalloc(CAAM_RNG_MAX_FIFO_STORE_SIZE, sizeof(u8), GFP_KERNEL); 184 - 184 + if (!buf) { 185 + return; 186 + } 185 187 while (len > 0) { 186 188 read_len = rng->read(rng, buf, len, wait); 187 189