From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: John Johansen <john.johansen@canonical.com>,
Georgia Garcia <georgia.garcia@canonical.com>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>
Cc: apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH] apparmor: don't take chroot root refs in d_namespace_path()
Date: Tue, 01 Dec 2026 15:27:26 +0000 [thread overview]
Message-ID: <20261201-apparmor-chroot-rel-v1-1-f075c3d7db40@gmail.com> (raw)
From: Arun Iyengar <aiyengar1990@gmail.com>
The unix peer checks call aa_path_perm() under unix_state_lock().
For a chroot_relative profile, d_namespace_path() then does
get_fs_root() and path_put(), and dput() may sleep.
Snapshot the root under RCU and fs->seq, as d_path() does.
__d_path() only compares against the root.
Fixes: c05e705812d1 ("apparmor: add fine grained af_unix mediation")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Tested on an Orange Pi 5 with a 7.3-based tree (KASAN + lockdep), a
chroot_relative profile and an AF_UNIX stress, on top of [1]:
133 "sleeping function called from invalid context" (dput) splats
without this patch, 0 with it on two boots. 7.4-rc1 base build only.
Independent of [1], which fixes the buffer allocation on the same path.
Claude (AI) helped write this patch; I reviewed and tested it.
[1] https://lore.kernel.org/r/20261121-apparmor-unix-peer-v1-1-99dd1cdb1e27@gmail.com
---
security/apparmor/path.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/security/apparmor/path.c b/security/apparmor/path.c
index 2494e8101538..dfc782937e49 100644
--- a/security/apparmor/path.c
+++ b/security/apparmor/path.c
@@ -117,10 +117,17 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
/* resolve paths relative to chroot?*/
if (flags & PATH_CHROOT_REL) {
+ struct fs_struct *fs = current->fs;
struct path root;
- get_fs_root(current->fs, &root);
+ unsigned int seq;
+
+ rcu_read_lock();
+ do {
+ seq = read_seqbegin(&fs->seq);
+ root = fs->root;
+ } while (read_seqretry(&fs->seq, seq));
res = __d_path(path, &root, buf, buflen);
- path_put(&root);
+ rcu_read_unlock();
} else {
res = d_absolute_path(path, buf, buflen);
if (!our_mnt(path->mnt))
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261201-apparmor-chroot-rel-6339ffc75905
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
reply other threads:[~2026-12-01 15:27 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=20261201-apparmor-chroot-rel-v1-1-f075c3d7db40@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=apparmor@lists.ubuntu.com \
--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 \
--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®