From: sashiko-bot@kernel.org
Cc: audit@vger.kernel.org
Subject: Re: [PATCH v2] audit: don't use the caller's root when it has no fs
Date: Tue, 20 Oct 2026 13:00:18 +0000 [thread overview]
Message-ID: <sashiko-outbox-178982@kernel.org> (raw)
In-Reply-To: <20261020125024.8550-1-ngocthang2710.1999@gmail.com>
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
next prev parent reply other threads:[~2026-10-20 13:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-04 20:07 ` Paul Moore
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=sashiko-outbox-178982@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=audit@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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