Skip to content

Commit 2f02fd3

Browse files
amir73iljankara
authored andcommitted
fanotify: fix ignore mask logic for events on child and on dir
The comments in fanotify_group_event_mask() say: "If the event is on dir/child and this mark doesn't care about events on dir/child, don't send it!" Specifically, mount and filesystem marks do not care about events on child, but they can still specify an ignore mask for those events. For example, a group that has: - A mount mark with mask 0 and ignore_mask FAN_OPEN - An inode mark on a directory with mask FAN_OPEN | FAN_OPEN_EXEC with flag FAN_EVENT_ON_CHILD A child file open for exec would be reported to group with the FAN_OPEN event despite the fact that FAN_OPEN is in ignore mask of mount mark, because the mark iteration loop skips over non-inode marks for events on child when calculating the ignore mask. Move ignore mask calculation to the top of the iteration loop block before excluding marks for events on dir/child. Link: https://lore.kernel.org/r/[email protected] Reported-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/linux-fsdevel/[email protected]/ Fixes: 55bf882 "fanotify: fix merging marks masks with FAN_ONDIR" Fixes: b469e7e "fanotify: fix handling of events on child..." Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 5e23663 commit 2f02fd3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
232232
if (!fsnotify_iter_should_report_type(iter_info, type))
233233
continue;
234234
mark = iter_info->marks[type];
235+
236+
/* Apply ignore mask regardless of ISDIR and ON_CHILD flags */
237+
marks_ignored_mask |= mark->ignored_mask;
238+
235239
/*
236240
* If the event is on dir and this mark doesn't care about
237241
* events on dir, don't send it!
@@ -249,7 +253,6 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
249253
continue;
250254

251255
marks_mask |= mark->mask;
252-
marks_ignored_mask |= mark->ignored_mask;
253256
}
254257

255258
test_mask = event_mask & marks_mask & ~marks_ignored_mask;

0 commit comments

Comments
 (0)