mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Henry Martin <bsdhenrymartin@gmail.com>
To: john.johansen@canonical.com, john@apparmor.net,
	georgia.garcia@canonical.com
Cc: apparmor@lists.ubuntu.com, linux-kernel@vger.kernel.org,
	Henry Martin <bsdhenrymartin@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] apparmor: fix out-of-bounds read of xmatch perms during exec attachment
Date: Sat,  7 Nov 2026 02:54:06 +0800	[thread overview]
Message-ID: <20261106185406.3332779-1-bsdhenrymartin@gmail.com> (raw)

verify_profile() validates the accept table indexes of the file
and policy dfas, but never of the attach xmatch dfa. When a policy
carries an explicit xmatch perms table, the blob accept values are
used as indexes into that table unchecked. At exec time,
aa_lookup_perms() uses one as an index into the xmatch perms array
with no bounds check.

The index is a full 32-bit value from the blob, so the read can be
placed gigabytes past the table, across the entire direct map. The
bytes read are interpreted as the allow/deny bits of the exec
request, and the transition outcome is observable by the task,
turning the bug into a bit-per-query read oracle over kernel
memory. An index pointing at unmapped memory oopses in
find_attach() at exec time. E.g. on mainline v7.4-rc1 (KASAN
build):

    BUG: KASAN: slab-out-of-bounds in find_attach+0xc50/0xfe0
    Read of size 4 at addr ffff88810fb2f934 by task su/495
    CPU: 5 UID: 1000 PID: 495 Comm: su
    Call Trace:
     kasan_report
     find_attach
     profile_transition
     apparmor_bprm_creds_for_exec
     bprm_execve
     __x64_sys_execve

Run verify_dfa_accept_index() on the attach xmatch dfa in
verify_profile(), the same check the file and policy dfas already
get.

This issue was discovered by Tencent CodeBuddy Security.

Cc: stable@vger.kernel.org
Fixes: 6f442d42c0d89 ("apparmor: fix profile verification and enable it")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 security/apparmor/policy_unpack.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index 35dfa3b451f39..054aad13f5e48 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -1593,6 +1593,15 @@ static int verify_profile(struct aa_profile *profile)
 		return -EPROTO;
 	}
 
+	if (profile->attach.xmatch->dfa &&
+	    !verify_dfa_accept_index(profile->attach.xmatch->dfa,
+				     profile->attach.xmatch->size)) {
+		audit_iface(profile, NULL, NULL,
+			    "Unpack: xmatch Invalid named transition", NULL,
+			    -EPROTO);
+		return -EPROTO;
+	}
+
 	if (!verify_perms(rules->file)) {
 		audit_iface(profile, NULL, NULL,
 			    "Unpack: Invalid perm index", NULL, -EPROTO);
-- 
2.43.7


                 reply	other threads:[~2026-11-06 18:54 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=20261106185406.3332779-1-bsdhenrymartin@gmail.com \
    --to=bsdhenrymartin@gmail.com \
    --cc=apparmor@lists.ubuntu.com \
    --cc=georgia.garcia@canonical.com \
    --cc=john.johansen@canonical.com \
    --cc=john@apparmor.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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®