From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Hellwig Subject: [PATCH 3/6] hfsplus: protect setflags using i_mutex Date: Sun, 26 Sep 2010 23:20:02 +0200 Message-ID: <20100926212002.GC6394@lst.de> References: <20100926211920.GA6394@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel@vger.kernel.org To: viro@zeniv.linux.org.uk, zippel@linux-m68k.org Return-path: Received: from verein.lst.de ([213.95.11.210]:46953 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757616Ab0IZVUI (ORCPT ); Sun, 26 Sep 2010 17:20:08 -0400 Content-Disposition: inline In-Reply-To: <20100926211920.GA6394@lst.de> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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: Christoph Hellwig Index: linux-2.6/fs/hfsplus/ioctl.c =================================================================== --- linux-2.6.orig/fs/hfsplus/ioctl.c 2010-09-26 02:01:29.927790059 +0900 +++ linux-2.6/fs/hfsplus/ioctl.c 2010-09-26 02:03:03.013790060 +0900 @@ -17,7 +17,6 @@ #include #include #include -#include #include #include "hfsplus_fs.h" @@ -42,10 +41,9 @@ static int hfsplus_ioctl_setflags(struct unsigned int flags; int err = 0; - lock_kernel(); err = mnt_want_write(file->f_path.mnt); if (err) - goto out_unlock_kernel; + goto out; if (!is_owner_or_cap(inode)) { err = -EACCES; @@ -57,18 +55,20 @@ static int hfsplus_ioctl_setflags(struct goto out_drop_write; } + mutex_lock(&inode->i_mutex); + if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) || HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) { if (!capable(CAP_LINUX_IMMUTABLE)) { err = -EPERM; - goto out_drop_write; + goto out_unlock_inode; } } /* don't silently ignore unsupported ext2 flags */ if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) { err = -EOPNOTSUPP; - goto out_drop_write; + goto out_unlock_inode; } if (flags & FS_IMMUTABLE_FL) { inode->i_flags |= S_IMMUTABLE; @@ -92,10 +92,11 @@ static int hfsplus_ioctl_setflags(struct inode->i_ctime = CURRENT_TIME_SEC; mark_inode_dirty(inode); +out_unlock_inode: + mutex_lock(&inode->i_mutex); out_drop_write: mnt_drop_write(file->f_path.mnt); -out_unlock_kernel: - unlock_kernel(); +out: return err; }