Re: [PATCH v3 09/13] filelock: lift the ban on directory leases in generic_setlease

Jan Kara <[email protected]>
Newsgroups org.kernel.vger.ecryptfs,dev.linux.lists.netfs,org.kernel.vger.linux-cifs,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-nfs,org.kernel.vger.linux-unionfs,org.kernel.vger.linux-xfs,org.kernel.vger.netdev
Message-ID <g7r2bffekbosexqbatj5mb7ljc5rn5rw3dwfehipsxdb6hewyp@heriwuhgh3zo>
On Tue 21-10-25 11:25:44, Jeff Layton wrote:
> With the addition of the try_break_lease calls in directory changing
> operations, allow generic_setlease to hand them out. Write leases on
> directories are never allowed however, so continue to reject them.
> 
> For now, there is no API for requesting delegations from userland, so
> ensure that userland is prevented from acquiring a lease on a directory.
> 
> Reviewed-by: NeilBrown <[email protected]>
> Signed-off-by: Jeff Layton <[email protected]>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <[email protected]>

								Honza

> ---
>  fs/locks.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/locks.c b/fs/locks.c
> index 0b16921fb52e602ea2e0c3de39d9d772af98ba7d..b47552106769ec5a189babfe12518e34aa59c759 100644
> --- a/fs/locks.c
> +++ b/fs/locks.c
> @@ -1929,14 +1929,19 @@ static int generic_delete_lease(struct file *filp, void *owner)
>  int generic_setlease(struct file *filp, int arg, struct file_lease **flp,
>  			void **priv)
>  {
> -	if (!S_ISREG(file_inode(filp)->i_mode))
> +	struct inode *inode = file_inode(filp);
> +
> +	if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
>  		return -EINVAL;
>  
>  	switch (arg) {
>  	case F_UNLCK:
>  		return generic_delete_lease(filp, *priv);
> -	case F_RDLCK:
>  	case F_WRLCK:
> +		if (S_ISDIR(inode->i_mode))
> +			return -EINVAL;
> +		fallthrough;
> +	case F_RDLCK:
>  		if (!(*flp)->fl_lmops->lm_break) {
>  			WARN_ON_ONCE(1);
>  			return -ENOLCK;
> @@ -2065,6 +2070,9 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, int arg)
>   */
>  int fcntl_setlease(unsigned int fd, struct file *filp, int arg)
>  {
> +	if (S_ISDIR(file_inode(filp)->i_mode))
> +		return -EINVAL;
> +
>  	if (arg == F_UNLCK)
>  		return vfs_setlease(filp, F_UNLCK, NULL, (void **)&filp);
>  	return do_fcntl_add_lease(fd, filp, arg);
> 
> -- 
> 2.51.0
> 
-- 
Jan Kara <[email protected]>
SUSE Labs, CR
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.