[PATCH] apparmor: don't take chroot root refs in d_namespace_path()

Arun Iyengar via B4 Relay devnull+aiyengar1990.gmail.com at kernel.org
Tue Dec 1 15:27:26 UTC 2026


From: Arun Iyengar <aiyengar1990 at 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 at vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990 at 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 at gmail.com>





More information about the Linux-security-module-archive mailing list