lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241220030830.272429-7-neilb@suse.de>
Date: Fri, 20 Dec 2024 13:54:24 +1100
From: NeilBrown <neilb@...e.de>
To: Alexander Viro <viro@...iv.linux.org.uk>,
	Christian Brauner <brauner@...nel.org>,
	Jan Kara <jack@...e.cz>,
	Linus Torvalds <torvalds@...ux-foundation.org>
Cc: linux-fsdevel@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH 06/11] VFS: introduce done_lookup_and_lock()

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@...e.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(-)

diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index c9e34842139f..bb6d26338b6c 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -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, '/'))
diff --git a/fs/bcachefs/fs-ioctl.c b/fs/bcachefs/fs-ioctl.c
index c5464219b23f..d51c86e24bef 100644
--- a/fs/bcachefs/fs-ioctl.c
+++ b/fs/bcachefs/fs-ioctl.c
@@ -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;
 }
diff --git a/fs/namei.c b/fs/namei.c
index 8780406cb4d7..29f86df4b9dc 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -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);
 }
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 15118992f745..898fc8ba37e1 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -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);
diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c
index c565fbf66ac8..db2c03caa74d 100644
--- a/kernel/audit_fsnotify.c
+++ b/kernel/audit_fsnotify.c
@@ -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;
 }
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index e3130675ee6b..e1137ea9294b 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -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;
 }
 
-- 
2.47.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ