linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2] apparmor: fix potential label refcnt leak in aa_change_profile
@ 2020-04-15 11:27 Markus Elfring
  2020-04-15 18:41 ` John Johansen
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2020-04-15 11:27 UTC (permalink / raw)
  To: Xiyu Yang, Xin Tan, linux-security-module
  Cc: linux-kernel, James Morris, John Johansen, Kangjie Lu,
	Serge E. Hallyn, Yuan Zhang

> According to the comment of aa_get_current_label(), …

I suggest to make this wording clearer.
Would you like to refer to any software documentation here?


> However, when the original object pointed by "label" becomes
> unreachable because aa_change_profile() returns or a new object
> is assigned to "label", reference count increased by
> aa_get_current_label() is not decreased, causing a refcnt leak.

How do you think about to reduce abbreviations in the commit message?

Would you like to add the tag “Fixes” to the change description?

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] apparmor: fix potential label refcnt leak in aa_change_profile
  2020-04-15 11:27 [PATCH v2] apparmor: fix potential label refcnt leak in aa_change_profile Markus Elfring
@ 2020-04-15 18:41 ` John Johansen
  0 siblings, 0 replies; 3+ messages in thread
From: John Johansen @ 2020-04-15 18:41 UTC (permalink / raw)
  To: Markus Elfring, Xiyu Yang, Xin Tan, linux-security-module
  Cc: linux-kernel, James Morris, Kangjie Lu, Serge E. Hallyn, Yuan Zhang

On 4/15/20 4:27 AM, Markus Elfring wrote:
>> According to the comment of aa_get_current_label(), …
> 
> I suggest to make this wording clearer.
> Would you like to refer to any software documentation here?
> 
> 
>> However, when the original object pointed by "label" becomes
>> unreachable because aa_change_profile() returns or a new object
>> is assigned to "label", reference count increased by
>> aa_get_current_label() is not decreased, causing a refcnt leak.
> 
> How do you think about to reduce abbreviations in the commit message?
> 
> Would you like to add the tag “Fixes” to the change description?
> 
Fixes tags are always nice to have filled out, but some times its
hard to determine or the patch submitter doesn't know how or ...
If the fixes tags aren't there I will add them before I push them up.
In this case its

Fixes: 9fcf78cca198 ("apparmor: update domain transitions that are subsets of confinement at nnp")

> Regards,
> Markus
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] apparmor: fix potential label refcnt leak in aa_change_profile
@ 2020-04-05  5:11 Xiyu Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Xiyu Yang @ 2020-04-05  5:11 UTC (permalink / raw)
  To: John Johansen, James Morris, Serge E. Hallyn,
	linux-security-module, linux-kernel
  Cc: xiyuyang19, yuanxzhang, kjlu, Xin Tan

aa_change_profile() invokes aa_get_current_label(), which returns
a reference of the current task's label.

According to the comment of aa_get_current_label(), the returned
reference must be put with aa_put_label().
However, when the original object pointed by "label" becomes
unreachable because aa_change_profile() returns or a new object
is assigned to "label", reference count increased by
aa_get_current_label() is not decreased, causing a refcnt leak.

Fix this by calling aa_put_label() before aa_change_profile() return
and dropping unnecessary aa_get_current_label().

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
---
Changes in v2:
- Remove unnecessary aa_get_current_label() because it gets called
  earlier in the fn
---
 security/apparmor/domain.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
index 6ceb74e0f789..a84ef030fbd7 100644
--- a/security/apparmor/domain.c
+++ b/security/apparmor/domain.c
@@ -1328,6 +1328,7 @@ int aa_change_profile(const char *fqname, int flags)
 		ctx->nnp = aa_get_label(label);
 
 	if (!fqname || !*fqname) {
+		aa_put_label(label);
 		AA_DEBUG("no profile name");
 		return -EINVAL;
 	}
@@ -1346,8 +1347,6 @@ int aa_change_profile(const char *fqname, int flags)
 			op = OP_CHANGE_PROFILE;
 	}
 
-	label = aa_get_current_label();
-
 	if (*fqname == '&') {
 		stack = true;
 		/* don't have label_parse() do stacking */
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-15 19:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 11:27 [PATCH v2] apparmor: fix potential label refcnt leak in aa_change_profile Markus Elfring
2020-04-15 18:41 ` John Johansen
  -- strict thread matches above, loose matches on Subject: below --
2020-04-05  5:11 Xiyu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).