[03/22] fanotify: Move recalculation of inode / vfsmount mask under mark_mutex
diff mbox

Message ID 20161222091538.28702-4-jack@suse.cz
State New
Headers show

Commit Message

Jan Kara Dec. 22, 2016, 9:15 a.m. UTC
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.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/notify/fanotify/fanotify_user.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Amir Goldstein Dec. 22, 2016, 4:27 p.m. UTC | #1
On Thu, Dec 22, 2016 at 11:15 AM, Jan Kara <jack@suse.cz> wrote:
> 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.
>

What am I missing this time?

dnotify_handle_event()
   dnotify_recalc_inode_mask()
      fsnotify_recalc_inode_mask() /* not under dnotify_group->mark_mutex */
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jan Kara Dec. 22, 2016, 5:31 p.m. UTC | #2
On Thu 22-12-16 18:27:11, Amir Goldstein wrote:
> On Thu, Dec 22, 2016 at 11:15 AM, Jan Kara <jack@suse.cz> wrote:
> > 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.
> >
> 
> What am I missing this time?
> 
> dnotify_handle_event()
>    dnotify_recalc_inode_mask()
>       fsnotify_recalc_inode_mask() /* not under dnotify_group->mark_mutex */

Dnotify uses mark->lock to protect recalculation of mask which also
protects mark from being removed from the list.

								Honza
Amir Goldstein Dec. 22, 2016, 7:08 p.m. UTC | #3
On Thu, Dec 22, 2016 at 7:31 PM, Jan Kara <jack@suse.cz> wrote:
> On Thu 22-12-16 18:27:11, Amir Goldstein wrote:
>> On Thu, Dec 22, 2016 at 11:15 AM, Jan Kara <jack@suse.cz> wrote:
>> > 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.
>> >
>>
>> What am I missing this time?
>>
>> dnotify_handle_event()
>>    dnotify_recalc_inode_mask()
>>       fsnotify_recalc_inode_mask() /* not under dnotify_group->mark_mutex */
>
> Dnotify uses mark->lock to protect recalculation of mask which also
> protects mark from being removed from the list.
>

Right. Thanks for clarifying.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 7ebfca6a1427..8dcec9eecafd 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -541,6 +541,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);
@@ -548,9 +550,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;
 }
 
@@ -571,6 +570,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);
@@ -579,8 +580,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;
 }
@@ -656,10 +655,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;
@@ -694,10 +692,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;