Commit e0d4517c authored by Jan Kara's avatar Jan Kara Committed by Greg Kroah-Hartman

fsnotify: add a way to stop queueing events on group shutdown

commit 12703dbf upstream.

Implement a function that can be called when a group is being shutdown
to stop queueing new events to the group.  Fanotify will use this.

Fixes: 5838d444 ("fanotify: fix double free of pending permission events")
Link: http://lkml.kernel.org/r/1473797711-14111-2-git-send-email-jack@suse.czSigned-off-by: default avatarJan Kara <jack@suse.cz>
Reviewed-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 364020ae
...@@ -39,6 +39,17 @@ static void fsnotify_final_destroy_group(struct fsnotify_group *group) ...@@ -39,6 +39,17 @@ static void fsnotify_final_destroy_group(struct fsnotify_group *group)
kfree(group); kfree(group);
} }
/*
* Stop queueing new events for this group. Once this function returns
* fsnotify_add_event() will not add any new events to the group's queue.
*/
void fsnotify_group_stop_queueing(struct fsnotify_group *group)
{
mutex_lock(&group->notification_mutex);
group->shutdown = true;
mutex_unlock(&group->notification_mutex);
}
/* /*
* Trying to get rid of a group. Remove all marks, flush all events and release * Trying to get rid of a group. Remove all marks, flush all events and release
* the group reference. * the group reference.
...@@ -47,6 +58,14 @@ static void fsnotify_final_destroy_group(struct fsnotify_group *group) ...@@ -47,6 +58,14 @@ static void fsnotify_final_destroy_group(struct fsnotify_group *group)
*/ */
void fsnotify_destroy_group(struct fsnotify_group *group) void fsnotify_destroy_group(struct fsnotify_group *group)
{ {
/*
* Stop queueing new events. The code below is careful enough to not
* require this but fanotify needs to stop queuing events even before
* fsnotify_destroy_group() is called and this makes the other callers
* of fsnotify_destroy_group() to see the same behavior.
*/
fsnotify_group_stop_queueing(group);
/* clear all inode marks for this group, attach them to destroy_list */ /* clear all inode marks for this group, attach them to destroy_list */
fsnotify_detach_group_marks(group); fsnotify_detach_group_marks(group);
......
...@@ -82,7 +82,8 @@ void fsnotify_destroy_event(struct fsnotify_group *group, ...@@ -82,7 +82,8 @@ void fsnotify_destroy_event(struct fsnotify_group *group,
* Add an event to the group notification queue. The group can later pull this * Add an event to the group notification queue. The group can later pull this
* event off the queue to deal with. The function returns 0 if the event was * event off the queue to deal with. The function returns 0 if the event was
* added to the queue, 1 if the event was merged with some other queued event, * added to the queue, 1 if the event was merged with some other queued event,
* 2 if the queue of events has overflown. * 2 if the event was not queued - either the queue of events has overflown
* or the group is shutting down.
*/ */
int fsnotify_add_event(struct fsnotify_group *group, int fsnotify_add_event(struct fsnotify_group *group,
struct fsnotify_event *event, struct fsnotify_event *event,
...@@ -96,6 +97,11 @@ int fsnotify_add_event(struct fsnotify_group *group, ...@@ -96,6 +97,11 @@ int fsnotify_add_event(struct fsnotify_group *group,
mutex_lock(&group->notification_mutex); mutex_lock(&group->notification_mutex);
if (group->shutdown) {
mutex_unlock(&group->notification_mutex);
return 2;
}
if (group->q_len >= group->max_events) { if (group->q_len >= group->max_events) {
ret = 2; ret = 2;
/* Queue overflow event only if it isn't already queued */ /* Queue overflow event only if it isn't already queued */
......
...@@ -148,6 +148,7 @@ struct fsnotify_group { ...@@ -148,6 +148,7 @@ struct fsnotify_group {
#define FS_PRIO_1 1 /* fanotify content based access control */ #define FS_PRIO_1 1 /* fanotify content based access control */
#define FS_PRIO_2 2 /* fanotify pre-content access */ #define FS_PRIO_2 2 /* fanotify pre-content access */
unsigned int priority; unsigned int priority;
bool shutdown; /* group is being shut down, don't queue more events */
/* stores all fastpath marks assoc with this group so they can be cleaned on unregister */ /* stores all fastpath marks assoc with this group so they can be cleaned on unregister */
struct mutex mark_mutex; /* protect marks_list */ struct mutex mark_mutex; /* protect marks_list */
...@@ -303,6 +304,8 @@ extern struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *op ...@@ -303,6 +304,8 @@ extern struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *op
extern void fsnotify_get_group(struct fsnotify_group *group); extern void fsnotify_get_group(struct fsnotify_group *group);
/* drop reference on a group from fsnotify_alloc_group */ /* drop reference on a group from fsnotify_alloc_group */
extern void fsnotify_put_group(struct fsnotify_group *group); extern void fsnotify_put_group(struct fsnotify_group *group);
/* group destruction begins, stop queuing new events */
extern void fsnotify_group_stop_queueing(struct fsnotify_group *group);
/* destroy group */ /* destroy group */
extern void fsnotify_destroy_group(struct fsnotify_group *group); extern void fsnotify_destroy_group(struct fsnotify_group *group);
/* fasync handler function */ /* fasync handler function */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment