Re: [PATCH 2/6] leases: fix write-open/read-lease race

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 21, 2011 at 10:58:13AM -0400, J. Bruce Fields wrote:
> 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.

And maybe someone that knows the open code better than me could confirm
whether it's reasonable to move the break_lease() call to __dentry_open
like this....

--b.

> 
> Signed-off-by: J. Bruce Fields <bfields@xxxxxxxxxx>
> ---
>  fs/namei.c |    5 +----
>  fs/open.c  |    4 ++++
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 2826db3..6ff59e5 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -2044,10 +2044,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)
> diff --git a/fs/open.c b/fs/open.c
> index f711921..22c41b5 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -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) {
> -- 
> 1.7.4.1
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux