fsnotify: Protect fsnotify_handle_inode_event from no-inode events
authorGabriel Krisman Bertazi <krisman@collabora.com>
Mon, 25 Oct 2021 19:27:26 +0000 (16:27 -0300)
committerJan Kara <jack@suse.cz>
Wed, 27 Oct 2021 10:34:12 +0000 (12:34 +0200)
FAN_FS_ERROR allows events without inodes - i.e. for file system-wide
errors.  Even though fsnotify_handle_inode_event is not currently used
by fanotify, this patch protects other backends from cases where neither
inode or dir are provided.  Also document the constraints of the
interface (inode and dir cannot be both NULL).

Link: https://lore.kernel.org/r/20211025192746.66445-12-krisman@collabora.com
Suggested-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/nfsd/filecache.c
fs/notify/fsnotify.c
include/linux/fsnotify_backend.h

index be3c1aad50ea3974433f39b3e6f362f2f0839155..fdf89fcf1a0ca17ac03ab3027b1b36512c408aa0 100644 (file)
@@ -602,6 +602,9 @@ nfsd_file_fsnotify_handle_event(struct fsnotify_mark *mark, u32 mask,
                                struct inode *inode, struct inode *dir,
                                const struct qstr *name, u32 cookie)
 {
+       if (WARN_ON_ONCE(!inode))
+               return 0;
+
        trace_nfsd_file_fsnotify_handle_event(inode, mask);
 
        /* Should be no marks on non-regular files */
index fde3a1115a170c905991b99b708befdade0220a3..4034ca566f95cedcb01480b0640be4b770539eec 100644 (file)
@@ -252,6 +252,9 @@ static int fsnotify_handle_inode_event(struct fsnotify_group *group,
        if (WARN_ON_ONCE(!ops->handle_inode_event))
                return 0;
 
+       if (WARN_ON_ONCE(!inode && !dir))
+               return 0;
+
        if ((inode_mark->mask & FS_EXCL_UNLINK) &&
            path && d_unlinked(path->dentry))
                return 0;
index 035438fe4a435e849b4cdfd000307af0b065971b..b71dc788018e4755495f53ebb34702c33462de52 100644 (file)
@@ -136,6 +136,7 @@ struct mem_cgroup;
  * @dir:       optional directory associated with event -
  *             if @file_name is not NULL, this is the directory that
  *             @file_name is relative to.
+ *             Either @inode or @dir must be non-NULL.
  * @file_name: optional file name associated with event
  * @cookie:    inotify rename cookie
  *