xfs
[Top] [All Lists]

[PATCH 5/5] xfs: Correctly lock inode when removing suid and security ma

To: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Subject: [PATCH 5/5] xfs: Correctly lock inode when removing suid and security marks
From: Jan Kara <jack@xxxxxxx>
Date: Thu, 4 Dec 2014 14:27:39 +0100
Cc: linux-fsdevel@xxxxxxxxxxxxxxx, xfs@xxxxxxxxxxx, linux-security-module@xxxxxxxxxxxxxxx, Jan Kara <jack@xxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1417699659-14284-1-git-send-email-jack@xxxxxxx>
References: <1417699659-14284-1-git-send-email-jack@xxxxxxx>
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 <jack@xxxxxxx>
---
 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 5c9e8296ebb3..c6622aa1f8af 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -521,6 +521,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
@@ -557,7 +564,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;
 }
 
 /*
-- 
1.8.1.4

<Prev in Thread] Current Thread [Next in Thread>