Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752389AbbB0Lk7 (ORCPT ); Fri, 27 Feb 2015 06:40:59 -0500 Received: from service87.mimecast.com ([91.220.42.44]:51618 "EHLO service87.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750777AbbB0Lk5 (ORCPT ); Fri, 27 Feb 2015 06:40:57 -0500 From: "Suzuki K. Poulose" To: Lino Sanfilippo Cc: linux-kernel@vger.kernel.org, "Suzuki K. Poulose" , Jan Kara , Eric Paris , Andrew Morton , Will Deacon Subject: [PATCH] fanotify: Fix event filtering with FAN_ONDIR set Date: Fri, 27 Feb 2015 11:40:39 +0000 Message-Id: <1425037239-18881-1-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 1.7.9.5 X-OriginalArrivalTime: 27 Feb 2015 11:40:53.0843 (UTC) FILETIME=[3E507230:01D05282] X-MC-Unique: 115022711405502201 Content-Type: text/plain; charset=WINDOWS-1252 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id t1RBf9sI008538 Content-Length: 2364 Lines: 65 From: "Suzuki K. Poulose" 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 Cc: Jan Kara Cc: Eric Paris Cc: Andrew Morton Cc: Will Deacon Signed-off-by: Suzuki K. Poulose --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/