Commit 75fe2b26 authored by Eric Paris's avatar Eric Paris
Browse files

inotify: do not leak inode marks in inotify_add_watch

inotify_add_watch had a couple of problems.  The biggest being that if
inotify_add_watch was called on the same inode twice (to update or change the
event mask) a refence was taken on the original inode mark by
fsnotify_find_mark_entry but was not being dropped at the end of the
inotify_add_watch call.  Thus if inotify_rm_watch was called although the mark
was removed from the inode, the refcnt wouldn't hit zero and we would leak
Reported-by: default avatarCatalin Marinas <>
Signed-off-by: default avatarEric Paris <>
parent 5549f7cd
......@@ -463,9 +463,6 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod
goto out_err;
/* if entry is added to the idr we keep the reference obtained
* through fsnotify_mark_add. remember to drop this reference
* when entry is removed from idr */
ret = idr_get_new_above(&group->inotify_data.idr, entry,
......@@ -476,8 +473,13 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod
goto out_err;
/* we put the mark on the idr, take a reference */
ret = ientry->wd;
old_mask = entry->mask;
......@@ -508,7 +510,11 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod
return ientry->wd;
/* this either matches fsnotify_find_mark_entry, or init_mark_entry
* depending on which path we took... */
return ret;
/* see this isn't supposed to happen, just kill the watch */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment