Skip to content

Commit

Permalink
inotify: do not leak inode marks in inotify_add_watch
Browse files Browse the repository at this point in the history
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
memory.

Reported-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
  • Loading branch information
Eric Paris committed Jul 21, 2009
1 parent 5549f7c commit 75fe2b2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions fs/notify/inotify/inotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,6 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod
goto out_err;

spin_lock(&group->inotify_data.idr_lock);
/* 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,
++group->inotify_data.last_wd,
&ientry->wd);
Expand All @@ -476,8 +473,13 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod
goto out_err;
}
atomic_inc(&group->inotify_data.user->inotify_watches);

/* we put the mark on the idr, take a reference */
fsnotify_get_mark(entry);
}

ret = ientry->wd;

spin_lock(&entry->lock);

old_mask = entry->mask;
Expand Down Expand Up @@ -508,7 +510,11 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod
fsnotify_recalc_group_mask(group);
}

return ientry->wd;
/* this either matches fsnotify_find_mark_entry, or init_mark_entry
* depending on which path we took... */
fsnotify_put_mark(entry);

return ret;

out_err:
/* see this isn't supposed to happen, just kill the watch */
Expand Down

0 comments on commit 75fe2b2

Please sign in to comment.