• Lino Sanfilippo's avatar
    inotify: fix race when adding a new watch · e1e5a9f8
    Lino Sanfilippo authored
    In inotify_new_watch() the number of watches for a group is compared
    against the max number of allowed watches and increased afterwards.  The
    check and incrementation is not done atomically, so it is possible for
    multiple concurrent threads to pass the check and increment the number
    of marks above the allowed max.
    
    This patch uses an inotify groups mark_lock to ensure that both check
    and incrementation are done atomic.  Furthermore we dont have to worry
    about the race that allows a concurrent thread to add a watch just after
    inotify_update_existing_watch() returned with -ENOENT anymore, since
    this is also synchronized by the groups mark mutex now.
    Signed-off-by: default avatarLino Sanfilippo <LinoSanfilippo@gmx.de>
    Cc: Eric Paris <eparis@redhat.com>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    e1e5a9f8
inotify_user.c 21.4 KB