crypto: api - check for ERR pointers in crypto_destroy_tfm()
PATCH v3 1/1 crypto: api - check for ERR pointers in crypto_destroy_tfm()
Given that crypto_alloc_tfm() may return ERR pointers, and to avoid crashes on obscure error paths where such pointers are presented to crypto_destroy_tfm() (such as [0]), add an ERR_PTR check there before dereferencing the second argument as a struct crypto_tfm pointer.
[0] https://lore.kernel.org/linux-crypto/[email protected]/
---
v3: missed crypto_free_shash() in v2
add Eric's Rb
v2: update kerneldoc comments of callers to crypto_destroy_tfm() that NULL or
error pointers are ignored.
crypto/api.c | 2 +- include/crypto/acompress.h | 2 ++ include/crypto/aead.h | 2 ++ include/crypto/akcipher.h | 2 ++ include/crypto/hash.h | 4 ++++ include/crypto/kpp.h | 2 ++ include/crypto/rng.h | 2 ++ include/crypto/skcipher.h | 2 ++ 8 files changed, 17 insertions(+), 1 deletion(-)
crypto/api.c +1 -1
@@ -562,7 +562,7 @@ void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm) {struct crypto_alg *alg; -if (unlikely (!mem)) +if (IS_ERR_OR_NULL (mem))return ; alg = tfm->__crt_alg;
include/crypto/acompress.h +2 -0
@@ -165,6 +165,8 @@ static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req)* crypto_free_acomp() -- free ACOMPRESS tfm handle * * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp() +* +* If @tfm is a NULL or error pointer, this function does nothing. */ static inline void crypto_free_acomp (struct crypto_acomp *tfm) {
include/crypto/aead.h +2 -0
@@ -185,6 +185,8 @@ static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm)/** * crypto_free_aead() - zeroize and free aead handle * @tfm: cipher handle to be freed +* +* If @tfm is a NULL or error pointer, this function does nothing. */ static inline void crypto_free_aead (struct crypto_aead *tfm) {
include/crypto/akcipher.h +2 -0
@@ -174,6 +174,8 @@ static inline struct crypto_akcipher *crypto_akcipher_reqtfm(* crypto_free_akcipher() - free AKCIPHER tfm handle * * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher() +* +* If @tfm is a NULL or error pointer, this function does nothing. */ static inline void crypto_free_akcipher (struct crypto_akcipher *tfm) {
include/crypto/hash.h +4 -0
@@ -281,6 +281,8 @@ static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm)/** * crypto_free_ahash() - zeroize and free the ahash handle * @tfm: cipher handle to be freed +* +* If @tfm is a NULL or error pointer, this function does nothing. */ static inline void crypto_free_ahash (struct crypto_ahash *tfm) {
@@ -724,6 +726,8 @@ static inline struct crypto_tfm *crypto_shash_tfm(struct crypto_shash *tfm)/** * crypto_free_shash() - zeroize and free the message digest handle * @tfm: cipher handle to be freed +* +* If @tfm is a NULL or error pointer, this function does nothing. */ static inline void crypto_free_shash (struct crypto_shash *tfm) {
include/crypto/kpp.h +2 -0
@@ -154,6 +154,8 @@ static inline void crypto_kpp_set_flags(struct crypto_kpp *tfm, u32 flags)* crypto_free_kpp() - free KPP tfm handle * * @tfm: KPP tfm handle allocated with crypto_alloc_kpp() +* +* If @tfm is a NULL or error pointer, this function does nothing. */ static inline void crypto_free_kpp (struct crypto_kpp *tfm) {
include/crypto/rng.h +2 -0
@@ -111,6 +111,8 @@ static inline struct rng_alg *crypto_rng_alg(struct crypto_rng *tfm)/** * crypto_free_rng() - zeroize and free RNG handle * @tfm: cipher handle to be freed +* +* If @tfm is a NULL or error pointer, this function does nothing. */ static inline void crypto_free_rng (struct crypto_rng *tfm) {
include/crypto/skcipher.h +2 -0
@@ -196,6 +196,8 @@ static inline struct crypto_tfm *crypto_skcipher_tfm(/** * crypto_free_skcipher() - zeroize and free cipher handle * @tfm: cipher handle to be freed +* +* If @tfm is a NULL or error pointer, this function does nothing. */ static inline void crypto_free_skcipher (struct crypto_skcipher *tfm) {
Signature · 1 line
2.30.1
Herbert Xu
maintainerQuoted 17 lines · Ard Biesheuvel
Given that
crypto_alloc_tfm()may return ERR pointers, and to avoid crashes on obscure error paths where such pointers are presented tocrypto_destroy_tfm()(such as [0]), add anERR_PTRcheck there before dereferencing the second argument as a structcrypto_tfmpointer.[0] https://lore.kernel.org/linux-crypto/[email protected]/
Reported-by [email protected]Reviewed-by Eric Biggers <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>---
v3: missedcrypto_free_shash()in v2
add Eric's Rb
v2: update kerneldoc comments of callers tocrypto_destroy_tfm()that NULL or
error pointers are ignored.
Quoted 9 lines
crypto/api.c | 2 +- include/crypto/acompress.h | 2 ++ include/crypto/aead.h | 2 ++ include/crypto/akcipher.h | 2 ++ include/crypto/hash.h | 4 ++++ include/crypto/kpp.h | 2 ++ include/crypto/rng.h | 2 ++ include/crypto/skcipher.h | 2 ++ 8 files changed, 17 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