Re: [PATCH] fanotify: dont destroy mark when ignore mask is cleared

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 23, 2010 at 02:51:19PM -0500, Eric Paris wrote:

> 
> Hmmmm, really I'm not sure if that is right either (but it's certainly
> closer)  What about something like:
> 
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 81df3ad..29fbf17 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -527,7 +527,7 @@ static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark,
>  	}
>  	spin_unlock(&fsn_mark->lock);
>  
> -	if (!(oldmask & ~mask))
> +	if (!fsn_mark->mask && !fsn_mark->ignored_mask)
>  		fsnotify_destroy_mark(fsn_mark);
>  
>  	return mask & oldmask;
> 
> 

Yep, youre right, we should also check the ignore mask before we destroy the mark.

BUT:
1. There is this flag FAN_MARK_ONDIR which is set implicitly in the ignore mask
whenever it has not explicitly been set by the user (see fanotify_mark_add_to_mask()).
If that flag has been set the ignore mask will never get cleared unless the
user does something like

fanotify_mark(fd, FAN_MARK_REMOVE | FAN_MARK_IGNORED_MASK, FAN_MARK_ONDIR,...)

which presumes that he knows that this flag has been set. 



Btw.: 
every time a user _forgets_ to explicitly set FAN_MARK_ONDIR, it will be set
in the ignored mask and thus events on dirs are skipped. Thus calls like

fanotify_mark(fd, FAN_MARK_ADD, FAN_MARK_ONDIR, ...)  /* get dir events */
fanotify_mark(fd, FAN_MARK_ADD, ...) /* add mark for some kind of event */

will result in dir events being ignored by the second call to fanotify_mark(),
although the user has requested those events in his first call.
This is very likely not what the user expected. Is there a reason why ONDIR is 
set implicitly in the ignore mask?
Otherwise i would suggest to not set it implicitly in mark->ignored_mask,
but to set it in mark->mask if requested by the user. Then we could ignore dir 
events as long as the flag has not been set there. 


2. I just realized that we cant simply call destroy_mark() if the masks are 0. 
There may be one or more concurrent processes calling fsnotify_find_inode_mark() 
(see fanotify_add_inode_mark()) and get the mark we are about to destroy at the 
same time.

I will take a closer look at it, but it seems to be difficult to me to safely 
call destroy_mark() as long as we are not in the context of fanotify_release() (in 
which we dont have to deal with concurrency like that any more). 





 
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux