]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fsnotify: clarify contract for create event hooks
authorAmir Goldstein <amir73il@gmail.com>
Mon, 25 Oct 2021 19:27:18 +0000 (16:27 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:18:49 +0000 (16:18 +0200)
[ Upstream commit dabe729dddca550446e9cc118c96d1f91703345b ]

Clarify argument names and contract for fsnotify_create() and
fsnotify_mkdir() to reflect the anomaly of kernfs, which leaves dentries
negavite after mkdir/create.

Remove the WARN_ON(!inode) in audit code that were added by the Fixes
commit under the wrong assumption that dentries cannot be negative after
mkdir/create.

Fixes: aa93bdc5500c ("fsnotify: use helpers to access data by data_type")
Link: https://lore.kernel.org/linux-fsdevel/87mtp5yz0q.fsf@collabora.com/
Link: https://lore.kernel.org/r/20211025192746.66445-4-krisman@collabora.com
Reviewed-by: Jan Kara <jack@suse.cz>
Reported-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
include/linux/fsnotify.h
kernel/audit_fsnotify.c
kernel/audit_watch.c

index 70e6b147a76ad804ab08c1c056f57e3bb45fc7ea..a327a95fa68f1694a0b1b69a8488b6314a284a74 100644 (file)
@@ -192,16 +192,22 @@ static inline void fsnotify_inoderemove(struct inode *inode)
 
 /*
  * fsnotify_create - 'name' was linked in
+ *
+ * Caller must make sure that dentry->d_name is stable.
+ * Note: some filesystems (e.g. kernfs) leave @dentry negative and instantiate
+ * ->d_inode later
  */
-static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
+static inline void fsnotify_create(struct inode *dir, struct dentry *dentry)
 {
-       audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE);
+       audit_inode_child(dir, dentry, AUDIT_TYPE_CHILD_CREATE);
 
-       fsnotify_dirent(inode, dentry, FS_CREATE);
+       fsnotify_dirent(dir, dentry, FS_CREATE);
 }
 
 /*
  * fsnotify_link - new hardlink in 'inode' directory
+ *
+ * Caller must make sure that new_dentry->d_name is stable.
  * Note: We have to pass also the linked inode ptr as some filesystems leave
  *   new_dentry->d_inode NULL and instantiate inode pointer later
  */
@@ -266,12 +272,16 @@ static inline void fsnotify_unlink(struct inode *dir, struct dentry *dentry)
 
 /*
  * fsnotify_mkdir - directory 'name' was created
+ *
+ * Caller must make sure that dentry->d_name is stable.
+ * Note: some filesystems (e.g. kernfs) leave @dentry negative and instantiate
+ * ->d_inode later
  */
-static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
+static inline void fsnotify_mkdir(struct inode *dir, struct dentry *dentry)
 {
-       audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE);
+       audit_inode_child(dir, dentry, AUDIT_TYPE_CHILD_CREATE);
 
-       fsnotify_dirent(inode, dentry, FS_CREATE | FS_ISDIR);
+       fsnotify_dirent(dir, dentry, FS_CREATE | FS_ISDIR);
 }
 
 /*
index c428312938e95b061c68f45b989207a2767fd012..7a506b65e863052ff2e21b241beb8e3318c14a5c 100644 (file)
@@ -161,8 +161,7 @@ static int audit_mark_handle_event(struct fsnotify_mark *inode_mark, u32 mask,
 
        audit_mark = container_of(inode_mark, struct audit_fsnotify_mark, mark);
 
-       if (WARN_ON_ONCE(inode_mark->group != audit_fsnotify_group) ||
-           WARN_ON_ONCE(!inode))
+       if (WARN_ON_ONCE(inode_mark->group != audit_fsnotify_group))
                return 0;
 
        if (mask & (FS_CREATE|FS_MOVED_TO|FS_DELETE|FS_MOVED_FROM)) {
index edbeffee64b8e51aef586ed8dfe44bf812cc6e25..fd7b30a2d9a4bf81b797280bc1732088c8c0f52e 100644 (file)
@@ -472,8 +472,7 @@ static int audit_watch_handle_event(struct fsnotify_mark *inode_mark, u32 mask,
 
        parent = container_of(inode_mark, struct audit_parent, mark);
 
-       if (WARN_ON_ONCE(inode_mark->group != audit_watch_group) ||
-           WARN_ON_ONCE(!inode))
+       if (WARN_ON_ONCE(inode_mark->group != audit_watch_group))
                return 0;
 
        if (mask & (FS_CREATE|FS_MOVED_TO) && inode)