* [PATCH v2] audit: don't use the caller's root when it has no fs
@ 2026-10-20 12:50 Nguyen Ngoc Thang
2026-10-20 13:00 ` sashiko-bot
2026-11-04 20:07 ` Paul Moore
0 siblings, 2 replies; 3+ messages in thread
From: Nguyen Ngoc Thang @ 2026-10-20 12:50 UTC (permalink / raw)
To: paul, eparis
Cc: audit, linux-kernel, linux-fsdevel, viro, brauner, jack,
syzbot+975ace299d6ba2eb1cea, Nguyen Ngoc Thang
audit_log_d_path() calls d_path(), which resolves the path relative to
current->fs->root. do_exit() runs exit_fs() before exit_task_work(), so
a deferred __fput() runs with current->fs == NULL and d_path() oopses:
ima_file_free() -> ima_update_xattr() -> ima_calc_file_hash()
-> dentry_open() -> smack_file_open() -> smack_log()
-> common_lsm_audit() -> audit_log_d_path() -> d_path()
-> read_seqbegin(¤t->fs->seq)
Without an fs there is no root to be relative to, so log the absolute
path with d_absolute_path() instead.
Reported-by: syzbot+975ace299d6ba2eb1cea@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=975ace299d6ba2eb1cea
Fixes: 4a9d4b024a31 ("switch fput to task_work_add")
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
---
Changes in v2 (Al Viro's review of v1, which patched d_path() itself):
- d_path() is meant to be relative to the caller's root, which is
meaningless here, so leave it alone and fix the caller instead.
- audit_log_d_path() uses d_absolute_path() when current->fs is NULL.
Reproduced in QEMU (x86_64, KASAN, Smack+IMA+audit) with the syzbot C
reproducer: without the patch the first exiting child hits a null-ptr-deref
in d_path(); with it the reproducer runs to completion with no KASAN/Oops,
and the audit record still carries path="...".
Al, does this match what you had in mind? A final fput() in some unrelated
task still logs a path relative to that task's root; this patch does not
change that.
kernel/audit.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/kernel/audit.c b/kernel/audit.c
index 9412af9144bc..32085674d0be 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -2218,7 +2218,11 @@ void audit_log_d_path(struct audit_buffer *ab, const char *prefix,
audit_log_format(ab, "\"<no_memory>\"");
return;
}
- p = d_path(path, pathname, PATH_MAX+11);
+ /* No fs after exit_fs(), so there is no root to be relative to */
+ if (current->fs)
+ p = d_path(path, pathname, PATH_MAX+11);
+ else
+ p = d_absolute_path(path, pathname, PATH_MAX+11);
if (IS_ERR(p)) { /* Should never happen since we send PATH_MAX */
/* FIXME: can we save some information here? */
audit_log_format(ab, "\"<too_long>\"");
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] audit: don't use the caller's root when it has no fs
2026-10-20 12:50 [PATCH v2] audit: don't use the caller's root when it has no fs Nguyen Ngoc Thang
@ 2026-10-20 13:00 ` sashiko-bot
2026-11-04 20:07 ` Paul Moore
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-20 13:00 UTC (permalink / raw)
Cc: audit
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] audit: audit_log_d_path() logs <too_long> on -EINVAL from d_absolute_path()
--
commit 414cd8bdacdc30225fedf858b3d33b72b5614c16
Author: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
audit: don't use the caller's root when it has no fs
This commit updates audit_log_d_path() to call d_absolute_path() instead of
d_path() when current->fs is NULL, preventing a NULL pointer dereference
when deferred __fput() runs from exit_task_work() after exit_fs() in
do_exit().
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 631d6d4a23cfd..1973da2eaf3f7 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -2218,7 +2218,11 @@ void audit_log_d_path(struct audit_buffer *ab, const char *prefix,
> audit_log_format(ab, "\"<no_memory>\"");
> return;
> }
> - p = d_path(path, pathname, PATH_MAX+11);
> + /* No fs after exit_fs(), so there is no root to be relative to */
> + if (current->fs)
> + p = d_path(path, pathname, PATH_MAX+11);
> + else
> + p = d_absolute_path(path, pathname, PATH_MAX+11);
> if (IS_ERR(p)) { /* Should never happen since we send PATH_MAX */
> /* FIXME: can we save some information here? */
> audit_log_format(ab, "\"<too_long>\"");
[Severity: Medium]
Can calling d_absolute_path() here cause audit_log_d_path() to falsely log
"<too_long>" instead of the file path?
Unlike d_path(), which dispatches path->dentry->d_op->d_dname(), prepends
" (deleted)" for unlinked dentries, and ignores positive return values from
prepend_path(), d_absolute_path() fails with ERR_PTR(-EINVAL) whenever
prepend_path() returns a value greater than 1:
fs/d_path.c:d_absolute_path() {
struct path root = {};
DECLARE_BUFFER(b, buf, buflen);
prepend_char(&b, 0);
if (unlikely(prepend_path(path, &root, &b) > 1))
return ERR_PTR(-EINVAL);
return extract_string(&b);
}
prepend_path() returns 2 when a mount has mnt_ns == NULL (such as a
lazy-unmounted MNT_DETACH filesystem), an anonymous mount namespace (from
open_tree() or fsmount()), or MNT_NS_INTERNAL (such as pipefs, sockfs, or
anon_inodefs), and returns 3 when a dentry escapes its mount root.
In the do_exit() path that triggers this code, exit_nsproxy_namespaces()
runs after exit_fs() and before exit_task_work():
kernel/exit.c:do_exit() {
...
exit_files(tsk);
exit_fs(tsk);
exit_nsproxy_namespaces(tsk);
exit_task_work(tsk);
...
}
If the exiting task holds the last reference to its mount namespace (for
example, after unshare(CLONE_NEWNS) or clone(CLONE_NEWNS)),
exit_nsproxy_namespaces() -> put_nsproxy() -> put_mnt_ns() -> umount_tree()
runs before exit_task_work() and clears p->mnt_ns to NULL on the mounts in
that namespace:
fs/namespace.c:umount_tree() {
...
WRITE_ONCE(p->mnt_ns, NULL);
if (how & UMOUNT_SYNC)
p->mnt.mnt_flags |= MNT_SYNC_UMOUNT;
if (mnt_has_parent(p)) {
if (needs_cover(p, how))
leave_cover(p);
umount_mnt(p);
}
...
}
When exit_task_work() subsequently runs deferred ____fput() and reaches
audit_log_d_path(), d_absolute_path() will see mnt_ns == NULL and return
ERR_PTR(-EINVAL), which the IS_ERR(p) check in audit_log_d_path() then
reports as "<too_long>".
Would it make more sense to use a helper that preserves d_path() semantics
(including d_dname(), " (deleted)", and detached mounts) with an empty root
path when current->fs is NULL, rather than d_absolute_path()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261020125024.8550-1-ngocthang2710.1999@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] audit: don't use the caller's root when it has no fs
2026-10-20 12:50 [PATCH v2] audit: don't use the caller's root when it has no fs Nguyen Ngoc Thang
2026-10-20 13:00 ` sashiko-bot
@ 2026-11-04 20:07 ` Paul Moore
1 sibling, 0 replies; 3+ messages in thread
From: Paul Moore @ 2026-11-04 20:07 UTC (permalink / raw)
To: sashiko-bot; +Cc: audit
On Oct 20, 2026 sashiko-bot@kernel.org wrote:
>
> audit_log_d_path() calls d_path(), which resolves the path relative to
> current->fs->root. do_exit() runs exit_fs() before exit_task_work(), so
> a deferred __fput() runs with current->fs == NULL and d_path() oopses:
>
> ima_file_free() -> ima_update_xattr() -> ima_calc_file_hash()
> -> dentry_open() -> smack_file_open() -> smack_log()
> -> common_lsm_audit() -> audit_log_d_path() -> d_path()
> -> read_seqbegin(¤t->fs->seq)
>
> Without an fs there is no root to be relative to, so log the absolute
> path with d_absolute_path() instead.
>
> Reported-by: syzbot+975ace299d6ba2eb1cea@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=975ace299d6ba2eb1cea
> Fixes: 4a9d4b024a31 ("switch fput to task_work_add")
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
> ---
> Changes in v2 (Al Viro's review of v1, which patched d_path() itself):
> - d_path() is meant to be relative to the caller's root, which is
> meaningless here, so leave it alone and fix the caller instead.
> - audit_log_d_path() uses d_absolute_path() when current->fs is NULL.
>
> Reproduced in QEMU (x86_64, KASAN, Smack+IMA+audit) with the syzbot C
> reproducer: without the patch the first exiting child hits a null-ptr-deref
> in d_path(); with it the reproducer runs to completion with no KASAN/Oops,
> and the audit record still carries path="...".
>
> Al, does this match what you had in mind? A final fput() in some unrelated
> task still logs a path relative to that task's root; this patch does not
> change that.
>
> kernel/audit.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 9412af9144bc..32085674d0be 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -2218,7 +2218,11 @@ void audit_log_d_path(struct audit_buffer *ab, const char *prefix,
> audit_log_format(ab, "\"<no_memory>\"");
> return;
> }
> - p = d_path(path, pathname, PATH_MAX+11);
> + /* No fs after exit_fs(), so there is no root to be relative to */
> + if (current->fs)
> + p = d_path(path, pathname, PATH_MAX+11);
> + else
> + p = d_absolute_path(path, pathname, PATH_MAX+11);
> if (IS_ERR(p)) { /* Should never happen since we send PATH_MAX */
> /* FIXME: can we save some information here? */
> audit_log_format(ab, "\"<too_long>\"");
See the sashiko feedback on this patch for more information, but since
d_absolute_path() can now error for reasons other "too_long" we should
probably change the error string to "<error>" or similar.
--
paul-moore.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-04 20:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 12:50 [PATCH v2] audit: don't use the caller's root when it has no fs Nguyen Ngoc Thang
2026-10-20 13:00 ` sashiko-bot
2026-11-04 20:07 ` Paul Moore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox