[lkml]   [2010]   [May]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Patch in this message
    Subject[24/39] inotify: race use after free/double free in inotify inode marks

    2.6.33-stable review patch. If anyone has any objections, please let us know.

    From: Eric Paris <>

    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
    ------------ -----------
    allocate a mark (refcnt == 1)
    add it to the idr
    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

    Signed-off-by: Eric Paris <>
    Signed-off-by: Greg Kroah-Hartman <>

    fs/notify/inotify/inotify_user.c | 9 ++++++---
    1 file changed, 6 insertions(+), 3 deletions(-)

    --- a/fs/notify/inotify/inotify_user.c
    +++ b/fs/notify/inotify/inotify_user.c
    @@ -550,21 +550,24 @@ retry:
    if (unlikely(!idr_pre_get(&group->inotify_data.idr, GFP_KERNEL)))
    goto out_err;

    + /* we are putting the mark on the idr, take a reference */
    + fsnotify_get_mark(&tmp_ientry->fsn_entry);
    ret = idr_get_new_above(&group->inotify_data.idr, &tmp_ientry->fsn_entry,
    if (ret) {
    + /* we didn't get on the idr, drop the idr reference */
    + fsnotify_put_mark(&tmp_ientry->fsn_entry);
    /* idr was out of memory allocate and try again */
    if (ret == -EAGAIN)
    goto retry;
    goto out_err;

    - /* we put the mark on the idr, take a reference */
    - fsnotify_get_mark(&tmp_ientry->fsn_entry);
    /* we are on the idr, now get on the inode */
    ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode);
    if (ret) {

     \ /
      Last update: 2010-05-25 01:31    [W:0.031 / U:6.344 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site