diff options
author | Jan Kara <jack@suse.cz> | 2016-10-07 19:56:58 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-07 21:46:26 -0400 |
commit | 0b1b86527df4b1f398266c23e926dd788925bb69 (patch) | |
tree | 04d4ba30ad9e2e17a9e68b344964fe06bcfcfd88 | |
parent | 073f65522aeb23e46fc8a809d69513132d3acc81 (diff) |
fanotify: fix possible false warning when freeing events
When freeing permission events by fsnotify_destroy_event(), the warning
WARN_ON(!list_empty(&event->list)); may falsely hit.
This is because although fanotify_get_response() saw event->response
set, there is nothing to make sure the current CPU also sees the removal
of the event from the list. Add proper locking around the WARN_ON() to
avoid the false warning.
Link: http://lkml.kernel.org/r/1473797711-14111-7-git-send-email-jack@suse.cz
Reported-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: Eric Paris <eparis@redhat.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/notify/notification.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/fs/notify/notification.c b/fs/notify/notification.c index 8a7a8cd041e8..1a8010e7a2a0 100644 --- a/fs/notify/notification.c +++ b/fs/notify/notification.c | |||
@@ -74,8 +74,17 @@ void fsnotify_destroy_event(struct fsnotify_group *group, | |||
74 | /* Overflow events are per-group and we don't want to free them */ | 74 | /* Overflow events are per-group and we don't want to free them */ |
75 | if (!event || event->mask == FS_Q_OVERFLOW) | 75 | if (!event || event->mask == FS_Q_OVERFLOW) |
76 | return; | 76 | return; |
77 | /* If the event is still queued, we have a problem... */ | 77 | /* |
78 | WARN_ON(!list_empty(&event->list)); | 78 | * If the event is still queued, we have a problem... Do an unreliable |
79 | * lockless check first to avoid locking in the common case. The | ||
80 | * locking may be necessary for permission events which got removed | ||
81 | * from the list by a different CPU than the one freeing the event. | ||
82 | */ | ||
83 | if (!list_empty(&event->list)) { | ||
84 | spin_lock(&group->notification_lock); | ||
85 | WARN_ON(!list_empty(&event->list)); | ||
86 | spin_unlock(&group->notification_lock); | ||
87 | } | ||
79 | group->ops->free_event(event); | 88 | group->ops->free_event(event); |
80 | } | 89 | } |
81 | 90 | ||