diff mbox series

[Bionic] UBUNTU: SAUCE: apparmor: fix memory leak when duplicate profile load

Message ID d8171038-8691-94a2-abab-a218c0f62513@canonical.com
State New
Headers show
Series [Bionic] UBUNTU: SAUCE: apparmor: fix memory leak when duplicate profile load | expand

Commit Message

John Johansen April 14, 2018, 5:52 a.m. UTC
AppArmor is leaking the newly loaded profile and its proxy when
the profile is an exact match to the currently loaded version.

In this case the match check results in the profile being skipped
and put with out dealing with the proxy and forwarding thus creating
a circular refcount and a leak.

BugLink: http://bugs.launchpad.net/bugs/1750594
Signed-off-by: John Johansen <john.johansen@canonical.com>
---
 security/apparmor/policy.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Seth Forshee April 16, 2018, 1:37 p.m. UTC | #1
On Fri, Apr 13, 2018 at 10:52:58PM -0700, John Johansen wrote:
> AppArmor is leaking the newly loaded profile and its proxy when
> the profile is an exact match to the currently loaded version.
> 
> In this case the match check results in the profile being skipped
> and put with out dealing with the proxy and forwarding thus creating
> a circular refcount and a leak.
> 
> BugLink: http://bugs.launchpad.net/bugs/1750594
> Signed-off-by: John Johansen <john.johansen@canonical.com>

Acked-by: Seth Forshee <seth.forshee@canonical.com>
Tyler Hicks April 16, 2018, 6:24 p.m. UTC | #2
On 04/14/2018 12:52 AM, John Johansen wrote:
> AppArmor is leaking the newly loaded profile and its proxy when
> the profile is an exact match to the currently loaded version.
> 
> In this case the match check results in the profile being skipped
> and put with out dealing with the proxy and forwarding thus creating
> a circular refcount and a leak.
> 
> BugLink: http://bugs.launchpad.net/bugs/1750594
> Signed-off-by: John Johansen <john.johansen@canonical.com>

This looks correct to me. aa_replace_profiles() calls aa_unpack() ->
unpack_profile() -> aa_alloc_profile() -> aa_get_proxy() so calling
aa_put_proxy() in this short circuit makes sense.

Acked-by: Tyler Hicks <tyhicks@canonical.com>

Tyler

> ---
>  security/apparmor/policy.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
> index b0b58848c248..a92c167c9249 100644
> --- a/security/apparmor/policy.c
> +++ b/security/apparmor/policy.c
> @@ -1003,6 +1003,9 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,
>  			audit_policy(label, op, ns_name, ent->new->base.hname,
>  				     "same as current profile, skipping",
>  				     error);
> +			/* break refcount cycle with proxy. */
> +			aa_put_proxy(ent->new->label.proxy);
> +			ent->new->label.proxy = NULL;
>  			goto skip;
>  		}
>  
>
Seth Forshee April 16, 2018, 7:10 p.m. UTC | #3
On Fri, Apr 13, 2018 at 10:52:58PM -0700, John Johansen wrote:
> AppArmor is leaking the newly loaded profile and its proxy when
> the profile is an exact match to the currently loaded version.
> 
> In this case the match check results in the profile being skipped
> and put with out dealing with the proxy and forwarding thus creating
> a circular refcount and a leak.
> 
> BugLink: http://bugs.launchpad.net/bugs/1750594
> Signed-off-by: John Johansen <john.johansen@canonical.com>

Applied to bionic/master-next, thanks!
diff mbox series

Patch

diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index b0b58848c248..a92c167c9249 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -1003,6 +1003,9 @@  ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,
 			audit_policy(label, op, ns_name, ent->new->base.hname,
 				     "same as current profile, skipping",
 				     error);
+			/* break refcount cycle with proxy. */
+			aa_put_proxy(ent->new->label.proxy);
+			ent->new->label.proxy = NULL;
 			goto skip;
 		}