Re: [PATCH 1/2] VFS: change kern_path_locked() and user_path_locked_at() to never return negative dentry
From: Paul Moore
Date: Fri Feb 07 2025 - 14:10:16 EST
On Thu, Feb 6, 2025 at 10:41 PM NeilBrown <neilb@xxxxxxx> wrote:
>
> No callers of kern_path_locked() or user_path_locked_at() want a
> negative dentry. So change them to return -ENOENT instead. This
> simplifies callers.
>
> This results in a subtle change to bcachefs in that an ioctl will now
> return -ENOENT in preference to -EXDEV. I believe this restores the
> behaviour to what it was prior to
> Commit bbe6a7c899e7 ("bch2_ioctl_subvolume_destroy(): fix locking")
>
> Signed-off-by: NeilBrown <neilb@xxxxxxx>
> ---
> drivers/base/devtmpfs.c | 65 +++++++++++++++++++----------------------
> fs/bcachefs/fs-ioctl.c | 4 ---
> fs/namei.c | 4 +++
> kernel/audit_watch.c | 12 ++++----
> 4 files changed, 40 insertions(+), 45 deletions(-)
...
> diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
> index 7f358740e958..e3130675ee6b 100644
> --- a/kernel/audit_watch.c
> +++ b/kernel/audit_watch.c
> @@ -350,11 +350,10 @@ static int audit_get_nd(struct audit_watch *watch, struct path *parent)
> struct dentry *d = kern_path_locked(watch->path, parent);
> if (IS_ERR(d))
> return PTR_ERR(d);
> - if (d_is_positive(d)) {
> - /* update watch filter fields */
> - watch->dev = d->d_sb->s_dev;
> - watch->ino = d_backing_inode(d)->i_ino;
> - }
> + /* update watch filter fields */
> + watch->dev = d->d_sb->s_dev;
> + watch->ino = d_backing_inode(d)->i_ino;
> +
> inode_unlock(d_backing_inode(parent->dentry));
> dput(d);
> return 0;
> @@ -419,7 +418,7 @@ int audit_add_watch(struct audit_krule *krule, struct list_head **list)
> /* caller expects mutex locked */
> mutex_lock(&audit_filter_mutex);
>
> - if (ret) {
> + if (ret && ret != -ENOENT) {
> audit_put_watch(watch);
> return ret;
> }
> @@ -438,6 +437,7 @@ int audit_add_watch(struct audit_krule *krule, struct list_head **list)
>
> h = audit_hash_ino((u32)watch->ino);
> *list = &audit_inode_hash[h];
> + ret = 0;
If you have to respin this patch for any reason I'd prefer to move the
'ret = 0' up to just after the if block you're modifying in the chunk
above, but that's a trivial nitpick so please don't respin only for
that. Otherwise it looks fine to me from an audit perspective.
Acked-by: Paul Moore <paul@xxxxxxxxxxxxxx> (Audit)
> error:
> path_put(&parent_path);
> audit_put_watch(watch);
> --
> 2.47.1
--
paul-moore.com