linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] apparmor: fix label replacement compiled out of __label_insert()
@ 2026-11-19 20:36 Andrew Kroh
  2026-11-19 20:42 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Kroh @ 2026-11-19 20:36 UTC (permalink / raw)
  To: John Johansen, Georgia Garcia
  Cc: apparmor, linux-security-module, linux-kernel

__label_insert() replaces an equal label in the labelset from inside
an assertion.

	AA_BUG(!__label_replace(this, label));

AA_BUG() evaluates its argument only if
CONFIG_SECURITY_APPARMOR_DEBUG_ASSERTS is set. That option depends on
CONFIG_SECURITY_APPARMOR_DEBUG, which is off by default. Without it,
the compiler discards the call to __label_replace(). The new label
does not go into the tree and does not get FLAG_IN_TREE. The caller,
__label_update(), then removes the old label from the tree.

The proxy of the old label points to the new label. A task that
holds the old label therefore moves to the new label after the first
profile replacement. The new label is not in the labelset, so
__labelset_update() cannot find it on later replacements. A task
with a compound (stacked) label keeps the profile versions from the
first replacement and ignores each later replacement until it execs.

Containers that set no_new_privs and change confinement with a stack
transition show the problem. To reproduce it, load two profiles.

  profile a { ... /usr/bin/bash Px -> a//&b, }
  profile b { ... }

Start a long-lived bash under a//&b. Replace b with a version that
denies a file, then with a version that allows the file again. The
task continues to get the deny. A task under a plain profile follows
every replacement.

Call __label_replace() outside the assertion and assert on its
result.

Fixes: f1bd904175e8 ("apparmor: add the base fns() for domain labels")
Cc: stable@vger.kernel.org
Signed-off-by: Andrew Kroh <andrew.kroh@xata.io>
---
Reproduced on Ubuntu 6.8.0-149-generic, 7.0.0-43-generic and on
apparmor-next (7.4-rc1) on arm64. These steps show the bug (as root):

  echo 'profile a { file, capability, } profile b { file, capability, }' > /tmp/allow
  echo 'profile a { file, capability, } profile b { file, capability, deny /etc/hostname r, }' > /tmp/deny
  apparmor_parser -r /tmp/allow   # load a and b
  aa-exec -p 'a//&b' -- bash      # shell confined by the stack a//&b
  read x < /etc/hostname          # allowed
  apparmor_parser -r /tmp/deny    # replace b: deny /etc/hostname
  read x < /etc/hostname          # denied
  apparmor_parser -r /tmp/allow   # replace b: allow it again
  read x < /etc/hostname          # still denied; allowed with this patch

The check must come from the long-lived task itself. A new exec
(e.g. cat) gets a freshly built label and is not affected.

No other AA_BUG() in security/apparmor has a side effect in its
argument.

 security/apparmor/label.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/security/apparmor/label.c b/security/apparmor/label.c
index fd67262330f9..0dc18743b04a 100644
--- a/security/apparmor/label.c
+++ b/security/apparmor/label.c
@@ -693,6 +693,8 @@ static struct aa_label *__label_insert(struct aa_labelset *ls,
 
 		parent = *new;
 		if (result == 0) {
+			bool replaced;
+
 			/* !__aa_get_label means queued for destruction,
 			 * so replace in place, however the label has
 			 * died before the replacement so do not share
@@ -703,7 +705,8 @@ static struct aa_label *__label_insert(struct aa_labelset *ls,
 					return this;
 			} else
 				__proxy_share(this, label);
-			AA_BUG(!__label_replace(this, label));
+			replaced = __label_replace(this, label);
+			AA_BUG(!replaced);
 			return aa_get_label(label);
 		} else if (result < 0)
 			new = &((*new)->rb_left);

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.56.0


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

* Re: [PATCH] apparmor: fix label replacement compiled out of __label_insert()
  2026-11-19 20:36 [PATCH] apparmor: fix label replacement compiled out of __label_insert() Andrew Kroh
@ 2026-11-19 20:42 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 20:42 UTC (permalink / raw)
  Cc: linux-security-module

> __label_insert() replaces an equal label in the labelset from inside
> an assertion.
> 
> 	AA_BUG(!__label_replace(this, label));
> 
> AA_BUG() evaluates its argument only if
> CONFIG_SECURITY_APPARMOR_DEBUG_ASSERTS is set. That option depends on
> CONFIG_SECURITY_APPARMOR_DEBUG, which is off by default. Without it,
> the compiler discards the call to __label_replace(). The new label
> does not go into the tree and does not get FLAG_IN_TREE. The caller,
> __label_update(), then removes the old label from the tree.
> 
> The proxy of the old label points to the new label. A task that
> holds the old label therefore moves to the new label after the first
> profile replacement. The new label is not in the labelset, so
> [ ... ]
> result.
> 
> Fixes: f1bd904175e8 ("apparmor: add the base fns() for domain labels")
> Cc: stable@vger.kernel.org
> Signed-off-by: Andrew Kroh <andrew.kroh@xata.io>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119203650.51147-1-andrew.kroh@xata.io?part=1


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

end of thread, other threads:[~2026-11-19 20:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 20:36 [PATCH] apparmor: fix label replacement compiled out of __label_insert() Andrew Kroh
2026-11-19 20:42 ` sashiko-bot

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