inotify: race use after free/double free in inotify inode marks
authorEric Paris <eparis@redhat.com>
Tue, 11 May 2010 21:17:40 +0000 (17:17 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 26 May 2010 21:29:17 +0000 (14:29 -0700)
commitc606e701ef469582a991aabd3a6f7816a9a9d351
treee5ebb94254bb6458d63d27a544d39cb65524d191
parentbbd7e6ac76997aadf0b827aaca61ba767eb5dd78
inotify: race use after free/double free in inotify inode marks

commit e08733446e72b983fed850fc5d8bd21b386feb29 upstream.

There is a race in the inotify add/rm watch code.  A task can find and
remove a mark which doesn't have all of it's references.  This can
result in a use after free/double free situation.

Task A Task B
------------ -----------
inotify_new_watch()
 allocate a mark (refcnt == 1)
 add it to the idr
inotify_rm_watch()
 inotify_remove_from_idr()
  fsnotify_put_mark()
      refcnt hits 0, free
 take reference because we are on idr
 [at this point it is a use after free]
 [time goes on]
 refcnt may hit 0 again, double free

The fix is to take the reference BEFORE the object can be found in the
idr.

Signed-off-by: Eric Paris <eparis@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/notify/inotify/inotify_user.c