mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: sig_cloudnative@sina.com
To: John Johansen <john.johansen@canonical.com>, apparmor@lists.ubuntu.com
Cc: Georgia Garcia <georgia.garcia@canonical.com>,
	Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	"Serge E . Hallyn" <serge@hallyn.com>,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, Xu Chen <chenxu@kylinos.cn>
Subject: [PATCH 1/3] apparmor: fix capability chunk walk in aa_profile_capget()
Date: Mon, 16 Nov 2026 10:22:05 +0800	[thread overview]
Message-ID: <20261116022206.174459-1-sig_cloudnative@sina.com> (raw)

From: Xu Chen <chenxu@kylinos.cn>

aa_profile_capget() rebuilds the kernel capability set that a profile
allows from the policy dfa.  Capabilities are broken into 32 bit
permission chunks with one dfa transition per chunk, but the loop that
walks the chunks stops before the last chunk, CAP_LAST_CAP >> 5, and the
chunk permissions are shifted by i * 5 instead of by the chunk width of
32 bits.

The permissions of the chunk holding the highest capabilities are thus
never read, and fixing only the loop bound would place them in the wrong
bits.  The capability set used by apparmor_capget() to intersect the
capabilities reported for a task is therefore wrong: capabilities the
profile allows are reported as missing, so for example a task confined by
a profile that allows CAP_PERFMON or CAP_CHECKPOINT_RESTORE sees them
dropped from its effective and permitted sets.

Walk all chunks up to and including CAP_LAST_CAP >> 5 and shift each
chunk by 32 bits.

Fixes: ce9e3b3fa25a ("apparmor: add ability to mediate caps with policy state machine")
Signed-off-by: Xu Chen <chenxu@kylinos.cn>
---
 security/apparmor/capability.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/security/apparmor/capability.c b/security/apparmor/capability.c
index 2f3c6c84358d..14f9e0f87f51 100644
--- a/security/apparmor/capability.c
+++ b/security/apparmor/capability.c
@@ -201,16 +201,16 @@ kernel_cap_t aa_profile_capget(const struct aa_profile *profile)
 		kernel_cap_t caps = CAP_EMPTY_SET;
 		int i;
 
-		/* caps broken into up to 256, 32 bit permission chunks */
-		for (i = 0; i < (CAP_LAST_CAP >> 5); i++) {
+		/* caps are broken into 32 bit permission chunks */
+		for (i = 0; i <= (CAP_LAST_CAP >> 5); i++) {
 			struct aa_perms perms = { };
 			aa_state_t tmp;
 
 			tmp = aa_dfa_next(rules->policy->dfa, state, i);
 			perms = *aa_lookup_perms(rules->policy, tmp);
 			aa_apply_modes_to_perms(profile, &perms);
-			caps.val |= ((u64)(perms.allow)) << (i * 5);
-			caps.val |= ((u64)(perms.complain)) << (i * 5);
+			caps.val |= ((u64)(perms.allow)) << (i * 32);
+			caps.val |= ((u64)(perms.complain)) << (i * 32);
 		}
 		return caps;
 	}

base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea
-- 
2.56.1


                 reply	other threads:[~2026-11-16  2:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116022206.174459-1-sig_cloudnative@sina.com \
    --to=sig_cloudnative@sina.com \
    --cc=apparmor@lists.ubuntu.com \
    --cc=chenxu@kylinos.cn \
    --cc=georgia.garcia@canonical.com \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®