crypto: sun8i-ce - Use kcalloc() instead of kzalloc()
PATCH 1/1 crypto: sun8i-ce - Use kcalloc() instead of kzalloc()
As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
So, use the purpose specific kcalloc() function instead of the argument size * count in the kzalloc() function.
--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +1 -1
@@ -362,7 +362,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) digestsize =SHA512_DIGEST_SIZE ;/* the padding could be up to two block. */ - buf =kzalloc (bs *2 ,GFP_KERNEL |GFP_DMA ); + buf =kcalloc (2 , bs,GFP_KERNEL |GFP_DMA );if (!buf) { err = -ENOMEM ; goto theend;
--
2.25.1
Quoted 8 lines · Erick Archer
As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
Quoted 6 lines
So, use the purpose specific
kcalloc()function instead of the argument size * count in thekzalloc()function.
Thanks!
Signature · 1 line
Gustavo
Quoted 20 lines
--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c +1
-2@@ -362,7 +362,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) digestsize =SHA512_DIGEST_SIZE ;/* the padding could be up to two block. */ - buf =kzalloc (bs *2 ,GFP_KERNEL |GFP_DMA ); + buf =kcalloc (2 , bs,GFP_KERNEL |GFP_DMA );if (!buf) { err = -ENOMEM ; goto theend; --2.25.1
Dne nedelja, 21. januar 2024 ob 16:34:07 CET je Erick Archer napisal(a):
Quoted 8 lines
As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
Quoted 6 lines
So, use the purpose specific
kcalloc()function instead of the argument size * count in thekzalloc()function.
Best regards,
Jernej
Herbert Xu
maintainerQuoted 11 lines · Erick Archer
As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors.
So, use the purpose specific
kcalloc()function instead of the argument size * count in thekzalloc()function.
Quoted 6 lines
Signed-off-by Erick Archer <[email protected]>--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 2 +- 1 file changed, 1 insertion(+), 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