Skip to content

Commit 55bf882

Browse files
amir73iljankara
authored andcommitted
fanotify: fix merging marks masks with FAN_ONDIR
Change the logic of FAN_ONDIR in two ways that are similar to the logic of FAN_EVENT_ON_CHILD, that was fixed in commit 54a307b ("fanotify: fix logic of events on child"): 1. The flag is meaningless in ignore mask 2. The flag refers only to events in the mask of the mark where it is set This is what the fanotify_mark.2 man page says about FAN_ONDIR: "Without this flag, only events for files are created." It doesn't say anything about setting this flag in ignore mask to stop getting events on directories nor can I think of any setup where this capability would be useful. Currently, when marks masks are merged, the FAN_ONDIR flag set in one mark affects the events that are set in another mark's mask and this behavior causes unexpected results. For example, a user adds a mark on a directory with mask FAN_ATTRIB | FAN_ONDIR and a mount mark with mask FAN_OPEN (without FAN_ONDIR). An opendir() of that directory (which is inside that mount) generates a FAN_OPEN event even though neither of the marks requested to get open events on directories. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent f367a62 commit 55bf882

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
171171
if (!fsnotify_iter_should_report_type(iter_info, type))
172172
continue;
173173
mark = iter_info->marks[type];
174+
/*
175+
* If the event is on dir and this mark doesn't care about
176+
* events on dir, don't send it!
177+
*/
178+
if (event_mask & FS_ISDIR && !(mark->mask & FS_ISDIR))
179+
continue;
180+
174181
/*
175182
* If the event is for a child and this mark doesn't care about
176183
* events on a child, don't send it!
@@ -203,10 +210,6 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
203210
user_mask &= ~FAN_ONDIR;
204211
}
205212

206-
if (event_mask & FS_ISDIR &&
207-
!(marks_mask & FS_ISDIR & ~marks_ignored_mask))
208-
return 0;
209-
210213
return test_mask & user_mask;
211214
}
212215

0 commit comments

Comments
 (0)