mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
filelock: lift the ban on directory leases in generic_setlease
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: Jan Kara <jack@suse.cz> Reviewed-by: NeilBrown <neil@brown.name> Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://patch.msgid.link/20251111-dir-deleg-ro-v6-13-52f3feebb2f2@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
committed by
Christian Brauner
parent
92bf53577f
commit
d0eab9fc10
12
fs/locks.c
12
fs/locks.c
@@ -1935,14 +1935,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;
|
||||
@@ -2071,6 +2076,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);
|
||||
|
||||
Reference in New Issue
Block a user