public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fanotify: Fix event filtering with FAN_ONDIR set
@ 2015-02-27 11:40 Suzuki K. Poulose
  2015-03-01  2:31 ` Lino Sanfilippo
  2015-03-02 10:38 ` Jan Kara
  0 siblings, 2 replies; 3+ messages in thread
From: Suzuki K. Poulose @ 2015-02-27 11:40 UTC (permalink / raw)
  To: Lino Sanfilippo
  Cc: linux-kernel, Suzuki K. Poulose, Jan Kara, Eric Paris,
	Andrew Morton, Will Deacon

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fanotify: Fix event filtering with FAN_ONDIR set
  2015-02-27 11:40 [PATCH] fanotify: Fix event filtering with FAN_ONDIR set Suzuki K. Poulose
@ 2015-03-01  2:31 ` Lino Sanfilippo
  2015-03-02 10:38 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Lino Sanfilippo @ 2015-03-01  2:31 UTC (permalink / raw)
  To: Suzuki K. Poulose
  Cc: linux-kernel, Jan Kara, Eric Paris, Andrew Morton, Will Deacon

Hi Suzuki,

On 27.02.2015 12:40, Suzuki K. Poulose wrote:
> 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).
> 

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

thank you for fixing this. I tested your solution and it works, so you
can add Tested-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>.

Regards,
Lino





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fanotify: Fix event filtering with FAN_ONDIR set
  2015-02-27 11:40 [PATCH] fanotify: Fix event filtering with FAN_ONDIR set Suzuki K. Poulose
  2015-03-01  2:31 ` Lino Sanfilippo
@ 2015-03-02 10:38 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2015-03-02 10:38 UTC (permalink / raw)
  To: Suzuki K. Poulose
  Cc: Lino Sanfilippo, linux-kernel, Jan Kara, Eric Paris,
	Andrew Morton, Will Deacon

On Fri 27-02-15 11:40:39, Suzuki K. Poulose wrote:
> 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>
  Thanks for the fix. I should have run LTP myself. You can add:
Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  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
> 
> 
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-02 10:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-27 11:40 [PATCH] fanotify: Fix event filtering with FAN_ONDIR set Suzuki K. Poulose
2015-03-01  2:31 ` Lino Sanfilippo
2015-03-02 10:38 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox