* [PATCH] apparmor: don't take chroot root refs in d_namespace_path()
@ 2026-12-01 15:27 ` Arun Iyengar via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Arun Iyengar @ 2026-12-01 15:27 UTC (permalink / raw)
To: John Johansen, Georgia Garcia, Paul Moore, James Morris,
Serge E. Hallyn
Cc: apparmor, linux-security-module, linux-kernel, stable,
Arun Iyengar
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>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] apparmor: don't take chroot root refs in d_namespace_path()
@ 2026-12-01 15:27 ` Arun Iyengar via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-01 15:27 UTC (permalink / raw)
To: John Johansen, Georgia Garcia, Paul Moore, James Morris,
Serge E. Hallyn
Cc: apparmor, linux-security-module, linux-kernel, stable,
Arun Iyengar
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>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] apparmor: don't take chroot root refs in d_namespace_path()
2026-12-01 15:27 ` Arun Iyengar via B4 Relay
(?)
@ 2026-12-01 15:34 ` sashiko-bot
-1 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-01 15:34 UTC (permalink / raw)
Cc: linux-security-module
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-apparmor-chroot-rel-v1-1-f075c3d7db40@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-01 15:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 15:27 [PATCH] apparmor: don't take chroot root refs in d_namespace_path() Arun Iyengar
2026-12-01 15:27 ` Arun Iyengar via B4 Relay
2026-12-01 15:34 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.