Skip to content

Commit f0666b1

Browse files
smunautSage Weil
authored andcommitted
libceph: fix crypto key null deref, memory leak
Avoid crashing if the crypto key payload was NULL, as when it was not correctly allocated and initialized. Also, avoid leaking it. Signed-off-by: Sylvain Munaut <tnt@246tNt.com> Signed-off-by: Sage Weil <sage@inktank.com> Reviewed-by: Alex Elder <elder@inktank.com>
1 parent 5ef50c3 commit f0666b1

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

‎net/ceph/crypto.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ void ceph_key_destroy(struct key *key) {
466466
struct ceph_crypto_key *ckey = key->payload.data;
467467

468468
ceph_crypto_key_destroy(ckey);
469+
kfree(ckey);
469470
}
470471

471472
struct key_type key_type_ceph = {

‎net/ceph/crypto.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ struct ceph_crypto_key {
1616

1717
static inline void ceph_crypto_key_destroy(struct ceph_crypto_key *key)
1818
{
19-
kfree(key->key);
19+
if (key)
20+
kfree(key->key);
2021
}
2122

2223
extern int ceph_crypto_key_clone(struct ceph_crypto_key *dst,

0 commit comments

Comments
 (0)