Skip to content

Commit b674e35

Browse files
lgs2513gregkh
authored andcommitted
crypto: caam - Add check for kcalloc() in test_len()
commit 7cf6e0b upstream. 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: 2be0d80 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 51a5ab3 commit b674e35

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/crypto/caam/caamrng.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ static inline void test_len(struct hwrng *rng, size_t len, bool wait)
181181
struct device *dev = ctx->ctrldev;
182182

183183
buf = kcalloc(CAAM_RNG_MAX_FIFO_STORE_SIZE, sizeof(u8), GFP_KERNEL);
184-
184+
if (!buf) {
185+
return;
186+
}
185187
while (len > 0) {
186188
read_len = rng->read(rng, buf, len, wait);
187189

0 commit comments

Comments
 (0)