Skip to content

Commit

Permalink
libceph: don't call crypto_free_sync_skcipher() on a NULL tfm
Browse files Browse the repository at this point in the history
In set_secret(), key->tfm is assigned to NULL on line 55, and then
ceph_crypto_key_destroy(key) is executed.

ceph_crypto_key_destroy(key)
  crypto_free_sync_skcipher(key->tfm)
    crypto_free_skcipher(&tfm->base);

This happens to work because crypto_sync_skcipher is a trivial wrapper
around crypto_skcipher: &tfm->base is still 0 and crypto_free_skcipher()
handles that.  Let's not rely on the layout of crypto_sync_skcipher.

This bug is found by a static analysis tool STCheck written by us.

Fixes: 69d6302 ("libceph: Remove VLA usage of skcipher").
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
  • Loading branch information
Jia-Ju Bai authored and Ilya Dryomov committed Aug 28, 2019
1 parent a55aa89 commit e8c9920
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions net/ceph/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ void ceph_crypto_key_destroy(struct ceph_crypto_key *key)
if (key) {
kfree(key->key);
key->key = NULL;
crypto_free_sync_skcipher(key->tfm);
key->tfm = NULL;
if (key->tfm) {
crypto_free_sync_skcipher(key->tfm);
key->tfm = NULL;
}
}
}

Expand Down

0 comments on commit e8c9920

Please sign in to comment.