summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJia-Ju Bai <baijiaju1990@gmail.com>2019-07-24 17:43:06 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-09-21 07:18:39 +0200
commit97b1d81abc613a3e6b1caf9565897824ff1fb2a4 (patch)
tree20bf95fd684f34491985adabf4ec0f99d1d9cfa2 /net
parentb8632186884a030da2cd83b2e02645e521ab2bbd (diff)
downloadlinux-stable-97b1d81abc613a3e6b1caf9565897824ff1fb2a4.tar.gz
linux-stable-97b1d81abc613a3e6b1caf9565897824ff1fb2a4.tar.bz2
linux-stable-97b1d81abc613a3e6b1caf9565897824ff1fb2a4.zip
libceph: don't call crypto_free_sync_skcipher() on a NULL tfm
[ Upstream commit e8c99200b4d117c340c392ebd5e62d85dfeed027 ] 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: 69d6302b65a8 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net')
-rw-r--r--net/ceph/crypto.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c
index 5d6724cee38f..4f75df40fb12 100644
--- a/net/ceph/crypto.c
+++ b/net/ceph/crypto.c
@@ -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;
+ }
}
}