linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Suzuki K. Poulose" <suzuki.poulose@arm.com>
To: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: linux-kernel@vger.kernel.org,
	"Suzuki K. Poulose" <suzuki.poulose@arm.com>,
	Jan Kara <jack@suse.cz>, Eric Paris <eparis@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Will Deacon <will.deacon@arm.com>
Subject: [PATCH] fanotify: Fix event filtering with FAN_ONDIR set
Date: Fri, 27 Feb 2015 11:40:39 +0000	[thread overview]
Message-ID: <1425037239-18881-1-git-send-email-suzuki.poulose@arm.com> (raw)

From: "Suzuki K. Poulose" <suzuki.poulose@arm.com>

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 commit (66ba93c0d7fe6: 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.

Cc: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: Jan Kara <jack@suse.cz>
Cc: Eric Paris <eparis@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Suzuki K. Poulose <suzuki.poulose@arm.com>
---
 fs/notify/fanotify/fanotify.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 9a66ff7..d2f97ec 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -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;
-- 
1.7.9.5



             reply	other threads:[~2015-02-27 11:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 11:40 Suzuki K. Poulose [this message]
2015-03-01  2:31 ` [PATCH] fanotify: Fix event filtering with FAN_ONDIR set Lino Sanfilippo
2015-03-02 10:38 ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425037239-18881-1-git-send-email-suzuki.poulose@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=LinoSanfilippo@gmx.de \
    --cc=akpm@linux-foundation.org \
    --cc=eparis@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).