Skip to contentSkip to conversation

tipc: fixed possible memory leak issue

PATCH In review Ameer Hamza 1 participant 2 messages Dec 3, 2021 – Dec 4, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tipc: fixed possible memory leak issue

Fixed coverity warning by freeing the memory before return

Addresses-Coverity: 1494433 ("Resource leak")

---
 net/tipc/crypto.c | 1 +
 1 file changed, 1 insertion(+)
net/tipc/crypto.c +1 -0
index b4d9419a015b..10e6d0e9ddbc 100644
@@ -599,6 +599,7 @@ static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
 	tmp->key = kmemdup(ukey, tipc_aead_key_size(ukey), GFP_KERNEL);
 	if (!tmp->key) {
 		tipc_aead_free(&tmp->rcu);
+		kfree_sensitive(tmp);
 		return -ENOMEM;
 	}
 	memcpy(&tmp->salt, ukey->key + keylen, TIPC_AES_GCM_SALT_SIZE);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 24 lines · Ameer Hamza

Fixed coverity warning by freeing the memory before return

Addresses-Coverity: 1494433 ("Resource leak")

---
 net/tipc/crypto.c | 1 +
 1 file changed, 1 insertion(+)
net/tipc/crypto.c +1 -0
index b4d9419a015b..10e6d0e9ddbc 100644
@@ -599,6 +599,7 @@ static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
 	tmp->key = kmemdup(ukey, tipc_aead_key_size(ukey), GFP_KERNEL);
 	if (!tmp->key) {
 		tipc_aead_free(&tmp->rcu);
+		kfree_sensitive(tmp);
 		return -ENOMEM;
 	}
 	memcpy(&tmp->salt, ukey->key + keylen, TIPC_AES_GCM_SALT_SIZE);
Signature · 1 line
2.25.1

I reviewed this change again and coverity is generating a false positive here. tipc_aead_free() is already releasing the allocated memory for tmp. Please ignore this patch and sorry for the inconvinience.