Skip to contentSkip to conversation

fix race in inotify_release

PATCH In review Amy Griffis 2 participants 2 messages May 16, 2006 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix race in inotify_release

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.

fs/inotify.c +5 -1
index 1f50302..7d57253 100644
@@ -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);
#1 lore raw
Quoted 8 lines · Amy Griffis

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.

Looks good. Thanks for the patch and stress testing inotify!

Signature · 1 line
John McCutchan <[email protected]>