linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] vfs: track the dentry name length in name_snapshot
@ 2019-04-26 18:28 Jeff Layton
  2019-04-26 18:28 ` [PATCH 1/5] dcache: track the length of the string in struct name_snapshot Jeff Layton
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Jeff Layton @ 2019-04-26 18:28 UTC (permalink / raw)
  To: viro
  Cc: linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack, amir73il,
	paul, eparis, linux-audit, rafael

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(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/5] dcache: track the length of the string in struct name_snapshot
  2019-04-26 18:28 [PATCH 0/5] vfs: track the dentry name length in name_snapshot Jeff Layton
@ 2019-04-26 18:28 ` Jeff Layton
  2019-04-26 18:28 ` [PATCH 2/5] fsnotify: have fsnotify_move take a struct qstr instead of a string Jeff Layton
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jeff Layton @ 2019-04-26 18:28 UTC (permalink / raw)
  To: viro
  Cc: linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack, amir73il,
	paul, eparis, linux-audit, rafael

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.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 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(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index aac41adf4743..a8dcc27ce2d0 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -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);
 	}
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index f25daa207421..37c0a025d7e8 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -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);
diff --git a/fs/namei.c b/fs/namei.c
index dede0147b3f6..c96713077326 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -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,
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index df06f3da166c..fb22f76329ae 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -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);
 	}
 
diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c
index 54e5d17d7f3e..cc1c9e5606ba 100644
--- a/fs/overlayfs/export.c
+++ b/fs/overlayfs/export.c
@@ -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;
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 60996e64c579..2ff5f3bb9ddc 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -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 *);
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index 09587e2860b5..e09cfff69bb2 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -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);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/5] fsnotify: have fsnotify_move take a struct qstr instead of a string
  2019-04-26 18:28 [PATCH 0/5] vfs: track the dentry name length in name_snapshot Jeff Layton
  2019-04-26 18:28 ` [PATCH 1/5] dcache: track the length of the string in struct name_snapshot Jeff Layton
@ 2019-04-26 18:28 ` Jeff Layton
  2019-04-26 18:28 ` [PATCH 3/5] fsnotify: have fsnotify() take a " Jeff Layton
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jeff Layton @ 2019-04-26 18:28 UTC (permalink / raw)
  To: viro
  Cc: linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack, amir73il,
	paul, eparis, linux-audit, rafael

With this, ovl_lookup_real_one can skip the strlen call.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/debugfs/inode.c       |  2 +-
 fs/namei.c               |  4 ++--
 include/linux/fsnotify.h | 11 +++++------
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 37c0a025d7e8..5dbeefa69a58 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -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);
diff --git a/fs/namei.c b/fs/namei.c
index c96713077326..5ebd64b21970 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -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);
 		}
 	}
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index e09cfff69bb2..2de90a7e388b 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -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);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/5] fsnotify: have fsnotify() take a qstr instead of a string
  2019-04-26 18:28 [PATCH 0/5] vfs: track the dentry name length in name_snapshot Jeff Layton
  2019-04-26 18:28 ` [PATCH 1/5] dcache: track the length of the string in struct name_snapshot Jeff Layton
  2019-04-26 18:28 ` [PATCH 2/5] fsnotify: have fsnotify_move take a struct qstr instead of a string Jeff Layton
@ 2019-04-26 18:28 ` Jeff Layton
  2019-04-26 18:28 ` [PATCH 4/5] fsnotify: change ->handle_event and send_to_group to take a qstr Jeff Layton
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jeff Layton @ 2019-04-26 18:28 UTC (permalink / raw)
  To: viro
  Cc: linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack, amir73il,
	paul, eparis, linux-audit, rafael

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

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 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(-)

diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index ae948aaa4c53..a43283c515f4 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -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);
 	}
 
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index fb22f76329ae..9cbb5ae11d2f 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -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;
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index 2de90a7e388b..66e322df78a3 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -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);
 }
 
 /*
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index dfc28fcb4de8..7eb7821766d5 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -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;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/5] fsnotify: change ->handle_event and send_to_group to take a qstr
  2019-04-26 18:28 [PATCH 0/5] vfs: track the dentry name length in name_snapshot Jeff Layton
                   ` (2 preceding siblings ...)
  2019-04-26 18:28 ` [PATCH 3/5] fsnotify: have fsnotify() take a " Jeff Layton
@ 2019-04-26 18:28 ` Jeff Layton
  2019-04-26 18:28 ` [PATCH 5/5] audit: fix audit_compare_dname_path " Jeff Layton
  2019-04-26 18:51 ` [PATCH 0/5] vfs: track the dentry name length in name_snapshot Al Viro
  5 siblings, 0 replies; 10+ messages in thread
From: Jeff Layton @ 2019-04-26 18:28 UTC (permalink / raw)
  To: viro
  Cc: linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack, amir73il,
	paul, eparis, linux-audit, rafael

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 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(-)

diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
index 58d77dc696eb..250369d6901d 100644
--- a/fs/notify/dnotify/dnotify.c
+++ b/fs/notify/dnotify/dnotify.c
@@ -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);
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 6b9c27548997..a34d7e003d7d 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -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;
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 9cbb5ae11d2f..5433e37fb0c5 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -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;
diff --git a/fs/notify/inotify/inotify.h b/fs/notify/inotify/inotify.h
index 74ae60305189..3f246f7b8a92 100644
--- a/fs/notify/inotify/inotify.h
+++ b/fs/notify/inotify/inotify.h
@@ -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;
diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index ff30abd6a49b..7e8b131029f8 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -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) {
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 7eb7821766d5..c28f6ed1f59b 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -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);
diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c
index 37ae95cfb7f4..6def7f426ba6 100644
--- a/kernel/audit_fsnotify.c
+++ b/kernel/audit_fsnotify.c
@@ -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))
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
index abfb112f26aa..e49c912f862d 100644
--- a/kernel/audit_tree.c
+++ b/kernel/audit_tree.c
@@ -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;
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index e8d1adeb2223..3c12fd5b680e 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -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);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/5] audit: fix audit_compare_dname_path to take a qstr
  2019-04-26 18:28 [PATCH 0/5] vfs: track the dentry name length in name_snapshot Jeff Layton
                   ` (3 preceding siblings ...)
  2019-04-26 18:28 ` [PATCH 4/5] fsnotify: change ->handle_event and send_to_group to take a qstr Jeff Layton
@ 2019-04-26 18:28 ` Jeff Layton
  2019-04-26 19:02   ` Paul Moore
  2019-04-26 18:51 ` [PATCH 0/5] vfs: track the dentry name length in name_snapshot Al Viro
  5 siblings, 1 reply; 10+ messages in thread
From: Jeff Layton @ 2019-04-26 18:28 UTC (permalink / raw)
  To: viro
  Cc: linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack, amir73il,
	paul, eparis, linux-audit, rafael

...and eliminate its strlen call.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 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(-)

diff --git a/kernel/audit.h b/kernel/audit.h
index 958d5b8fc1b3..8c581fd38050 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -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);
diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c
index 6def7f426ba6..af281e965d24 100644
--- a/kernel/audit_fsnotify.c
+++ b/kernel/audit_fsnotify.c
@@ -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);
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index 3c12fd5b680e..b50c574223fa 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -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);
 
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 63f8b3f26fab..6f585b48f4ef 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -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)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index d1eab1d4a930..05e06b766af1 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/5] vfs: track the dentry name length in name_snapshot
  2019-04-26 18:28 [PATCH 0/5] vfs: track the dentry name length in name_snapshot Jeff Layton
                   ` (4 preceding siblings ...)
  2019-04-26 18:28 ` [PATCH 5/5] audit: fix audit_compare_dname_path " Jeff Layton
@ 2019-04-26 18:51 ` Al Viro
  2019-04-26 18:59   ` Paul Moore
  2019-04-26 19:03   ` Jeff Layton
  5 siblings, 2 replies; 10+ messages in thread
From: Al Viro @ 2019-04-26 18:51 UTC (permalink / raw)
  To: Jeff Layton
  Cc: linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack, amir73il,
	paul, eparis, linux-audit, rafael

On Fri, Apr 26, 2019 at 02:28:42PM -0400, Jeff Layton wrote:
> 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 vfs.git@work.dcache.

> 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(-)

 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...

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/5] vfs: track the dentry name length in name_snapshot
  2019-04-26 18:51 ` [PATCH 0/5] vfs: track the dentry name length in name_snapshot Al Viro
@ 2019-04-26 18:59   ` Paul Moore
  2019-04-26 19:03   ` Jeff Layton
  1 sibling, 0 replies; 10+ messages in thread
From: Paul Moore @ 2019-04-26 18:59 UTC (permalink / raw)
  To: Jeff Layton
  Cc: Al Viro, linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack,
	amir73il, Eric Paris, linux-audit, rafael

On Fri, Apr 26, 2019 at 2:52 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Fri, Apr 26, 2019 at 02:28:42PM -0400, Jeff Layton wrote:
> > 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 vfs.git@work.dcache.

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

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/5] audit: fix audit_compare_dname_path to take a qstr
  2019-04-26 18:28 ` [PATCH 5/5] audit: fix audit_compare_dname_path " Jeff Layton
@ 2019-04-26 19:02   ` Paul Moore
  0 siblings, 0 replies; 10+ messages in thread
From: Paul Moore @ 2019-04-26 19:02 UTC (permalink / raw)
  To: Jeff Layton
  Cc: viro, linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack,
	amir73il, Eric Paris, linux-audit, rafael

On Fri, Apr 26, 2019 at 2:28 PM Jeff Layton <jlayton@kernel.org> wrote:
>
> ...and eliminate its strlen call.
>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
>  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.

Acked-by: Paul Moore <paul@paul-moore.com>

> diff --git a/kernel/audit.h b/kernel/audit.h
> index 958d5b8fc1b3..8c581fd38050 100644
> --- a/kernel/audit.h
> +++ b/kernel/audit.h
> @@ -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);
> diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c
> index 6def7f426ba6..af281e965d24 100644
> --- a/kernel/audit_fsnotify.c
> +++ b/kernel/audit_fsnotify.c
> @@ -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);
> diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
> index 3c12fd5b680e..b50c574223fa 100644
> --- a/kernel/audit_watch.c
> +++ b/kernel/audit_watch.c
> @@ -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);
>
> diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
> index 63f8b3f26fab..6f585b48f4ef 100644
> --- a/kernel/auditfilter.c
> +++ b/kernel/auditfilter.c
> @@ -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)
> diff --git a/kernel/auditsc.c b/kernel/auditsc.c
> index d1eab1d4a930..05e06b766af1 100644
> --- a/kernel/auditsc.c
> +++ b/kernel/auditsc.c
> @@ -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
>


-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/5] vfs: track the dentry name length in name_snapshot
  2019-04-26 18:51 ` [PATCH 0/5] vfs: track the dentry name length in name_snapshot Al Viro
  2019-04-26 18:59   ` Paul Moore
@ 2019-04-26 19:03   ` Jeff Layton
  1 sibling, 0 replies; 10+ messages in thread
From: Jeff Layton @ 2019-04-26 19:03 UTC (permalink / raw)
  To: Al Viro
  Cc: linux-kernel, linux-fsdevel, miklos, gregkh, tj, jack, amir73il,
	paul, eparis, linux-audit, rafael

On Fri, 2019-04-26 at 19:51 +0100, Al Viro wrote:
> On Fri, Apr 26, 2019 at 02:28:42PM -0400, Jeff Layton wrote:
> > 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 vfs.git@work.dcache.
> 
> > 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(-)
> 
>  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...

Pretty similar :)

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

Cheers,
-- 
Jeff Layton <jlayton@kernel.org>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-04-26 19:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 18:28 [PATCH 0/5] vfs: track the dentry name length in name_snapshot Jeff Layton
2019-04-26 18:28 ` [PATCH 1/5] dcache: track the length of the string in struct name_snapshot Jeff Layton
2019-04-26 18:28 ` [PATCH 2/5] fsnotify: have fsnotify_move take a struct qstr instead of a string Jeff Layton
2019-04-26 18:28 ` [PATCH 3/5] fsnotify: have fsnotify() take a " Jeff Layton
2019-04-26 18:28 ` [PATCH 4/5] fsnotify: change ->handle_event and send_to_group to take a qstr Jeff Layton
2019-04-26 18:28 ` [PATCH 5/5] audit: fix audit_compare_dname_path " Jeff Layton
2019-04-26 19:02   ` Paul Moore
2019-04-26 18:51 ` [PATCH 0/5] vfs: track the dentry name length in name_snapshot Al Viro
2019-04-26 18:59   ` Paul Moore
2019-04-26 19:03   ` Jeff Layton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).