Skip to content

Commit

Permalink
leases: fix write-open/read-lease race
Browse files Browse the repository at this point in the history
In setlease, we use i_writecount to decide whether we can give out a
read lease.

In open, we break leases before incrementing i_writecount.

There is therefore a window between the break lease and the i_writecount
increment when setlease could add a new read lease.

This would leave us with a simultaneous write open and read lease, which
shouldn't happen.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
J. Bruce Fields authored and root committed Oct 28, 2011
1 parent 79835a7 commit f3c7691
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 1 addition & 4 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,10 +2035,7 @@ static int may_open(struct path *path, int acc_mode, int flag)
if (flag & O_NOATIME && !inode_owner_or_capable(inode))
return -EPERM;

/*
* Ensure there are no outstanding leases on the file.
*/
return break_lease(inode, flag);
return 0;
}

static int handle_truncate(struct file *filp)
Expand Down
4 changes: 4 additions & 0 deletions fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
if (error)
goto cleanup_all;

error = break_lease(inode, f->f_flags);
if (error)
goto cleanup_all;

if (!open && f->f_op)
open = f->f_op->open;
if (open) {
Expand Down

0 comments on commit f3c7691

Please sign in to comment.