Skip to contentSkip to conversation

Let us not leak memory in SELinux : security_netlbl_cache_add()

PATCH In review Jesper Juhl 2 participants 2 messages Jul 20, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Let us not leak memory in SELinux : security_netlbl_cache_add()

Hi,

Leaking memory is a bad idea, so let's not do it, in security/selinux/ss/services.c::security_netlbl_cache_add().

Note: The Coverity checker gets credit for spotting this one.
Note: Patch has only been compile tested.

---

 security/selinux/ss/services.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
security/selinux/ss/services.c +3 -1
index b5f017f..0ae032f 100644
@@ -2417,8 +2417,10 @@ static void security_netlbl_cache_add(struct netlbl_lsm_secattr *secattr,
 
 	cache->type = NETLBL_CACHE_T_MLS;
 	if (ebitmap_cpy(&cache->data.mls_label.level[0].cat,
-			&ctx->range.level[0].cat) != 0)
+			&ctx->range.level[0].cat) != 0) {
+		kfree(cache);
 		return;
+	}
 	cache->data.mls_label.level[1].cat.highbit =
 		cache->data.mls_label.level[0].cat.highbit;
 	cache->data.mls_label.level[1].cat.node =
#1 lore raw
Quoted 7 lines · Jesper Juhl

Hi,

Leaking memory is a bad idea, so let's not do it, in security/selinux/ss/services.c::security_netlbl_cache_add().

Note: The Coverity checker gets credit for spotting this one.
Note: Patch has only been compile tested.

Thanks!

Verified and applied to:

git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6.git#for-linus

- James

Signature · 2 lines
James Morris
<[email protected]>