Commit 6333816a authored by Christoph Hellwig's avatar Christoph Hellwig

hfsplus: protect setflags using i_mutex

Use i_mutex for protecting against concurrent setflags ioctls like in
other filesystems and get rid of the BKL in hfsplus_ioctl.
Signed-off-by: default avatarChristoph Hellwig <hch@tuxera.com>
parent 94744567
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/xattr.h> #include <linux/xattr.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
...@@ -42,10 +41,9 @@ static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags) ...@@ -42,10 +41,9 @@ static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags)
unsigned int flags; unsigned int flags;
int err = 0; int err = 0;
lock_kernel();
err = mnt_want_write(file->f_path.mnt); err = mnt_want_write(file->f_path.mnt);
if (err) if (err)
goto out_unlock_kernel; goto out;
if (!is_owner_or_cap(inode)) { if (!is_owner_or_cap(inode)) {
err = -EACCES; err = -EACCES;
...@@ -57,18 +55,20 @@ static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags) ...@@ -57,18 +55,20 @@ static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags)
goto out_drop_write; goto out_drop_write;
} }
mutex_lock(&inode->i_mutex);
if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) || if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) ||
HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) { HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
if (!capable(CAP_LINUX_IMMUTABLE)) { if (!capable(CAP_LINUX_IMMUTABLE)) {
err = -EPERM; err = -EPERM;
goto out_drop_write; goto out_unlock_inode;
} }
} }
/* don't silently ignore unsupported ext2 flags */ /* don't silently ignore unsupported ext2 flags */
if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) { if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
goto out_drop_write; goto out_unlock_inode;
} }
if (flags & FS_IMMUTABLE_FL) { if (flags & FS_IMMUTABLE_FL) {
inode->i_flags |= S_IMMUTABLE; inode->i_flags |= S_IMMUTABLE;
...@@ -92,10 +92,11 @@ static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags) ...@@ -92,10 +92,11 @@ static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags)
inode->i_ctime = CURRENT_TIME_SEC; inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode); mark_inode_dirty(inode);
out_unlock_inode:
mutex_lock(&inode->i_mutex);
out_drop_write: out_drop_write:
mnt_drop_write(file->f_path.mnt); mnt_drop_write(file->f_path.mnt);
out_unlock_kernel: out:
unlock_kernel();
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment