linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] apparmor: Fix use-after-free in aa_audit_rule_init
@ 2019-10-17  1:46 Navid Emamdoost
  2019-10-20 14:16 ` Markus Elfring
  0 siblings, 1 reply; 11+ messages in thread
From: Navid Emamdoost @ 2019-10-17  1:46 UTC (permalink / raw)
  Cc: emamd001, smccaman, kjlu, Navid Emamdoost, John Johansen,
	James Morris, Serge E. Hallyn, linux-security-module,
	linux-kernel

In the implementation of aa_audit_rule_init(), when aa_label_parse()
fails the allocated memory for rule is released using
aa_audit_rule_free(). But after this release the the return statement
tries to access the label field of the rule which results in
use-after-free. Before releaseing the rule, copy errNo and return it
after releasing rule.

Fixes: 52e8c38001d8 ("apparmor: Fix memory leak of rule on error exit path")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 security/apparmor/audit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c
index 5a98661a8b46..48c15fb0aafe 100644
--- a/security/apparmor/audit.c
+++ b/security/apparmor/audit.c
@@ -178,6 +178,7 @@ void aa_audit_rule_free(void *vrule)
 int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
 {
 	struct aa_audit_rule *rule;
+	int err;
 
 	switch (field) {
 	case AUDIT_SUBJ_ROLE:
@@ -197,8 +198,9 @@ int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
 	rule->label = aa_label_parse(&root_ns->unconfined->label, rulestr,
 				     GFP_KERNEL, true, false);
 	if (IS_ERR(rule->label)) {
+		err = rule->label;
 		aa_audit_rule_free(rule);
-		return PTR_ERR(rule->label);
+		return PTR_ERR(err);
 	}
 
 	*vrule = rule;
-- 
2.17.1


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

end of thread, other threads:[~2019-10-24  8:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-17  1:46 [PATCH] apparmor: Fix use-after-free in aa_audit_rule_init Navid Emamdoost
2019-10-20 14:16 ` Markus Elfring
2019-10-20 18:49   ` John Johansen
2019-10-21 15:23     ` [PATCH v2] " Navid Emamdoost
2019-10-21 15:45       ` Tyler Hicks
2019-10-21 16:05         ` [PATCH v3] " Navid Emamdoost
2019-10-21 16:08           ` Tyler Hicks
2019-10-21 16:06         ` [PATCH v2] " Navid Emamdoost
2019-10-24  6:20       ` kbuild test robot
2019-10-24  8:48       ` kbuild test robot
2019-10-21 15:25     ` [PATCH] " Navid Emamdoost

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).