aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inotify.c
diff options
context:
space:
mode:
authorDmitri Monakhov <dmonakhov@openvz.org>2008-12-09 16:14:26 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-12-10 11:01:53 -0500
commit6ee5a399d6a92a52646836a6e10faf255c16393e (patch)
tree52966233a5093c0d7cdeb244be9b6c3c8e1760c4 /fs/inotify.c
parentaa6f14796630c8b03c11e782484aec2aee05e671 (diff)
inotify: fix IN_ONESHOT unmount event watcher
On umount two event will be dispatched to watcher: 1: inotify_dev_queue_event(.., IN_UNMOUNT,..) 2: remove_watch(watch, dev) ->inotify_dev_queue_event(.., IN_IGNORED, ..) But if watcher has IN_ONESHOT bit set then the watcher will be released inside first event. Which result in accessing invalid object later. IMHO it is not pure regression. This bug wasn't triggered while initial inotify interface testing phase because of another bug in IN_ONESHOT handling logic :) commit ac74c00e499ed276a965e5b5600667d5dc04a84a Author: Ulisses Furquim <ulissesf@gmail.com> Date: Fri Feb 8 04:18:16 2008 -0800 inotify: fix check for one-shot watches before destroying them As the IN_ONESHOT bit is never set when an event is sent we must check it in the watch's mask and not in the event's mask. TESTCASE: mkdir mnt mount -ttmpfs none mnt mkdir mnt/d ./inotify mnt/d& umount mnt ## << lockup or crash here TESTSOURCE: /* gcc -oinotify inotify.c */ #include <stdio.h> #include <stdlib.h> #include <sys/inotify.h> int main(int argc, char **argv) { char buf[1024]; struct inotify_event *ie; char *p; int i; ssize_t l; p = argv[1]; i = inotify_init(); inotify_add_watch(i, p, ~0); l = read(i, buf, sizeof(buf)); printf("read %d bytes\n", l); ie = (struct inotify_event *) buf; printf("event mask: %d\n", ie->mask); return 0; } Signed-off-by: Dmitri Monakhov <dmonakhov@openvz.org> Cc: John McCutchan <ttb@tentacle.dhs.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Robert Love <rlove@google.com> Cc: Ulisses Furquim <ulissesf@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/inotify.c')
-rw-r--r--fs/inotify.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/inotify.c b/fs/inotify.c
index 7bbed1b89825..dae3f28f30d4 100644
--- a/fs/inotify.c
+++ b/fs/inotify.c
@@ -428,11 +428,13 @@ void inotify_unmount_inodes(struct list_head *list)
428 watches = &inode->inotify_watches; 428 watches = &inode->inotify_watches;
429 list_for_each_entry_safe(watch, next_w, watches, i_list) { 429 list_for_each_entry_safe(watch, next_w, watches, i_list) {
430 struct inotify_handle *ih= watch->ih; 430 struct inotify_handle *ih= watch->ih;
431 get_inotify_watch(watch);
431 mutex_lock(&ih->mutex); 432 mutex_lock(&ih->mutex);
432 ih->in_ops->handle_event(watch, watch->wd, IN_UNMOUNT, 0, 433 ih->in_ops->handle_event(watch, watch->wd, IN_UNMOUNT, 0,
433 NULL, NULL); 434 NULL, NULL);
434 inotify_remove_watch_locked(ih, watch); 435 inotify_remove_watch_locked(ih, watch);
435 mutex_unlock(&ih->mutex); 436 mutex_unlock(&ih->mutex);
437 put_inotify_watch(watch);
436 } 438 }
437 mutex_unlock(&inode->inotify_mutex); 439 mutex_unlock(&inode->inotify_mutex);
438 iput(inode); 440 iput(inode);