Skip to content

Commit

Permalink
Merge tag 'locks-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/…
Browse files Browse the repository at this point in the history
…git/jlayton/linux

Pull file locking updates from Jeff Layton:
 "This starts with a couple of fixes for potential deadlocks in the
  fowner/fasync handling.

  The next patch removes the old mandatory locking code from the kernel
  altogether.

  The last patch cleans up rw_verify_area a bit more after the mandatory
  locking removal"

* tag 'locks-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux:
  fs: clean up after mandatory file locking support removal
  fs: remove mandatory file locking support
  fcntl: fix potential deadlock for &fasync_struct.fa_lock
  fcntl: fix potential deadlocks for &fown_struct.lock
  • Loading branch information
torvalds committed Aug 30, 2021
2 parents 451819a + 2949e84 commit 6f01c93
Show file tree
Hide file tree
Showing 20 changed files with 28 additions and 536 deletions.
188 changes: 0 additions & 188 deletions Documentation/filesystems/mandatory-locking.rst

This file was deleted.

13 changes: 0 additions & 13 deletions fs/9p/vfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)

p9_debug(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);

/* No mandatory locks */
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
return -ENOLCK;

if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
filemap_write_and_wait(inode->i_mapping);
invalidate_mapping_pages(&inode->i_data, 0, -1);
Expand Down Expand Up @@ -312,10 +308,6 @@ static int v9fs_file_lock_dotl(struct file *filp, int cmd, struct file_lock *fl)
p9_debug(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %pD\n",
filp, cmd, fl, filp);

/* No mandatory locks */
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
goto out_err;

if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
filemap_write_and_wait(inode->i_mapping);
invalidate_mapping_pages(&inode->i_data, 0, -1);
Expand All @@ -327,7 +319,6 @@ static int v9fs_file_lock_dotl(struct file *filp, int cmd, struct file_lock *fl)
ret = v9fs_file_getlock(filp, fl);
else
ret = -EINVAL;
out_err:
return ret;
}

Expand All @@ -348,10 +339,6 @@ static int v9fs_file_flock_dotl(struct file *filp, int cmd,
p9_debug(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %pD\n",
filp, cmd, fl, filp);

/* No mandatory locks */
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
goto out_err;

if (!(fl->fl_flags & FL_FLOCK))
goto out_err;

Expand Down
10 changes: 0 additions & 10 deletions fs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ config FILE_LOCKING
for filesystems like NFS and for the flock() system
call. Disabling this option saves about 11k.

config MANDATORY_FILE_LOCKING
bool "Enable Mandatory file locking"
depends on FILE_LOCKING
default y
help
This option enables files appropriately marked files on appropriely
mounted filesystems to support mandatory locking.

To the best of my knowledge this is dead code that no one cares about.

source "fs/crypto/Kconfig"

source "fs/verity/Kconfig"
Expand Down
4 changes: 0 additions & 4 deletions fs/afs/flock.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,6 @@ int afs_lock(struct file *file, int cmd, struct file_lock *fl)
fl->fl_type, fl->fl_flags,
(long long) fl->fl_start, (long long) fl->fl_end);

/* AFS doesn't support mandatory locks */
if (__mandatory_lock(&vnode->vfs_inode) && fl->fl_type != F_UNLCK)
return -ENOLCK;

if (IS_GETLK(cmd))
return afs_do_getlk(file, fl);

Expand Down
3 changes: 0 additions & 3 deletions fs/ceph/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)

if (!(fl->fl_flags & FL_POSIX))
return -ENOLCK;
/* No mandatory locks */
if (__mandatory_lock(file->f_mapping->host) && fl->fl_type != F_UNLCK)
return -ENOLCK;

dout("ceph_lock, fl_owner: %p\n", fl->fl_owner);

Expand Down
18 changes: 10 additions & 8 deletions fs/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,16 @@ void f_delown(struct file *filp)
pid_t f_getown(struct file *filp)
{
pid_t pid = 0;
read_lock(&filp->f_owner.lock);

read_lock_irq(&filp->f_owner.lock);
rcu_read_lock();
if (pid_task(filp->f_owner.pid, filp->f_owner.pid_type)) {
pid = pid_vnr(filp->f_owner.pid);
if (filp->f_owner.pid_type == PIDTYPE_PGID)
pid = -pid;
}
rcu_read_unlock();
read_unlock(&filp->f_owner.lock);
read_unlock_irq(&filp->f_owner.lock);
return pid;
}

Expand Down Expand Up @@ -208,7 +209,7 @@ static int f_getown_ex(struct file *filp, unsigned long arg)
struct f_owner_ex owner = {};
int ret = 0;

read_lock(&filp->f_owner.lock);
read_lock_irq(&filp->f_owner.lock);
rcu_read_lock();
if (pid_task(filp->f_owner.pid, filp->f_owner.pid_type))
owner.pid = pid_vnr(filp->f_owner.pid);
Expand All @@ -231,7 +232,7 @@ static int f_getown_ex(struct file *filp, unsigned long arg)
ret = -EINVAL;
break;
}
read_unlock(&filp->f_owner.lock);
read_unlock_irq(&filp->f_owner.lock);

if (!ret) {
ret = copy_to_user(owner_p, &owner, sizeof(owner));
Expand All @@ -249,10 +250,10 @@ static int f_getowner_uids(struct file *filp, unsigned long arg)
uid_t src[2];
int err;

read_lock(&filp->f_owner.lock);
read_lock_irq(&filp->f_owner.lock);
src[0] = from_kuid(user_ns, filp->f_owner.uid);
src[1] = from_kuid(user_ns, filp->f_owner.euid);
read_unlock(&filp->f_owner.lock);
read_unlock_irq(&filp->f_owner.lock);

err = put_user(src[0], &dst[0]);
err |= put_user(src[1], &dst[1]);
Expand Down Expand Up @@ -1003,13 +1004,14 @@ static void kill_fasync_rcu(struct fasync_struct *fa, int sig, int band)
{
while (fa) {
struct fown_struct *fown;
unsigned long flags;

if (fa->magic != FASYNC_MAGIC) {
printk(KERN_ERR "kill_fasync: bad magic number in "
"fasync_struct!\n");
return;
}
read_lock(&fa->fa_lock);
read_lock_irqsave(&fa->fa_lock, flags);
if (fa->fa_file) {
fown = &fa->fa_file->f_owner;
/* Don't send SIGURG to processes which have not set a
Expand All @@ -1018,7 +1020,7 @@ static void kill_fasync_rcu(struct fasync_struct *fa, int sig, int band)
if (!(sig == SIGURG && fown->signum == 0))
send_sigio(fown, fa->fa_fd, band);
}
read_unlock(&fa->fa_lock);
read_unlock_irqrestore(&fa->fa_lock, flags);
fa = rcu_dereference(fa->fa_next);
}
}
Expand Down
3 changes: 0 additions & 3 deletions fs/gfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,9 +1237,6 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)

if (!(fl->fl_flags & FL_POSIX))
return -ENOLCK;
if (__mandatory_lock(&ip->i_inode) && fl->fl_type != F_UNLCK)
return -ENOLCK;

if (cmd == F_CANCELLK) {
/* Hack: */
cmd = F_SETLK;
Expand Down
Loading

0 comments on commit 6f01c93

Please sign in to comment.