2010-11-10 03:32:04

by wzt wzt

[permalink] [raw]
Subject: [PATCH] APPARMOR: Fix memory leak of alloc_namespace()

policy->name is a substring of policy->hname, if prefix is not NULL, it will
allocted strlen(prefix) + strlen(name) + 3 bytes to policy->hname in policy_init().
use kzfree(ns->base.name) will casue memory leak if alloc_namespace() failed.

Signed-off-by: Zhitong Wang <[email protected]>

---
security/apparmor/policy.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 52cc865..4f0eade 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -306,7 +306,7 @@ static struct aa_namespace *alloc_namespace(const char *prefix,
return ns;

fail_unconfined:
- kzfree(ns->base.name);
+ kzfree(ns->base.hname);
fail_ns:
kzfree(ns);
return NULL;
--
1.6.5.3


2010-11-10 16:51:09

by John Johansen

[permalink] [raw]
Subject: Re: [PATCH] APPARMOR: Fix memory leak of alloc_namespace()

On 11/09/2010 07:31 PM, [email protected] wrote:
> policy->name is a substring of policy->hname, if prefix is not NULL, it will
> allocted strlen(prefix) + strlen(name) + 3 bytes to policy->hname in policy_init().
> use kzfree(ns->base.name) will casue memory leak if alloc_namespace() failed.
>
> Signed-off-by: Zhitong Wang <[email protected]>
yes, thank you.

Signed-off-by: John Johansen <[email protected]>

>
> ---
> security/apparmor/policy.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
> index 52cc865..4f0eade 100644
> --- a/security/apparmor/policy.c
> +++ b/security/apparmor/policy.c
> @@ -306,7 +306,7 @@ static struct aa_namespace *alloc_namespace(const char *prefix,
> return ns;
>
> fail_unconfined:
> - kzfree(ns->base.name);
> + kzfree(ns->base.hname);
> fail_ns:
> kzfree(ns);
> return NULL;