Audit system development
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: 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: Wed, 04 Nov 2026 15:07:53 -0500	[thread overview]
Message-ID: <b25c8d7bf9a0d0739ea12969633f1a21@paul-moore.com> (raw)
In-Reply-To: <20261020125024.8550-1-ngocthang2710.1999@gmail.com>

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(&current->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

      parent reply	other threads:[~2026-11-04 20:07 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
2026-11-04 20:07 ` Paul Moore [this message]

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=b25c8d7bf9a0d0739ea12969633f1a21@paul-moore.com \
    --to=paul@paul-moore.com \
    --cc=audit@vger.kernel.org \
    --cc=sashiko-bot@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