crypto: caam: Add check for kcalloc() in test_len()
Subsystems (3)
PATCH v3 1/1 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.
---
changelog:
v3:
- Fix build error: test_len() returns void; return without a value.
- No functional changes beyond the allocation failure path.
v2:
- Return on allocation failure to avoid possible NULL dereference.
--- drivers/crypto/caam/caamrng.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/crypto/caam/caamrng.c +3 -1
@@ -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);
Signature · 1 line
2.43.0
Herbert Xu
maintainerQuoted 13 lines · Guangshuo Li
As
kcalloc()may fail, check its return value to avoid a NULL pointer dereference when passing the buffer torng->read(). On allocation failure, log the error and return sincetest_len()returns void.Fixes 2be0d806e25e ("crypto: caam - add a test for the RNG")Signed-off-by Guangshuo Li <[email protected]>---
changelog:
v3:
- Fix build error:test_len()returns void; return without a value.
- No functional changes beyond the allocation failure path.
Quoted 5 lines
v2:
- Return on allocation failure to avoid possible NULL dereference.--- drivers/crypto/caam/caamrng.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt