From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kara Subject: [PATCH 5/5] xfs: Correctly lock inode when removing suid and security marks Date: Tue, 3 Mar 2015 11:38:39 +0100 Message-ID: <1425379119-3773-6-git-send-email-jack@suse.cz> References: <1425379119-3773-1-git-send-email-jack@suse.cz> Cc: linux-fsdevel@vger.kernel.org, xfs@oss.sgi.com, Jan Kara To: Al Viro Return-path: Received: from cantor2.suse.de ([195.135.220.15]:58884 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756116AbbCCKiv (ORCPT ); Tue, 3 Mar 2015 05:38:51 -0500 In-Reply-To: <1425379119-3773-1-git-send-email-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Currently XFS calls file_remove_privs() without holding i_mutex. This is wrong because that function can end up messing with file permissions and security xattrs for which we need i_mutex held. Fix the problem by grabbing iolock exclusively when we will need to change anything in permissions / xattrs. Signed-off-by: Jan Kara --- fs/xfs/xfs_file.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index fa81a43702ee..3d601e92bd44 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -563,6 +563,13 @@ restart: if (error) return error; + /* For changing security info in file_remove_privs() we need i_mutex */ + if (*iolock == XFS_IOLOCK_SHARED && !IS_NOSEC(inode)) { + xfs_rw_iunlock(ip, *iolock); + *iolock = XFS_IOLOCK_EXCL; + xfs_rw_ilock(ip, *iolock); + goto restart; + } /* * If the offset is beyond the size of the file, we need to zero any * blocks that fall between the existing EOF and the start of this @@ -601,7 +608,9 @@ restart: * setgid bits if the process is not being run by root. This keeps * people from modifying setuid and setgid binaries. */ - return file_remove_privs(file); + if (!IS_NOSEC(inode)) + return file_remove_privs(file); + return 0; } /* -- 2.1.4