Skip to contentSkip to conversation

vfs: track the dentry name length in name_snapshot

PATCH In review Jeff Layton 3 participants 10 messages Apr 26, 2019

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover vfs: track the dentry name length in name_snapshot

name_snapshot will snapshot the current contents of a dentry's name for later consumption. Several of those users end up needing to do a strlen on the resulting string later. We already have that info in the original dentry though, so we can do this a bit more efficiently by stuffing the name length into the name_snapshot as well.

This is not well tested, but it built and booted. Do we have a testsuite that exercises the fsnotify code, in particular?

Jeff Layton (5):
dcache: track the length of the string in struct name_snapshot
fsnotify: have fsnotify_move take a struct qstr instead of a string
fsnotify: have fsnotify() take a qstr instead of a string
fsnotify: change ->handle_event and send_to_group to take a qstr
audit: fix audit_compare_dname_path to take a qstr

 fs/dcache.c                          | 11 +++++++----
 fs/debugfs/inode.c                   |  2 +-
 fs/kernfs/file.c                     |  6 ++++--
 fs/namei.c                           |  4 ++--
 fs/notify/dnotify/dnotify.c          |  2 +-
 fs/notify/fanotify/fanotify.c        |  2 +-
 fs/notify/fsnotify.c                 |  8 ++++----
 fs/notify/inotify/inotify.h          |  2 +-
 fs/notify/inotify/inotify_fsnotify.c |  6 +++---
 fs/overlayfs/export.c                |  2 +-
 include/linux/dcache.h               |  2 +-
 include/linux/fsnotify.h             | 17 ++++++++---------
 include/linux/fsnotify_backend.h     |  6 +++---
 kernel/audit.h                       |  3 ++-
 kernel/audit_fsnotify.c              |  5 +++--
 kernel/audit_tree.c                  |  2 +-
 kernel/audit_watch.c                 |  4 ++--
 kernel/auditfilter.c                 |  7 ++++---
 kernel/auditsc.c                     |  7 +++----
 19 files changed, 52 insertions(+), 46 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/5 dcache: track the length of the string in struct name_snapshot

Several existing callers end up having to strlen the string, so just convert the code over to set up a qstr instead and copy the length from the original.

---
 fs/dcache.c              | 11 +++++++----
 fs/debugfs/inode.c       |  2 +-
 fs/namei.c               |  2 +-
 fs/notify/fsnotify.c     |  4 ++--
 fs/overlayfs/export.c    |  2 +-
 include/linux/dcache.h   |  2 +-
 include/linux/fsnotify.h |  2 +-
 7 files changed, 14 insertions(+), 11 deletions(-)
fs/dcache.c +7 -4
index aac41adf4743..a8dcc27ce2d0 100644
@@ -287,22 +287,25 @@ void take_dentry_name_snapshot(struct name_snapshot *name, struct dentry *dentry
 	if (unlikely(dname_external(dentry))) {
 		struct external_name *p = external_name(dentry);
 		atomic_inc(&p->u.count);
+		name->name.len = dentry->d_name.len;
 		spin_unlock(&dentry->d_lock);
-		name->name = p->name;
+		name->name.name = p->name;
 	} else {
 		memcpy(name->inline_name, dentry->d_iname,
 		       dentry->d_name.len + 1);
+		name->name.len = dentry->d_name.len;
 		spin_unlock(&dentry->d_lock);
-		name->name = name->inline_name;
+		name->name.name = name->inline_name;
 	}
 }
 EXPORT_SYMBOL(take_dentry_name_snapshot);
 
 void release_dentry_name_snapshot(struct name_snapshot *name)
 {
-	if (unlikely(name->name != name->inline_name)) {
+	if (unlikely(name->name.name != name->inline_name)) {
 		struct external_name *p;
-		p = container_of(name->name, struct external_name, name[0]);
+		p = container_of(name->name.name, struct external_name,
+				 name[0]);
 		if (unlikely(atomic_dec_and_test(&p->u.count)))
 			kfree_rcu(p, u.head);
 	}
fs/debugfs/inode.c +1 -1
index f25daa207421..37c0a025d7e8 100644
@@ -824,7 +824,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
 		goto exit;
 	}
 	d_move(old_dentry, dentry);
-	fsnotify_move(d_inode(old_dir), d_inode(new_dir), old_name.name,
+	fsnotify_move(d_inode(old_dir), d_inode(new_dir), old_name.name.name,
 		d_is_dir(old_dentry),
 		NULL, old_dentry);
 	release_dentry_name_snapshot(&old_name);
fs/namei.c +1 -1
index dede0147b3f6..c96713077326 100644
@@ -4498,7 +4498,7 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 		inode_unlock(target);
 	dput(new_dentry);
 	if (!error) {
-		fsnotify_move(old_dir, new_dir, old_name.name, is_dir,
+		fsnotify_move(old_dir, new_dir, old_name.name.name, is_dir,
 			      !(flags & RENAME_EXCHANGE) ? target : NULL, old_dentry);
 		if (flags & RENAME_EXCHANGE) {
 			fsnotify_move(new_dir, old_dir, old_dentry->d_name.name,
fs/notify/fsnotify.c +2 -2
index df06f3da166c..fb22f76329ae 100644
@@ -179,10 +179,10 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask
 		take_dentry_name_snapshot(&name, dentry);
 		if (path)
 			ret = fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH,
-				       name.name, 0);
+				       name.name.name, 0);
 		else
 			ret = fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE,
-				       name.name, 0);
+				       name.name.name, 0);
 		release_dentry_name_snapshot(&name);
 	}
 
fs/overlayfs/export.c +1 -1
index 54e5d17d7f3e..cc1c9e5606ba 100644
@@ -398,7 +398,7 @@ static struct dentry *ovl_lookup_real_one(struct dentry *connected,
 	 * pointer because we hold no lock on the real dentry.
 	 */
 	take_dentry_name_snapshot(&name, real);
-	this = lookup_one_len(name.name, connected, strlen(name.name));
+	this = lookup_one_len(name.name.name, connected, name.name.len);
 	err = PTR_ERR(this);
 	if (IS_ERR(this)) {
 		goto fail;
include/linux/dcache.h +1 -1
index 60996e64c579..2ff5f3bb9ddc 100644
@@ -594,7 +594,7 @@ static inline struct inode *d_real_inode(const struct dentry *dentry)
 }
 
 struct name_snapshot {
-	const unsigned char *name;
+	struct qstr name;
 	unsigned char inline_name[DNAME_INLINE_LEN];
 };
 void take_dentry_name_snapshot(struct name_snapshot *, struct dentry *);
include/linux/fsnotify.h +1 -1
index 09587e2860b5..e09cfff69bb2 100644
@@ -178,7 +178,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
 	take_dentry_name_snapshot(&name, dentry);
 
 	fsnotify(d_inode(parent), mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
-		 name.name, 0);
+		 name.name.name, 0);
 
 	release_dentry_name_snapshot(&name);
 	dput(parent);
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/5 fsnotify: have fsnotify_move take a struct qstr instead of a string

In reply to Jeff Layton

With this, ovl_lookup_real_one can skip the strlen call.

---
 fs/debugfs/inode.c       |  2 +-
 fs/namei.c               |  4 ++--
 include/linux/fsnotify.h | 11 +++++------
 3 files changed, 8 insertions(+), 9 deletions(-)
fs/debugfs/inode.c +1 -1
index 37c0a025d7e8..5dbeefa69a58 100644
@@ -824,7 +824,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
 		goto exit;
 	}
 	d_move(old_dentry, dentry);
-	fsnotify_move(d_inode(old_dir), d_inode(new_dir), old_name.name.name,
+	fsnotify_move(d_inode(old_dir), d_inode(new_dir), &old_name.name,
 		d_is_dir(old_dentry),
 		NULL, old_dentry);
 	release_dentry_name_snapshot(&old_name);
fs/namei.c +2 -2
index c96713077326..5ebd64b21970 100644
@@ -4498,10 +4498,10 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 		inode_unlock(target);
 	dput(new_dentry);
 	if (!error) {
-		fsnotify_move(old_dir, new_dir, old_name.name.name, is_dir,
+		fsnotify_move(old_dir, new_dir, &old_name.name, is_dir,
 			      !(flags & RENAME_EXCHANGE) ? target : NULL, old_dentry);
 		if (flags & RENAME_EXCHANGE) {
-			fsnotify_move(new_dir, old_dir, old_dentry->d_name.name,
+			fsnotify_move(new_dir, old_dir, &old_dentry->d_name,
 				      new_is_dir, NULL, new_dentry);
 		}
 	}
include/linux/fsnotify.h +5 -6
index e09cfff69bb2..2de90a7e388b 100644
@@ -102,7 +102,7 @@ static inline void fsnotify_link_count(struct inode *inode)
  * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
  */
 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
-				 const unsigned char *old_name,
+				 const struct qstr *old_name,
 				 int isdir, struct inode *target,
 				 struct dentry *moved)
 {
@@ -111,7 +111,6 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
 	__u32 old_dir_mask = FS_MOVED_FROM;
 	__u32 new_dir_mask = FS_MOVED_TO;
 	__u32 mask = FS_MOVE_SELF;
-	const unsigned char *new_name = moved->d_name.name;
 
 	if (old_dir == new_dir)
 		old_dir_mask |= FS_DN_RENAME;
@@ -122,10 +121,10 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
 		mask |= FS_ISDIR;
 	}
 
-	fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name,
-		 fs_cookie);
-	fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name,
-		 fs_cookie);
+	fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE,
+		 old_name->name, fs_cookie);
+	fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE,
+		 moved->d_name.name, fs_cookie);
 
 	if (target)
 		fsnotify_link_count(target);
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/5 fsnotify: have fsnotify() take a qstr instead of a string

In reply to Jeff Layton

This means that kernfs_notify_workfn has to grow a strlen as well.

---
 fs/kernfs/file.c                 |  6 ++++--
 fs/notify/fsnotify.c             |  8 ++++----
 include/linux/fsnotify.h         | 10 +++++-----
 include/linux/fsnotify_backend.h |  4 ++--
 4 files changed, 15 insertions(+), 13 deletions(-)
fs/kernfs/file.c +4 -2
index ae948aaa4c53..a43283c515f4 100644
@@ -885,6 +885,8 @@ static void kernfs_notify_workfn(struct work_struct *work)
 	list_for_each_entry(info, &kernfs_root(kn)->supers, node) {
 		struct kernfs_node *parent;
 		struct inode *inode;
+		const struct qstr name = { .name = kn->name,
+					   .len  = strlen(kn->name) };
 
 		/*
 		 * We want fsnotify_modify() on @kn but as the
@@ -903,7 +905,7 @@ static void kernfs_notify_workfn(struct work_struct *work)
 			p_inode = ilookup(info->sb, parent->id.ino);
 			if (p_inode) {
 				fsnotify(p_inode, FS_MODIFY | FS_EVENT_ON_CHILD,
-					 inode, FSNOTIFY_EVENT_INODE, kn->name, 0);
+					 inode, FSNOTIFY_EVENT_INODE, &name, 0);
 				iput(p_inode);
 			}
 
@@ -911,7 +913,7 @@ static void kernfs_notify_workfn(struct work_struct *work)
 		}
 
 		fsnotify(inode, FS_MODIFY, inode, FSNOTIFY_EVENT_INODE,
-			 kn->name, 0);
+			 &name, 0);
 		iput(inode);
 	}
 
fs/notify/fsnotify.c +4 -4
index fb22f76329ae..9cbb5ae11d2f 100644
@@ -179,10 +179,10 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask
 		take_dentry_name_snapshot(&name, dentry);
 		if (path)
 			ret = fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH,
-				       name.name.name, 0);
+				       &name.name, 0);
 		else
 			ret = fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE,
-				       name.name.name, 0);
+				       &name.name, 0);
 		release_dentry_name_snapshot(&name);
 	}
 
@@ -325,7 +325,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info)
  * notification event in whatever means they feel necessary.
  */
 int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
-	     const unsigned char *file_name, u32 cookie)
+	     const struct qstr *file_name, u32 cookie)
 {
 	struct fsnotify_iter_info iter_info = {};
 	struct super_block *sb = to_tell->i_sb;
@@ -379,7 +379,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
 	 */
 	while (fsnotify_iter_select_report_types(&iter_info)) {
 		ret = send_to_group(to_tell, mask, data, data_is, cookie,
-				    file_name, &iter_info);
+				    file_name->name, &iter_info);
 
 		if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS))
 			goto out;
include/linux/fsnotify.h +5 -5
index 2de90a7e388b..66e322df78a3 100644
@@ -27,7 +27,7 @@ static inline int fsnotify_dirent(struct inode *dir, struct dentry *dentry,
 				  __u32 mask)
 {
 	return fsnotify(dir, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
-			dentry->d_name.name, 0);
+			&dentry->d_name, 0);
 }
 
 /* Notify this dentry's parent about a child's events. */
@@ -122,9 +122,9 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
 	}
 
 	fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE,
-		 old_name->name, fs_cookie);
+		 old_name, fs_cookie);
 	fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE,
-		 moved->d_name.name, fs_cookie);
+		 &moved->d_name, fs_cookie);
 
 	if (target)
 		fsnotify_link_count(target);
@@ -177,7 +177,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
 	take_dentry_name_snapshot(&name, dentry);
 
 	fsnotify(d_inode(parent), mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
-		 name.name.name, 0);
+		 &name.name, 0);
 
 	release_dentry_name_snapshot(&name);
 	dput(parent);
@@ -217,7 +217,7 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct
 	fsnotify_link_count(inode);
 	audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE);
 
-	fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
+	fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, &new_dentry->d_name, 0);
 }
 
 /*
include/linux/fsnotify_backend.h +2 -2
index dfc28fcb4de8..7eb7821766d5 100644
@@ -350,7 +350,7 @@ struct fsnotify_mark {
 
 /* main fsnotify call to send events */
 extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
-		    const unsigned char *name, u32 cookie);
+		    const struct qstr *name, u32 cookie);
 extern int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask);
 extern void __fsnotify_inode_delete(struct inode *inode);
 extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
@@ -505,7 +505,7 @@ static inline void fsnotify_init_event(struct fsnotify_event *event,
 #else
 
 static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
-			   const unsigned char *name, u32 cookie)
+			   const struct qstr *name, u32 cookie)
 {
 	return 0;
 }
Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/5 fsnotify: change ->handle_event and send_to_group to take a qstr

In reply to Jeff Layton
---
 fs/notify/dnotify/dnotify.c          | 2 +-
 fs/notify/fanotify/fanotify.c        | 2 +-
 fs/notify/fsnotify.c                 | 4 ++--
 fs/notify/inotify/inotify.h          | 2 +-
 fs/notify/inotify/inotify_fsnotify.c | 6 +++---
 include/linux/fsnotify_backend.h     | 2 +-
 kernel/audit_fsnotify.c              | 5 +++--
 kernel/audit_tree.c                  | 2 +-
 kernel/audit_watch.c                 | 6 +++---
 9 files changed, 16 insertions(+), 15 deletions(-)
fs/notify/dnotify/dnotify.c +1 -1
index 58d77dc696eb..250369d6901d 100644
@@ -81,7 +81,7 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark)
 static int dnotify_handle_event(struct fsnotify_group *group,
 				struct inode *inode,
 				u32 mask, const void *data, int data_type,
-				const unsigned char *file_name, u32 cookie,
+				const struct qstr *file_name, u32 cookie,
 				struct fsnotify_iter_info *iter_info)
 {
 	struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
fs/notify/fanotify/fanotify.c +1 -1
index 6b9c27548997..a34d7e003d7d 100644
@@ -361,7 +361,7 @@ static __kernel_fsid_t fanotify_get_fsid(struct fsnotify_iter_info *iter_info)
 static int fanotify_handle_event(struct fsnotify_group *group,
 				 struct inode *inode,
 				 u32 mask, const void *data, int data_type,
-				 const unsigned char *file_name, u32 cookie,
+				 const struct qstr *file_name, u32 cookie,
 				 struct fsnotify_iter_info *iter_info)
 {
 	int ret = 0;
fs/notify/fsnotify.c +2 -2
index 9cbb5ae11d2f..5433e37fb0c5 100644
@@ -195,7 +195,7 @@ EXPORT_SYMBOL_GPL(__fsnotify_parent);
 static int send_to_group(struct inode *to_tell,
 			 __u32 mask, const void *data,
 			 int data_is, u32 cookie,
-			 const unsigned char *file_name,
+			 const struct qstr *file_name,
 			 struct fsnotify_iter_info *iter_info)
 {
 	struct fsnotify_group *group = NULL;
@@ -379,7 +379,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
 	 */
 	while (fsnotify_iter_select_report_types(&iter_info)) {
 		ret = send_to_group(to_tell, mask, data, data_is, cookie,
-				    file_name->name, &iter_info);
+				    file_name, &iter_info);
 
 		if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS))
 			goto out;
fs/notify/inotify/inotify.h +1 -1
index 74ae60305189..3f246f7b8a92 100644
@@ -27,7 +27,7 @@ extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
 extern int inotify_handle_event(struct fsnotify_group *group,
 				struct inode *inode,
 				u32 mask, const void *data, int data_type,
-				const unsigned char *file_name, u32 cookie,
+				const struct qstr *file_name, u32 cookie,
 				struct fsnotify_iter_info *iter_info);
 
 extern const struct fsnotify_ops inotify_fsnotify_ops;
fs/notify/inotify/inotify_fsnotify.c +3 -3
index ff30abd6a49b..7e8b131029f8 100644
@@ -67,7 +67,7 @@ static int inotify_merge(struct list_head *list,
 int inotify_handle_event(struct fsnotify_group *group,
 			 struct inode *inode,
 			 u32 mask, const void *data, int data_type,
-			 const unsigned char *file_name, u32 cookie,
+			 const struct qstr *file_name, u32 cookie,
 			 struct fsnotify_iter_info *iter_info)
 {
 	struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
@@ -89,7 +89,7 @@ int inotify_handle_event(struct fsnotify_group *group,
 			return 0;
 	}
 	if (file_name) {
-		len = strlen(file_name);
+		len = file_name->len;
 		alloc_len += len + 1;
 	}
 
@@ -129,7 +129,7 @@ int inotify_handle_event(struct fsnotify_group *group,
 	event->sync_cookie = cookie;
 	event->name_len = len;
 	if (len)
-		strcpy(event->name, file_name);
+		strcpy(event->name, file_name->name);
 
 	ret = fsnotify_add_event(group, fsn_event, inotify_merge);
 	if (ret) {
include/linux/fsnotify_backend.h +1 -1
index 7eb7821766d5..c28f6ed1f59b 100644
@@ -117,7 +117,7 @@ struct fsnotify_ops {
 	int (*handle_event)(struct fsnotify_group *group,
 			    struct inode *inode,
 			    u32 mask, const void *data, int data_type,
-			    const unsigned char *file_name, u32 cookie,
+			    const struct qstr *file_name, u32 cookie,
 			    struct fsnotify_iter_info *iter_info);
 	void (*free_group_priv)(struct fsnotify_group *group);
 	void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
kernel/audit_fsnotify.c +3 -2
index 37ae95cfb7f4..6def7f426ba6 100644
@@ -164,7 +164,7 @@ static void audit_autoremove_mark_rule(struct audit_fsnotify_mark *audit_mark)
 static int audit_mark_handle_event(struct fsnotify_group *group,
 				    struct inode *to_tell,
 				    u32 mask, const void *data, int data_type,
-				    const unsigned char *dname, u32 cookie,
+				    const struct qstr *dname, u32 cookie,
 				    struct fsnotify_iter_info *iter_info)
 {
 	struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
@@ -188,7 +188,8 @@ static int audit_mark_handle_event(struct fsnotify_group *group,
 	}
 
 	if (mask & (FS_CREATE|FS_MOVED_TO|FS_DELETE|FS_MOVED_FROM)) {
-		if (audit_compare_dname_path(dname, audit_mark->path, AUDIT_NAME_FULL))
+		if (audit_compare_dname_path(dname->name, audit_mark->path,
+					     AUDIT_NAME_FULL))
 			return 0;
 		audit_update_mark(audit_mark, inode);
 	} else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF))
kernel/audit_tree.c +1 -1
index abfb112f26aa..e49c912f862d 100644
@@ -1040,7 +1040,7 @@ static void evict_chunk(struct audit_chunk *chunk)
 static int audit_tree_handle_event(struct fsnotify_group *group,
 				   struct inode *to_tell,
 				   u32 mask, const void *data, int data_type,
-				   const unsigned char *file_name, u32 cookie,
+				   const struct qstr *file_name, u32 cookie,
 				   struct fsnotify_iter_info *iter_info)
 {
 	return 0;
kernel/audit_watch.c +3 -3
index e8d1adeb2223..3c12fd5b680e 100644
@@ -482,7 +482,7 @@ void audit_remove_watch_rule(struct audit_krule *krule)
 static int audit_watch_handle_event(struct fsnotify_group *group,
 				    struct inode *to_tell,
 				    u32 mask, const void *data, int data_type,
-				    const unsigned char *dname, u32 cookie,
+				    const struct qstr *dname, u32 cookie,
 				    struct fsnotify_iter_info *iter_info)
 {
 	struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info);
@@ -507,9 +507,9 @@ static int audit_watch_handle_event(struct fsnotify_group *group,
 	}
 
 	if (mask & (FS_CREATE|FS_MOVED_TO) && inode)
-		audit_update_watch(parent, dname, inode->i_sb->s_dev, inode->i_ino, 0);
+		audit_update_watch(parent, dname->name, inode->i_sb->s_dev, inode->i_ino, 0);
 	else if (mask & (FS_DELETE|FS_MOVED_FROM))
-		audit_update_watch(parent, dname, AUDIT_DEV_UNSET, AUDIT_INO_UNSET, 1);
+		audit_update_watch(parent, dname->name, AUDIT_DEV_UNSET, AUDIT_INO_UNSET, 1);
 	else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF))
 		audit_remove_parent_watches(parent);
 
Signature · 1 line
2.20.1
#5 lore raw

PATCH 5/5 audit: fix audit_compare_dname_path to take a qstr

In reply to Jeff Layton

...and eliminate its strlen call.

---
 kernel/audit.h          | 3 ++-
 kernel/audit_fsnotify.c | 2 +-
 kernel/audit_watch.c    | 6 +++---
 kernel/auditfilter.c    | 7 ++++---
 kernel/auditsc.c        | 7 +++----
 5 files changed, 13 insertions(+), 12 deletions(-)
kernel/audit.h +2 -1
index 958d5b8fc1b3..8c581fd38050 100644
@@ -231,7 +231,8 @@ extern int audit_comparator(const u32 left, const u32 op, const u32 right);
 extern int audit_uid_comparator(kuid_t left, u32 op, kuid_t right);
 extern int audit_gid_comparator(kgid_t left, u32 op, kgid_t right);
 extern int parent_len(const char *path);
-extern int audit_compare_dname_path(const char *dname, const char *path, int plen);
+extern int audit_compare_dname_path(const struct qstr *dname, const char *path,
+				    int plen);
 extern struct sk_buff *audit_make_reply(int seq, int type, int done, int multi,
 					const void *payload, int size);
 extern void		    audit_panic(const char *message);
kernel/audit_fsnotify.c +1 -1
index 6def7f426ba6..af281e965d24 100644
@@ -188,7 +188,7 @@ static int audit_mark_handle_event(struct fsnotify_group *group,
 	}
 
 	if (mask & (FS_CREATE|FS_MOVED_TO|FS_DELETE|FS_MOVED_FROM)) {
-		if (audit_compare_dname_path(dname->name, audit_mark->path,
+		if (audit_compare_dname_path(dname, audit_mark->path,
 					     AUDIT_NAME_FULL))
 			return 0;
 		audit_update_mark(audit_mark, inode);
kernel/audit_watch.c +3 -3
index 3c12fd5b680e..b50c574223fa 100644
@@ -255,7 +255,7 @@ static void audit_watch_log_rule_change(struct audit_krule *r, struct audit_watc
 
 /* Update inode info in audit rules based on filesystem event. */
 static void audit_update_watch(struct audit_parent *parent,
-			       const char *dname, dev_t dev,
+			       const struct qstr *dname, dev_t dev,
 			       unsigned long ino, unsigned invalidating)
 {
 	struct audit_watch *owatch, *nwatch, *nextw;
@@ -507,9 +507,9 @@ static int audit_watch_handle_event(struct fsnotify_group *group,
 	}
 
 	if (mask & (FS_CREATE|FS_MOVED_TO) && inode)
-		audit_update_watch(parent, dname->name, inode->i_sb->s_dev, inode->i_ino, 0);
+		audit_update_watch(parent, dname, inode->i_sb->s_dev, inode->i_ino, 0);
 	else if (mask & (FS_DELETE|FS_MOVED_FROM))
-		audit_update_watch(parent, dname->name, AUDIT_DEV_UNSET, AUDIT_INO_UNSET, 1);
+		audit_update_watch(parent, dname, AUDIT_DEV_UNSET, AUDIT_INO_UNSET, 1);
 	else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF))
 		audit_remove_parent_watches(parent);
 
kernel/auditfilter.c +4 -3
index 63f8b3f26fab..6f585b48f4ef 100644
@@ -1290,12 +1290,13 @@ int parent_len(const char *path)
  * @parentlen:	length of the parent if known. Passing in AUDIT_NAME_FULL
  * 		here indicates that we must compute this value.
  */
-int audit_compare_dname_path(const char *dname, const char *path, int parentlen)
+int audit_compare_dname_path(const struct qstr *dname, const char *path,
+			     int parentlen)
 {
 	int dlen, pathlen;
 	const char *p;
 
-	dlen = strlen(dname);
+	dlen = dname->len;
 	pathlen = strlen(path);
 	if (pathlen < dlen)
 		return 1;
@@ -1306,7 +1307,7 @@ int audit_compare_dname_path(const char *dname, const char *path, int parentlen)
 
 	p = path + parentlen;
 
-	return strncmp(p, dname, dlen);
+	return strncmp(p, dname->name, dlen);
 }
 
 int audit_filter(int msgtype, unsigned int listtype)
kernel/auditsc.c +3 -4
index d1eab1d4a930..05e06b766af1 100644
@@ -2045,7 +2045,6 @@ void __audit_inode_child(struct inode *parent,
 {
 	struct audit_context *context = audit_context();
 	struct inode *inode = d_backing_inode(dentry);
-	const char *dname = dentry->d_name.name;
 	struct audit_names *n, *found_parent = NULL, *found_child = NULL;
 	struct audit_entry *e;
 	struct list_head *list = &audit_filter_list[AUDIT_FILTER_FS];
@@ -2083,7 +2082,7 @@ void __audit_inode_child(struct inode *parent,
 			continue;
 
 		if (n->ino == parent->i_ino && n->dev == parent->i_sb->s_dev &&
-		    !audit_compare_dname_path(dname,
+		    !audit_compare_dname_path(&dentry->d_name,
 					      n->name->name, n->name_len)) {
 			if (n->type == AUDIT_TYPE_UNKNOWN)
 				n->type = AUDIT_TYPE_PARENT;
@@ -2099,8 +2098,8 @@ void __audit_inode_child(struct inode *parent,
 		    (n->type != type && n->type != AUDIT_TYPE_UNKNOWN))
 			continue;
 
-		if (!strcmp(dname, n->name->name) ||
-		    !audit_compare_dname_path(dname, n->name->name,
+		if (!strcmp(dentry->d_name.name, n->name->name) ||
+		    !audit_compare_dname_path(&dentry->d_name, n->name->name,
 						found_parent ?
 						found_parent->name_len :
 						AUDIT_NAME_FULL)) {
Signature · 1 line
2.20.1
maintainer Acked-by on v1 5/5
#6 lore raw

Re: [PATCH 5/5] audit: fix audit_compare_dname_path to take a qstr

Quoted 11 lines · Jeff Layton

...and eliminate its strlen call.

---
 kernel/audit.h          | 3 ++-
 kernel/audit_fsnotify.c | 2 +-
 kernel/audit_watch.c    | 6 +++---
 kernel/auditfilter.c    | 7 ++++---
 kernel/auditsc.c        | 7 +++----
 5 files changed, 13 insertions(+), 12 deletions(-)

This looks fine to me. I'm guessing you are planning on this going in with the other patches, but if you want me to pull this single patch into audit/next let me know.

Quoted 116 lines
kernel/audit.h +2 -1
index 958d5b8fc1b3..8c581fd38050 100644
@@ -231,7 +231,8 @@ extern int audit_comparator(const u32 left, const u32 op, const u32 right);
 extern int audit_uid_comparator(kuid_t left, u32 op, kuid_t right);
 extern int audit_gid_comparator(kgid_t left, u32 op, kgid_t right);
 extern int parent_len(const char *path);
-extern int audit_compare_dname_path(const char *dname, const char *path, int plen);
+extern int audit_compare_dname_path(const struct qstr *dname, const char *path,
+                                   int plen);
 extern struct sk_buff *audit_make_reply(int seq, int type, int done, int multi,
                                        const void *payload, int size);
 extern void                audit_panic(const char *message);
kernel/audit_fsnotify.c +1 -1
index 6def7f426ba6..af281e965d24 100644
@@ -188,7 +188,7 @@ static int audit_mark_handle_event(struct fsnotify_group *group,
        }
 
        if (mask & (FS_CREATE|FS_MOVED_TO|FS_DELETE|FS_MOVED_FROM)) {
-               if (audit_compare_dname_path(dname->name, audit_mark->path,
+               if (audit_compare_dname_path(dname, audit_mark->path,
                                             AUDIT_NAME_FULL))
                        return 0;
                audit_update_mark(audit_mark, inode);
kernel/audit_watch.c +3 -3
index 3c12fd5b680e..b50c574223fa 100644
@@ -255,7 +255,7 @@ static void audit_watch_log_rule_change(struct audit_krule *r, struct audit_watc
 
 /* Update inode info in audit rules based on filesystem event. */
 static void audit_update_watch(struct audit_parent *parent,
-                              const char *dname, dev_t dev,
+                              const struct qstr *dname, dev_t dev,
                               unsigned long ino, unsigned invalidating)
 {
        struct audit_watch *owatch, *nwatch, *nextw;
@@ -507,9 +507,9 @@ static int audit_watch_handle_event(struct fsnotify_group *group,
        }
 
        if (mask & (FS_CREATE|FS_MOVED_TO) && inode)
-               audit_update_watch(parent, dname->name, inode->i_sb->s_dev, inode->i_ino, 0);
+               audit_update_watch(parent, dname, inode->i_sb->s_dev, inode->i_ino, 0);
        else if (mask & (FS_DELETE|FS_MOVED_FROM))
-               audit_update_watch(parent, dname->name, AUDIT_DEV_UNSET, AUDIT_INO_UNSET, 1);
+               audit_update_watch(parent, dname, AUDIT_DEV_UNSET, AUDIT_INO_UNSET, 1);
        else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF))
                audit_remove_parent_watches(parent);
 
kernel/auditfilter.c +4 -3
index 63f8b3f26fab..6f585b48f4ef 100644
@@ -1290,12 +1290,13 @@ int parent_len(const char *path)
  * @parentlen: length of the parent if known. Passing in AUDIT_NAME_FULL
  *             here indicates that we must compute this value.
  */
-int audit_compare_dname_path(const char *dname, const char *path, int parentlen)
+int audit_compare_dname_path(const struct qstr *dname, const char *path,
+                            int parentlen)
 {
        int dlen, pathlen;
        const char *p;
 
-       dlen = strlen(dname);
+       dlen = dname->len;
        pathlen = strlen(path);
        if (pathlen < dlen)
                return 1;
@@ -1306,7 +1307,7 @@ int audit_compare_dname_path(const char *dname, const char *path, int parentlen)
 
        p = path + parentlen;
 
-       return strncmp(p, dname, dlen);
+       return strncmp(p, dname->name, dlen);
 }
 
 int audit_filter(int msgtype, unsigned int listtype)
kernel/auditsc.c +3 -5
index d1eab1d4a930..05e06b766af1 100644
@@ -2045,7 +2045,6 @@ void __audit_inode_child(struct inode *parent,
 {
        struct audit_context *context = audit_context();
        struct inode *inode = d_backing_inode(dentry);
-       const char *dname = dentry->d_name.name;
        struct audit_names *n, *found_parent = NULL, *found_child = NULL;
        struct audit_entry *e;
        struct list_head *list = &audit_filter_list[AUDIT_FILTER_FS];
@@ -2083,7 +2082,7 @@ void __audit_inode_child(struct inode *parent,
                        continue;
 
                if (n->ino == parent->i_ino && n->dev == parent->i_sb->s_dev &&
-                   !audit_compare_dname_path(dname,
+                   !audit_compare_dname_path(&dentry->d_name,
                                              n->name->name, n->name_len)) {
                        if (n->type == AUDIT_TYPE_UNKNOWN)
                                n->type = AUDIT_TYPE_PARENT;
@@ -2099,8 +2098,8 @@ void __audit_inode_child(struct inode *parent,
                    (n->type != type && n->type != AUDIT_TYPE_UNKNOWN))
                        continue;
 
-               if (!strcmp(dname, n->name->name) ||
-                   !audit_compare_dname_path(dname, n->name->name,
+               if (!strcmp(dentry->d_name.name, n->name->name) ||
+                   !audit_compare_dname_path(&dentry->d_name, n->name->name,
                                                found_parent ?
                                                found_parent->name_len :
                                                AUDIT_NAME_FULL)) {
--

2.20.1

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#7 lore raw
In reply to Jeff Layton
Quoted 8 lines · Jeff Layton

name_snapshot will snapshot the current contents of a dentry's name for later consumption. Several of those users end up needing to do a strlen on the resulting string later. We already have that info in the original dentry though, so we can do this a bit more efficiently by stuffing the name length into the name_snapshot as well.

This is not well tested, but it built and booted. Do we have a testsuite that exercises the fsnotify code, in particular?

FWIW, my variant sits in [email protected].

Quoted 19 lines

Jeff Layton (5):
dcache: track the length of the string in struct name_snapshot
fsnotify: have fsnotify_move take a struct qstr instead of a string
fsnotify: have fsnotify() take a qstr instead of a string
fsnotify: change ->handle_event and send_to_group to take a qstr
audit: fix audit_compare_dname_path to take a qstr

 fs/dcache.c                          | 11 +++++++----
 fs/debugfs/inode.c                   |  2 +-
 fs/kernfs/file.c                     |  6 ++++--
 fs/namei.c                           |  4 ++--
 fs/notify/dnotify/dnotify.c          |  2 +-
 fs/notify/fanotify/fanotify.c        |  2 +-
 fs/notify/fsnotify.c                 |  8 ++++----
 fs/notify/inotify/inotify.h          |  2 +-
 fs/notify/inotify/inotify_fsnotify.c |  6 +++---
 fs/overlayfs/export.c                |  2 +-
 include/linux/dcache.h               |  2 +-
 include/linux/fsnotify.h             | 17 ++++++++---------
Quoted 8 lines
 include/linux/fsnotify_backend.h     |  6 +++---
 kernel/audit.h                       |  3 ++-
 kernel/audit_fsnotify.c              |  5 +++--
 kernel/audit_tree.c                  |  2 +-
 kernel/audit_watch.c                 |  4 ++--
 kernel/auditfilter.c                 |  7 ++++---
 kernel/auditsc.c                     |  7 +++----
 19 files changed, 52 insertions(+), 46 deletions(-)
 fs/dcache.c                          | 14 ++++++--------
 fs/debugfs/inode.c                   |  2 +-
 fs/kernfs/file.c                     |  6 ++++--
 fs/namei.c                           |  4 ++--
 fs/notify/dnotify/dnotify.c          |  2 +-
 fs/notify/fanotify/fanotify.c        |  2 +-
 fs/notify/fsnotify.c                 |  8 ++++----
 fs/notify/inotify/inotify.h          |  2 +-
 fs/notify/inotify/inotify_fsnotify.c |  6 +++---
 fs/overlayfs/export.c                |  2 +-
 include/linux/dcache.h               |  2 +-
 include/linux/fsnotify.h             | 10 +++++-----
 include/linux/fsnotify_backend.h     |  6 +++---
 kernel/audit.h                       |  2 +-
 kernel/audit_fsnotify.c              |  2 +-
 kernel/audit_tree.c                  |  2 +-
 kernel/audit_watch.c                 |  4 ++--
 kernel/auditfilter.c                 |  6 +++---
 kernel/auditsc.c                     |  4 ++--
 19 files changed, 43 insertions(+), 43 deletions(-)

here...

maintainer
#8 lore raw
Quoted 11 lines · Al Viro
Quoted 8 lines · Jeff Layton

name_snapshot will snapshot the current contents of a dentry's name for later consumption. Several of those users end up needing to do a strlen on the resulting string later. We already have that info in the original dentry though, so we can do this a bit more efficiently by stuffing the name length into the name_snapshot as well.

This is not well tested, but it built and booted. Do we have a testsuite that exercises the fsnotify code, in particular?

FWIW, my variant sits in [email protected].

Jan Kara contributed some audit related stress tests to the audit-testsuite (link below). You can find the tests under ./tests_manual/stress_tree.

* https://github.com/linux-audit/audit-testsuite

Signature · 2 lines
paul moore
www.paul-moore.com
#9 lore raw
In reply to Al Viro
Quoted 61 lines · Al Viro
Quoted 8 lines · Jeff Layton

name_snapshot will snapshot the current contents of a dentry's name for later consumption. Several of those users end up needing to do a strlen on the resulting string later. We already have that info in the original dentry though, so we can do this a bit more efficiently by stuffing the name length into the name_snapshot as well.

This is not well tested, but it built and booted. Do we have a testsuite that exercises the fsnotify code, in particular?

FWIW, my variant sits in [email protected].

Quoted 19 lines

Jeff Layton (5):
dcache: track the length of the string in struct name_snapshot
fsnotify: have fsnotify_move take a struct qstr instead of a string
fsnotify: have fsnotify() take a qstr instead of a string
fsnotify: change ->handle_event and send_to_group to take a qstr
audit: fix audit_compare_dname_path to take a qstr

 fs/dcache.c                          | 11 +++++++----
 fs/debugfs/inode.c                   |  2 +-
 fs/kernfs/file.c                     |  6 ++++--
 fs/namei.c                           |  4 ++--
 fs/notify/dnotify/dnotify.c          |  2 +-
 fs/notify/fanotify/fanotify.c        |  2 +-
 fs/notify/fsnotify.c                 |  8 ++++----
 fs/notify/inotify/inotify.h          |  2 +-
 fs/notify/inotify/inotify_fsnotify.c |  6 +++---
 fs/overlayfs/export.c                |  2 +-
 include/linux/dcache.h               |  2 +-
 include/linux/fsnotify.h             | 17 ++++++++---------
Quoted 8 lines
 include/linux/fsnotify_backend.h     |  6 +++---
 kernel/audit.h                       |  3 ++-
 kernel/audit_fsnotify.c              |  5 +++--
 kernel/audit_tree.c                  |  2 +-
 kernel/audit_watch.c                 |  4 ++--
 kernel/auditfilter.c                 |  7 ++++---
 kernel/auditsc.c                     |  7 +++----
 19 files changed, 52 insertions(+), 46 deletions(-)
 fs/dcache.c                          | 14 ++++++--------
 fs/debugfs/inode.c                   |  2 +-
 fs/kernfs/file.c                     |  6 ++++--
 fs/namei.c                           |  4 ++--
 fs/notify/dnotify/dnotify.c          |  2 +-
 fs/notify/fanotify/fanotify.c        |  2 +-
 fs/notify/fsnotify.c                 |  8 ++++----
 fs/notify/inotify/inotify.h          |  2 +-
 fs/notify/inotify/inotify_fsnotify.c |  6 +++---
 fs/overlayfs/export.c                |  2 +-
 include/linux/dcache.h               |  2 +-
 include/linux/fsnotify.h             | 10 +++++-----
 include/linux/fsnotify_backend.h     |  6 +++---
 kernel/audit.h                       |  2 +-
 kernel/audit_fsnotify.c              |  2 +-
 kernel/audit_tree.c                  |  2 +-
 kernel/audit_watch.c                 |  4 ++--
 kernel/auditfilter.c                 |  6 +++---
 kernel/auditsc.c                     |  4 ++--
 19 files changed, 43 insertions(+), 43 deletions(-)
Quoted 1 line

here...

Pretty similar :)

Let's just go with yours then, since it breaks out some of the strlen changes into separate patches.

Cheers,

Signature · 1 line
Jeff Layton <[email protected]>