Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Jeff Layton and committed by
Christian Brauner
d0eab9fc 92bf5357

+10 -2
+10 -2
fs/locks.c
··· 1935 1935 int generic_setlease(struct file *filp, int arg, struct file_lease **flp, 1936 1936 void **priv) 1937 1937 { 1938 - if (!S_ISREG(file_inode(filp)->i_mode)) 1938 + struct inode *inode = file_inode(filp); 1939 + 1940 + if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) 1939 1941 return -EINVAL; 1940 1942 1941 1943 switch (arg) { 1942 1944 case F_UNLCK: 1943 1945 return generic_delete_lease(filp, *priv); 1944 - case F_RDLCK: 1945 1946 case F_WRLCK: 1947 + if (S_ISDIR(inode->i_mode)) 1948 + return -EINVAL; 1949 + fallthrough; 1950 + case F_RDLCK: 1946 1951 if (!(*flp)->fl_lmops->lm_break) { 1947 1952 WARN_ON_ONCE(1); 1948 1953 return -ENOLCK; ··· 2076 2071 */ 2077 2072 int fcntl_setlease(unsigned int fd, struct file *filp, int arg) 2078 2073 { 2074 + if (S_ISDIR(file_inode(filp)->i_mode)) 2075 + return -EINVAL; 2076 + 2079 2077 if (arg == F_UNLCK) 2080 2078 return vfs_setlease(filp, F_UNLCK, NULL, (void **)&filp); 2081 2079 return do_fcntl_add_lease(fd, filp, arg);