@@ -251,8 +251,8 @@ static int dev_rmdir(const char *name)
else
err = -EPERM;
- dput(dentry);
- inode_unlock(d_inode(parent.dentry));
+ done_lookup_and_lock(parent.dentry, dentry);
+
path_put(&parent);
return err;
}
@@ -339,8 +339,7 @@ static int handle_remove(const char *nodename, struct device *dev)
if (!err || err == -ENOENT)
deleted = 1;
}
- dput(dentry);
- inode_unlock(d_inode(parent.dentry));
+ done_lookup_and_lock(parent.dentry, dentry);
path_put(&parent);
if (deleted && strchr(nodename, '/'))
@@ -522,8 +522,7 @@ static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
d_delete(victim);
}
err:
- inode_unlock(dir);
- dput(victim);
+ done_lookup_and_lock(path.dentry, victim);
path_put(&path);
return ret;
}
@@ -2773,6 +2773,13 @@ struct dentry *user_path_locked_at(int dfd, const char __user *name, struct path
}
EXPORT_SYMBOL(user_path_locked_at);
+void done_lookup_and_lock(struct dentry *parent, struct dentry *child)
+{
+ dput(child);
+ inode_unlock(d_inode(parent));
+}
+EXPORT_SYMBOL(done_lookup_and_lock);
+
int kern_path(const char *name, unsigned int flags, struct path *path)
{
struct filename *filename = getname_kernel(name);
@@ -4146,8 +4153,7 @@ EXPORT_SYMBOL(kern_path_create);
void done_path_create(struct path *path, struct dentry *dentry)
{
- dput(dentry);
- inode_unlock(path->dentry->d_inode);
+ done_lookup_and_lock(path->dentry, dentry);
mnt_drop_write(path->mnt);
path_put(path);
}
@@ -65,6 +65,7 @@ extern struct dentry *user_path_create(int, const char __user *, struct path *,
extern void done_path_create(struct path *, struct dentry *);
extern struct dentry *kern_path_locked(const char *, struct path *);
extern struct dentry *user_path_locked_at(int , const char __user *, struct path *);
+extern void done_lookup_and_lock(struct dentry *parent, struct dentry *child);
int vfs_path_parent_lookup(struct filename *filename, unsigned int flags,
struct path *parent, struct qstr *last, int *type,
const struct path *root);
@@ -86,7 +86,6 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *pa
if (IS_ERR(dentry))
return ERR_CAST(dentry); /* returning an error */
inode = path.dentry->d_inode;
- inode_unlock(inode);
audit_mark = kzalloc(sizeof(*audit_mark), GFP_KERNEL);
if (unlikely(!audit_mark)) {
@@ -107,7 +106,7 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *pa
audit_mark = ERR_PTR(ret);
}
out:
- dput(dentry);
+ done_lookup_and_lock(path.dentry, dentry);
path_put(&path);
return audit_mark;
}
@@ -354,8 +354,7 @@ static int audit_get_nd(struct audit_watch *watch, struct path *parent)
watch->dev = d->d_sb->s_dev;
watch->ino = d_backing_inode(d)->i_ino;
- inode_unlock(d_backing_inode(parent->dentry));
- dput(d);
+ done_lookup_and_lock(parent->dentry, d);
return 0;
}
Callers of kern_path_locked() and user_path_locked_at() should now call done_lookup_and_lock() to unlock the directory and dput() the dentry. This will allow the locking rules to be changed in a central place. Signed-off-by: NeilBrown <neilb@suse.de> --- drivers/base/devtmpfs.c | 7 +++---- fs/bcachefs/fs-ioctl.c | 3 +-- fs/namei.c | 10 ++++++++-- include/linux/namei.h | 1 + kernel/audit_fsnotify.c | 3 +-- kernel/audit_watch.c | 3 +-- 6 files changed, 15 insertions(+), 12 deletions(-)