Linux-Fsdevel Archive on lore.kernel.org
 help / color / Atom feed
From: Lino Sanfilippo <LinoSanfilippo@gmx.de>
To: Jan Kara <jack@suse.cz>, Andrew Morton <akpm@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org,
	Miklos Szeredi <mszeredi@redhat.com>,
	Eric Paris <eparis@redhat.com>, Al Viro <viro@ZenIV.linux.org.uk>
Subject: Re: [PATCH 5/6] fanotify: Use notification_lock instead of access_lock
Date: Wed, 14 Sep 2016 19:14:11 +0200
Message-ID: <b7b1eb72-e4ec-f548-c4e8-25390020dae1@gmx.de> (raw)
In-Reply-To: <1473797711-14111-6-git-send-email-jack@suse.cz>

On 13.09.2016 22:15, Jan Kara wrote:
> Fanotify code has an own lock (access_lock) to protect a list of events
> waiting for a response from userspace. However this is somewhat awkward
> as the same list_head in the event is protected by notification_lock
> if it is part of the notification queue and by access_lock if it is part
> of the fanotify private queue which makes it difficult for any reliable
> checks in the generic code. So make fanotify use the same lock -
> notification_lock - for protecting its private event list.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/notify/fanotify/fanotify_user.c | 13 +++++--------
>  include/linux/fsnotify_backend.h   |  1 -
>  2 files changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index e6f3fe9bb2ed..aed06fe2533d 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -147,7 +147,7 @@ static struct fanotify_perm_event_info *dequeue_event(
>  {
>  	struct fanotify_perm_event_info *event, *return_e = NULL;
>  
> -	spin_lock(&group->fanotify_data.access_lock);
> +	spin_lock(&group->notification_lock);
>  	list_for_each_entry(event, &group->fanotify_data.access_list,
>  			    fae.fse.list) {
>  		if (event->fd != fd)
> @@ -157,7 +157,7 @@ static struct fanotify_perm_event_info *dequeue_event(
>  		return_e = event;
>  		break;
>  	}
> -	spin_unlock(&group->fanotify_data.access_lock);
> +	spin_unlock(&group->notification_lock);
>  
>  	pr_debug("%s: found return_re=%p\n", __func__, return_e);
>  
> @@ -309,10 +309,10 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
>  				wake_up(&group->fanotify_data.access_waitq);
>  				break;
>  			}
> -			spin_lock(&group->fanotify_data.access_lock);
> +			spin_lock(&group->notification_lock);
>  			list_add_tail(&kevent->list,
>  				      &group->fanotify_data.access_list);
> -			spin_unlock(&group->fanotify_data.access_lock);
> +			spin_unlock(&group->notification_lock);
>  #endif
>  		}
>  		buf += ret;
> @@ -371,7 +371,7 @@ static int fanotify_release(struct inode *ignored, struct file *file)
>  	 * Process all permission events on access_list and notification queue
>  	 * and simulate reply from userspace.
>  	 */
> -	spin_lock(&group->fanotify_data.access_lock);
> +	spin_lock(&group->notification_lock);
>  	list_for_each_entry_safe(event, next, &group->fanotify_data.access_list,
>  				 fae.fse.list) {
>  		pr_debug("%s: found group=%p event=%p\n", __func__, group,
> @@ -380,14 +380,12 @@ static int fanotify_release(struct inode *ignored, struct file *file)
>  		list_del_init(&event->fae.fse.list);
>  		event->response = FAN_ALLOW;
>  	}
> -	spin_unlock(&group->fanotify_data.access_lock);
>  
>  	/*
>  	 * Destroy all non-permission events. For permission events just
>  	 * dequeue them and set the response. They will be freed once the
>  	 * response is consumed and fanotify_get_response() returns.
>  	 */
> -	spin_lock(&group->notification_lock);
>  	while (!fsnotify_notify_queue_is_empty(group)) {
>  		fsn_event = fsnotify_remove_first_event(group);
>  		if (!(fsn_event->mask & FAN_ALL_PERM_EVENTS)) {
> @@ -767,7 +765,6 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
>  		event_f_flags |= O_LARGEFILE;
>  	group->fanotify_data.f_flags = event_f_flags;
>  #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
> -	spin_lock_init(&group->fanotify_data.access_lock);
>  	init_waitqueue_head(&group->fanotify_data.access_waitq);
>  	INIT_LIST_HEAD(&group->fanotify_data.access_list);
>  #endif
> diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
> index 0713e873b1c9..79467b239fcf 100644
> --- a/include/linux/fsnotify_backend.h
> +++ b/include/linux/fsnotify_backend.h
> @@ -177,7 +177,6 @@ struct fsnotify_group {
>  		struct fanotify_group_private_data {
>  #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
>  			/* allows a group to block waiting for a userspace response */
> -			spinlock_t access_lock;
>  			struct list_head access_list;
>  			wait_queue_head_t access_waitq;
>  #endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */
> 

Reviewed-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>

  reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13 20:15 [PATCH 0/6 v2] fsnotify: Fix list corruption for permission events Jan Kara
2016-09-13 20:15 ` [PATCH 1/6] fsnotify: Add a way to stop queueing events on group shutdown Jan Kara
2016-09-13 20:15 ` [PATCH 2/6] fanotify: Fix list corruption in fanotify_get_response() Jan Kara
2016-09-13 20:15 ` [PATCH 3/6] fsnotify: Drop notification_mutex before destroying event Jan Kara
2016-09-14 17:11   ` Lino Sanfilippo
2016-09-13 20:15 ` [PATCH 4/6] fsnotify: Convert notification_mutex to a spinlock Jan Kara
2016-09-14 17:13   ` Lino Sanfilippo
2016-09-13 20:15 ` [PATCH 5/6] fanotify: Use notification_lock instead of access_lock Jan Kara
2016-09-14 17:14   ` Lino Sanfilippo [this message]
2016-09-13 20:15 ` [PATCH 6/6] fanotify: Fix possible false warning when freeing events Jan Kara
2016-09-14 17:14   ` Lino Sanfilippo

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=b7b1eb72-e4ec-f548-c4e8-25390020dae1@gmx.de \
    --to=linosanfilippo@gmx.de \
    --cc=akpm@linux-foundation.org \
    --cc=eparis@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mszeredi@redhat.com \
    --cc=viro@ZenIV.linux.org.uk \
    /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

Linux-Fsdevel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-fsdevel/0 linux-fsdevel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fsdevel linux-fsdevel/ https://lore.kernel.org/linux-fsdevel \
		linux-fsdevel@vger.kernel.org
	public-inbox-index linux-fsdevel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-fsdevel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git