[PATCH] fs/locks.c: Fix sys_flock() race
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 31 Mar 2006 10:30:55 +0000 (02:30 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Fri, 31 Mar 2006 20:18:56 +0000 (12:18 -0800)
commit993dfa8776308dcfd311cf77a3bbed4aa11e9868
tree2e90eabd31d3e8db1f2f3c95494109ff29a78237
parent7a2bd3f7efa86e8b56482a8f8948c8b222064a67
[PATCH] fs/locks.c: Fix sys_flock() race

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: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
fs/locks.c