mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
crypto: api - check for ERR pointers in crypto_destroy_tfm()
[ Upstream commit 83681f2beb
]
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/000000000000de949705bc59e0f6@google.com/
Reported-by: syzbot+12cf5fbfdeba210a89dd@syzkaller.appspotmail.com
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
c0e5510b5a
commit
417ec24258
@ -567,7 +567,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;
|
||||
|
@ -152,6 +152,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)
|
||||
{
|
||||
|
@ -187,6 +187,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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -253,6 +253,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)
|
||||
{
|
||||
@ -689,6 +691,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)
|
||||
{
|
||||
|
@ -159,6 +159,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)
|
||||
{
|
||||
|
@ -116,6 +116,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)
|
||||
{
|
||||
|
@ -206,6 +206,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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user