Linux Security Modules development
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH v2] lsm: don't call d_path() when current->fs is NULL
Date: Fri, 20 Nov 2026 17:18:14 -0500	[thread overview]
Message-ID: <481c20b898f003247763475ef417c321@paul-moore.com> (raw)
In-Reply-To: <20261106111016.5783-1-drifabdelmalekmohamedsaid@gmail.com>

On Nov  6, 2026 sashiko-bot@kernel.org wrote:
> 
> When the last reference to a file is put from exit_task_work(), the task
> has already run exit_fs(), so current->fs is NULL.
> 
> syzbot reported:
> 
> Call trace:
>  get_fs_root_rcu fs/d_path.c:244 [inline]
>  d_path+0x224/0x4dc fs/d_path.c:287
>  audit_log_d_path+0xdc/0x19c kernel/audit.c:2221
>  audit_log_lsm_data+0xe0/0x12d0 security/lsm_audit.c:199
>  dump_common_audit_data security/lsm_audit.c:421 [inline]
> ...
>  security_file_open+0xec/0x258 security/security.c:2739
>  do_dentry_open+0x2a8/0xfbc fs/open.c:973
>  vfs_open+0x44/0x2dc fs/open.c:1101
>  dentry_open+0x74/0xc0 fs/open.c:1124
> ...
>  security_file_release+0x84/0x148 security/security.c:2424
>  __fput+0x2c4/0x74c fs/file_table.c:506
>  ____fput+0x20/0x30 fs/file_table.c:541
>  task_work_run+0x1cc/0x25c kernel/task_work.c:233
>  exit_task_work include/linux/task_work.h:40 [inline]
>  do_exit+0x58c/0x1a74 kernel/exit.c:986
> 
> d_path() renders a path relative to current->fs->root.  After exit_fs()
> there is no such root, and no substitute root is meaningful: the
> record's pid/comm describe a task that can no longer name the file, and
> the file may have been opened by a different task entirely.  Falling
> back to another root would produce a well-formed but misleading path,
> so report the field as path=?
> 
> Handle this in audit_log_lsm_data(), where the meaning of the field is
> known, for LSM_AUDIT_DATA_PATH (Smack file_open), LSM_AUDIT_DATA_FILE
> (SELinux file_open), LSM_AUDIT_DATA_IOCTL_OP and the AF_UNIX path in
> LSM_AUDIT_DATA_NET.
> 
> Fixes: 4a9d4b024a31 ("switch fput to task_work_add")
> Reported-by: syzbot+975ace299d6ba2eb1cea@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=975ace299d6ba2eb1cea
> Signed-off-by: Drif Abdelmalek Mohamed Said <drifabdelmalekmohamedsaid@gmail.com>
> ---
> v2:
>   - Replaced logging from path=(null) to path=?
>   - Added audit_log_lsm_inode helper
> v1: https://lore.kernel.org/all/20261019222858.1766-1-drifabdelmalekmohamedsaid@gmail.com/
>  security/lsm_audit.c | 70 ++++++++++++++++++++------------------------
>  1 file changed, 31 insertions(+), 39 deletions(-)

Thanks for the second revision, one comments below ...

> diff --git a/security/lsm_audit.c b/security/lsm_audit.c
> index 955b2e7b2c8e..d92b0823e871 100644
> --- a/security/lsm_audit.c
> +++ b/security/lsm_audit.c
> @@ -169,6 +169,27 @@ static inline void print_ipv4_addr(struct audit_buffer *ab, __be32 addr,
>  		audit_log_format(ab, " %s=%d", name2, ntohs(port));
>  }
>  
> +static void audit_log_lsm_inode(struct audit_buffer *ab, struct inode *inode)
> +{
> +	if (!inode)
> +		return;
> +
> +	audit_log_format(ab, " dev=");
> +	audit_log_untrustedstring(ab, inode->i_sb->s_id);
> +	audit_log_format(ab, " ino=%llu", inode->i_ino);
> +}
> +
> +static void audit_log_lsm_path(struct audit_buffer *ab, struct inode *inode,
> +			       const struct path *path)
> +{
> +	if (current->fs)
> +		audit_log_d_path(ab, " path=", path);
> +	else
> +		audit_log_format(ab, " path=?");
> +
> +	audit_log_lsm_inode(ab, inode);
> +}

As I mentioned in my comments to your v1 patch, we want this function to
look something like the following:

  static void audit_log_lsm_path(ab, inode, path)
  {
    if (current->fs)
      audit_log_d_path(...);
    else if (inode)
      audit_log_lsm_inode(ab, inode)
    else
      audit_log_format(ab, " path=?");
  }

... we only want to log " path=?" if we have no other options.

--
paul-moore.com

      parent reply	other threads:[~2026-11-20 22:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 11:10 [PATCH v2] lsm: don't call d_path() when current->fs is NULL Drif Abdelmalek Mohamed Said
2026-11-06 11:15 ` sashiko-bot
2026-11-20 22:18 ` 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=481c20b898f003247763475ef417c321@paul-moore.com \
    --to=paul@paul-moore.com \
    --cc=linux-security-module@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