aboutsummaryrefslogtreecommitdiff
path: root/lib/memory-notifier-error-inject.c
diff options
context:
space:
mode:
authorJeff Layton <[email protected]>2014-02-03 12:13:06 -0500
committerJeff Layton <[email protected]>2014-03-31 08:24:42 -0400
commit24cbe7845ea50b636ab2218b9d648270ff55f148 (patch)
tree89769bf1271ff804c830d0ba7898294a5762b7a6 /lib/memory-notifier-error-inject.c
parent18156e7e66e5147d2483382a1e3817d2401ca1a8 (diff)
locks: close potential race between setlease and open
As Al Viro points out, there is an unlikely, but possible race between opening a file and setting a lease on it. generic_add_lease is done with the i_lock held, but the inode->i_flock check in break_lease is lockless. It's possible for another task doing an open to do the entire pathwalk and call break_lease between the point where generic_add_lease checks for a conflicting open and adds the lease to the list. If this occurs, we can end up with a lease set on the file with a conflicting open. To guard against that, check again for a conflicting open after adding the lease to the i_flock list. If the above race occurs, then we can simply unwind the lease setting and return -EAGAIN. Because we take dentry references and acquire write access on the file before calling break_lease, we know that if the i_flock list is empty when the open caller goes to check it then the necessary refcounts have already been incremented. Thus the additional check for a conflicting open will see that there is one and the setlease call will fail. Cc: Bruce Fields <[email protected]> Cc: David Howells <[email protected]> Cc: "Paul E. McKenney" <[email protected]> Reported-by: Al Viro <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
Diffstat (limited to 'lib/memory-notifier-error-inject.c')
0 files changed, 0 insertions, 0 deletions