Skip to content

Commit

Permalink
fanotify: fix event filtering with FAN_ONDIR set
Browse files Browse the repository at this point in the history
With FAN_ONDIR set, the user can end up getting events, which it hasn't
marked.  This was revealed with fanotify04 testcase failure on
Linux-4.0-rc1, and is a regression from 3.19, revealed with 66ba93c
("fanotify: don't set FAN_ONDIR implicitly on a marks ignored mask").

   # /opt/ltp/testcases/bin/fanotify04
   [ ... ]
  fanotify04    7  TPASS  :  event generated properly for type 100000
  fanotify04    8  TFAIL  :  fanotify04.c:147: got unexpected event 30
  fanotify04    9  TPASS  :  No event as expected

The testcase sets the adds the following marks : FAN_OPEN | FAN_ONDIR for
a fanotify on a dir.  Then does an open(), followed by close() of the
directory and expects to see an event FAN_OPEN(0x20).  However, the
fanotify returns (FAN_OPEN|FAN_CLOSE_NOWRITE(0x10)).  This happens due to
the flaw in the check for event_mask in fanotify_should_send_event() which
does:

	if (event_mask & marks_mask & ~marks_ignored_mask)
		return true;

where, event_mask == (FAN_ONDIR | FAN_CLOSE_NOWRITE),
       marks_mask == (FAN_ONDIR | FAN_OPEN),
       marks_ignored_mask == 0

Fix this by masking the outgoing events to the user, as we already take
care of FAN_ONDIR and FAN_EVENT_ON_CHILD.

Signed-off-by: Suzuki K. Poulose <[email protected]>
Tested-by: Lino Sanfilippo <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Cc: Eric Paris <[email protected]>
Cc: Will Deacon <[email protected]>

Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Suzuki K. Poulose authored and torvalds committed Mar 13, 2015
1 parent 5b8bf30 commit b3c1030
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/notify/fanotify/fanotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
!(marks_mask & FS_ISDIR & ~marks_ignored_mask))
return false;

if (event_mask & marks_mask & ~marks_ignored_mask)
if (event_mask & FAN_ALL_OUTGOING_EVENTS & marks_mask &
~marks_ignored_mask)
return true;

return false;
Expand Down

0 comments on commit b3c1030

Please sign in to comment.