Archive-only list for syzbot
 help / color / mirror / Atom feed
* [PATCH RFC] apparmor: fix error handling in aa_alloc_profile
@ 2026-08-25 15:33 syzbot
  0 siblings, 0 replies; only message in thread
From: syzbot @ 2026-08-25 15:33 UTC (permalink / raw)
  To: syzkaller-upstream-moderation; +Cc: syzbot

When aa_alloc_profile() fails to initialize a profile, it jumps to a single
error label that calls aa_free_profile(). This monolithic cleanup function
calls aa_policy_destroy() on the profile's base policy. However, if the
failure occurs early in aa_policy_init() (e.g., during aa_str_alloc()), the
policy's list heads are not yet initialized. Because the profile is
allocated with kzalloc_flex(), the uninitialized list heads are zeroed,
causing list_empty() to evaluate to false. This triggers an AA_BUG()
assertion in aa_policy_destroy():

  ------------[ cut here ]------------
  AppArmor WARN aa_policy_destroy: (((!list_empty(&policy->profiles) &&
  (&policy->profiles)->prev != ((void *) 0x122 +
  (0xdead000000000000UL))))):
  WARNING: security/apparmor/lib.c:509 at aa_policy_destroy+0x164/0x1b0
  security/apparmor/lib.c:509
  ...
  Call Trace:
   <TASK>
   aa_free_profile+0x9d/0x9f0 security/apparmor/policy.c:334
   aa_alloc_profile+0x1e4/0x3e0 security/apparmor/policy.c:416
   unpack_profile security/apparmor/policy_unpack.c:1153 [inline]
   aa_unpack+0x17db/0x7430 security/apparmor/policy_unpack.c:1748
   aa_replace_profiles+0x226/0x2a20 security/apparmor/policy.c:1183
   policy_update+0x234/0x4a0 security/apparmor/apparmorfs.c:505
   profile_load+0x1cb/0x320 security/apparmor/apparmorfs.c:522
   vfs_write+0x296/0xba0 fs/read_write.c:685

To fix this, modify aa_alloc_profile() to use a strict reverse LIFO goto
ladder for error handling. This ensures that cleanup functions are only
called for fully initialized components, preventing aa_policy_destroy()
from being executed on a partially initialized policy.

Fixes: 637f688dc3dc ("apparmor: switch from profiles to using labels on contexts")
Assisted-by: Gemini:gemini-3.7-flash Gemini:gemini-3.1-pro-preview syzbot
Reported-by: syzbot+faed97c4ed43bfe7fee5@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=faed97c4ed43bfe7fee5
Link: https://syzkaller.appspot.com/ai_job?id=8594cc18-d31f-4dc1-9d81-89d765382445
To: <apparmor@lists.ubuntu.com>
To: "Georgia Garcia" <georgia.garcia@canonical.com>
To: "James Morris" <jmorris@namei.org>
To: "John Johansen" <john.johansen@canonical.com>
To: <linux-security-module@vger.kernel.org>
To: "Paul Moore" <paul@paul-moore.com>
To: "Serge E. Hallyn" <serge@hallyn.com>
Cc: <linux-kernel@vger.kernel.org>

---
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 94b4a7e72..7ec43a491 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -385,21 +385,21 @@ struct aa_profile *aa_alloc_profile(const char *hname, struct aa_proxy *proxy,
 		return NULL;
 
 	if (!aa_policy_init(&profile->base, NULL, hname, gfp))
-		goto fail;
+		goto fail_profile;
 	if (!aa_label_init(&profile->label, 1, gfp))
-		goto fail;
+		goto fail_policy;
 
 	/* allocate the first ruleset, but leave it empty */
 	profile->label.rules[0] = aa_alloc_ruleset(gfp);
 	if (!profile->label.rules[0])
-		goto fail;
+		goto fail_label;
 	profile->n_rules = 1;
 
 	/* update being set needed by fs interface */
 	if (!proxy) {
 		proxy = aa_alloc_proxy(&profile->label, gfp);
 		if (!proxy)
-			goto fail;
+			goto fail_rules;
 	} else
 		aa_get_proxy(proxy);
 	profile->label.proxy = proxy;
@@ -412,8 +412,14 @@ struct aa_profile *aa_alloc_profile(const char *hname, struct aa_proxy *proxy,
 	/* refcount released by caller */
 	return profile;
 
-fail:
-	aa_free_profile(profile);
+fail_rules:
+	free_ruleset(profile->label.rules[0]);
+fail_label:
+	aa_label_destroy(&profile->label);
+fail_policy:
+	aa_policy_destroy(&profile->base);
+fail_profile:
+	kfree_sensitive(profile);
 
 	return NULL;
 }


base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
-- 
This is an AI-generated patch subject to moderation.
Reply with '#syz upstream' to Sign-off the patch as a human author
and send it to the upstream kernel mailing lists.
Reply with '#syz reject' to reject it ('#syz unreject' to undo).

See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
You can comment on the patch as usual, syzbot will try to address
the comments and send a new version of the patch if necessary.
syzbot engineers can be reached at syzkaller@googlegroups.com.

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-25 15:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-25 15:33 [PATCH RFC] apparmor: fix error handling in aa_alloc_profile syzbot

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