fanotify: fix double free of pending permission events
[linux-2.6-microblaze.git] / fs / notify / notification.c
index 1d39422..a95d8e0 100644 (file)
@@ -73,7 +73,8 @@ void fsnotify_destroy_event(struct fsnotify_group *group,
        /* Overflow events are per-group and we don't want to free them */
        if (!event || event->mask == FS_Q_OVERFLOW)
                return;
-
+       /* If the event is still queued, we have a problem... */
+       WARN_ON(!list_empty(&event->list));
        group->ops->free_event(event);
 }
 
@@ -124,6 +125,21 @@ queue:
        return ret;
 }
 
+/*
+ * Remove @event from group's notification queue. It is the responsibility of
+ * the caller to destroy the event.
+ */
+void fsnotify_remove_event(struct fsnotify_group *group,
+                          struct fsnotify_event *event)
+{
+       mutex_lock(&group->notification_mutex);
+       if (!list_empty(&event->list)) {
+               list_del_init(&event->list);
+               group->q_len--;
+       }
+       mutex_unlock(&group->notification_mutex);
+}
+
 /*
  * Remove and return the first event from the notification list.  It is the
  * responsibility of the caller to destroy the obtained event