mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fix race in inotify_release
@ 2006-05-16 19:39 Amy Griffis
       [not found] ` <1147809280.2752.0.camel@localhost.localdomain>
  0 siblings, 1 reply; 2+ messages in thread
From: Amy Griffis @ 2006-05-16 19:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: John McCutchan, Robert Love

While doing some inotify stress testing, I hit the following race.  In
inotify_release(), it's possible for a watch to be removed from the
lists in between dropping dev->mutex and taking inode->inotify_mutex.
The reference we hold prevents the watch from being freed, but not
from being removed.

Checking the dev's idr mapping will prevent a double list_del of the
same watch.

Signed-off-by: Amy Griffis <amy.griffis@hp.com>

diff --git a/fs/inotify.c b/fs/inotify.c
index 1f50302..7d57253 100644
--- a/fs/inotify.c
+++ b/fs/inotify.c
@@ -848,7 +848,11 @@ static int inotify_release(struct inode 
 		inode = watch->inode;
 		mutex_lock(&inode->inotify_mutex);
 		mutex_lock(&dev->mutex);
-		remove_watch_no_event(watch, dev);
+
+		/* make sure we didn't race with another list removal */
+		if (likely(idr_find(&dev->idr, watch->wd)))
+			remove_watch_no_event(watch, dev);
+
 		mutex_unlock(&dev->mutex);
 		mutex_unlock(&inode->inotify_mutex);
 		put_inotify_watch(watch);



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-05-16 19:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-16 19:39 [PATCH] fix race in inotify_release Amy Griffis
     [not found] ` <1147809280.2752.0.camel@localhost.localdomain>
2006-05-16 19:54   ` John McCutchan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®