fsnotify: consistent behavior for parent not watching children
authorAmir Goldstein <amir73il@gmail.com>
Wed, 11 May 2022 19:02:13 +0000 (22:02 +0300)
committerJan Kara <jack@suse.cz>
Wed, 18 May 2022 13:08:09 +0000 (15:08 +0200)
commite730558adffb88a52e562db089e969ee9510184a
tree518bd7a2fd19903346d8484493480ad4ae2c7961
parent14362a2541797cf9df0e86fb12dcd7950baf566e
fsnotify: consistent behavior for parent not watching children

The logic for handling events on child in groups that have a mark on
the parent inode, but without FS_EVENT_ON_CHILD flag in the mask is
duplicated in several places and inconsistent.

Move the logic into the preparation of mark type iterator, so that the
parent mark type will be excluded from all mark type iterations in that
case.

This results in several subtle changes of behavior, hopefully all
desired changes of behavior, for example:

- Group A has a mount mark with FS_MODIFY in mask
- Group A has a mark with ignore mask that does not survive FS_MODIFY
  and does not watch children on directory D.
- Group B has a mark with FS_MODIFY in mask that does watch children
  on directory D.
- FS_MODIFY event on file D/foo should not clear the ignore mask of
  group A, but before this change it does

And if group A ignore mask was set to survive FS_MODIFY:
- FS_MODIFY event on file D/foo should be reported to group A on account
  of the mount mark, but before this change it is wrongly ignored

Fixes: 2f02fd3fa13e ("fanotify: fix ignore mask logic for events on child and on dir")
Reported-by: Jan Kara <jack@suse.com>
Link: https://lore.kernel.org/linux-fsdevel/20220314113337.j7slrb5srxukztje@quack3.lan/
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20220511190213.831646-3-amir73il@gmail.com
fs/notify/fanotify/fanotify.c
fs/notify/fsnotify.c