fanotify: Move recalculation of inode / vfsmount mask under mark_mutex
authorJan Kara <jack@suse.cz>
Wed, 14 Dec 2016 12:53:46 +0000 (13:53 +0100)
committerJan Kara <jack@suse.cz>
Mon, 3 Apr 2017 14:56:40 +0000 (16:56 +0200)
Move recalculation of inode / vfsmount notification mask under
group->mark_mutex of the mark which was modified. These are the only
places where mask recalculation happens without mark being protected
from detaching from inode / vfsmount which will cause issues with the
following patches.

Reviewed-by: Miklos Szeredi <mszeredi@redhat.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/notify/fanotify/fanotify_user.c

index 2b37f27858345ccf7bca6747768df11680067a1e..c5e69870287f10b492119d25bb4c927532615427 100644 (file)
@@ -542,6 +542,8 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group,
 
        removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
                                                 &destroy_mark);
+       if (removed & real_mount(mnt)->mnt_fsnotify_mask)
+               fsnotify_recalc_vfsmount_mask(mnt);
        if (destroy_mark)
                fsnotify_detach_mark(fsn_mark);
        mutex_unlock(&group->mark_mutex);
@@ -549,9 +551,6 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group,
                fsnotify_free_mark(fsn_mark);
 
        fsnotify_put_mark(fsn_mark);
-       if (removed & real_mount(mnt)->mnt_fsnotify_mask)
-               fsnotify_recalc_vfsmount_mask(mnt);
-
        return 0;
 }
 
@@ -572,6 +571,8 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group,
 
        removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
                                                 &destroy_mark);
+       if (removed & inode->i_fsnotify_mask)
+               fsnotify_recalc_inode_mask(inode);
        if (destroy_mark)
                fsnotify_detach_mark(fsn_mark);
        mutex_unlock(&group->mark_mutex);
@@ -580,8 +581,6 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group,
 
        /* matches the fsnotify_find_inode_mark() */
        fsnotify_put_mark(fsn_mark);
-       if (removed & inode->i_fsnotify_mask)
-               fsnotify_recalc_inode_mask(inode);
 
        return 0;
 }
@@ -657,10 +656,9 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
                }
        }
        added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
-       mutex_unlock(&group->mark_mutex);
-
        if (added & ~real_mount(mnt)->mnt_fsnotify_mask)
                fsnotify_recalc_vfsmount_mask(mnt);
+       mutex_unlock(&group->mark_mutex);
 
        fsnotify_put_mark(fsn_mark);
        return 0;
@@ -695,10 +693,9 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
                }
        }
        added = fanotify_mark_add_to_mask(fsn_mark, mask, flags);
-       mutex_unlock(&group->mark_mutex);
-
        if (added & ~inode->i_fsnotify_mask)
                fsnotify_recalc_inode_mask(inode);
+       mutex_unlock(&group->mark_mutex);
 
        fsnotify_put_mark(fsn_mark);
        return 0;