linux-brain/fs/notify
Amir Goldstein 987d8ff3a2 fanotify: fix handling of events on child sub-directory
commit b469e7e47c upstream.

When an event is reported on a sub-directory and the parent inode has
a mark mask with FS_EVENT_ON_CHILD|FS_ISDIR, the event will be sent to
fsnotify() even if the event type is not in the parent mark mask
(e.g. FS_OPEN).

Further more, if that event happened on a mount or a filesystem with
a mount/sb mark that does have that event type in their mask, the "on
child" event will be reported on the mount/sb mark.  That is not
desired, because user will get a duplicate event for the same action.

Note that the event reported on the victim inode is never merged with
the event reported on the parent inode, because of the check in
should_merge(): old_fsn->inode == new_fsn->inode.

Fix this by looking for a match of an actual event type (i.e. not just
FS_ISDIR) in parent's inode mark mask and by not reporting an "on child"
event to group if event type is only found on mount/sb marks.

[backport hint: The bug seems to have always been in fanotify, but this
                patch will only apply cleanly to v4.19.y]

Cc: <stable@vger.kernel.org> # v4.19
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
[amir: backport to v4.9]
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-06 17:33:30 +01:00
..
dnotify fsnotify: get rid of fsnotify_destroy_mark_locked() 2015-09-04 16:54:41 -07:00
fanotify fanotify: fix logic of events on child 2018-04-24 09:34:18 +02:00
inotify fsnotify: convert notification_mutex to a spinlock 2016-10-07 18:46:26 -07:00
Kconfig rcu: Make SRCU optional by using CONFIG_SRCU 2015-01-06 11:04:29 -08:00
Makefile fs, notify: add procfs fdinfo helper 2012-12-17 17:15:28 -08:00
fdinfo.c inotify: hide internal kernel bits from fdinfo 2015-11-05 19:34:48 -08:00
fdinfo.h fs: Convert show_fdinfo functions to void 2014-11-05 14:13:23 -05:00
fsnotify.c fanotify: fix handling of events on child sub-directory 2019-02-06 17:33:30 +01:00
fsnotify.h fsnotify: avoid spurious EMFILE errors from inotify_init() 2016-05-19 19:12:14 -07:00
group.c fsnotify: convert notification_mutex to a spinlock 2016-10-07 18:46:26 -07:00
inode_mark.c fsnotify: Fix possible use-after-free in inode iteration on umount 2017-01-09 08:32:22 +01:00
mark.c fsnotify: avoid spurious EMFILE errors from inotify_init() 2016-05-19 19:12:14 -07:00
notification.c fsnotify: clean up spinlock assertions 2016-10-07 18:46:26 -07:00
vfsmount_mark.c fsnotify: remove mark->free_list 2015-09-04 16:54:41 -07:00