• Trond Myklebust's avatar
    [PATCH] fs/locks.c: Fix sys_flock() race · 993dfa87
    Trond Myklebust authored
    sys_flock() currently has a race which can result in a double free in the
    multi-thread case.
    
    Thread 1			Thread 2
    
    sys_flock(file, LOCK_EX)
    				sys_flock(file, LOCK_UN)
    
    If Thread 2 removes the lock from inode->i_lock before Thread 1 tests for
    list_empty(&lock->fl_link) at the end of sys_flock, then both threads will
    end up calling locks_free_lock for the same lock.
    
    Fix is to make flock_lock_file() do the same as posix_lock_file(), namely
    to make a copy of the request, so that the caller can always free the lock.
    
    This also has the side-effect of fixing up a reference problem in the
    lockd handling of flock.
    Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    993dfa87
locks.c 55.6 KB