mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] apparmor: fix potential label refcnt leak in aa_change_profile
@ 2020-03-29 14:57 Xiyu Yang
  2020-04-04 23:35 ` John Johansen
  0 siblings, 1 reply; 2+ messages in thread
From: Xiyu Yang @ 2020-03-29 14:57 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 the original object pointed
by "label" becomes unreachable.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
---
 security/apparmor/domain.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
index 6ceb74e0f789..b99145ae34c0 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,6 +1347,7 @@ int aa_change_profile(const char *fqname, int flags)
 			op = OP_CHANGE_PROFILE;
 	}
 
+	aa_put_label(label);
 	label = aa_get_current_label();
 
 	if (*fqname == '&') {
-- 
2.7.4


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

end of thread, other threads:[~2020-04-04 23:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-29 14:57 [PATCH] apparmor: fix potential label refcnt leak in aa_change_profile Xiyu Yang
2020-04-04 23:35 ` John Johansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®