xfs: only clear the suid bit once in xfs_write
authorChristoph Hellwig <hch@infradead.org>
Wed, 3 Feb 2010 19:43:31 +0000 (19:43 +0000)
committerAlex Elder <aelder@sgi.com>
Fri, 12 Feb 2010 19:43:57 +0000 (13:43 -0600)
file_remove_suid already calls into ->setattr to clear the suid and
sgid bits if needed, no need to start a second transaction to do it
ourselves.

Note that xfs_write_clear_setuid issues a sync transaction while the
path through ->setattr doesn't, but that is consistant with the
other filesystems.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Alex Elder <aelder@sgi.com>
Signed-off-by: Alex Elder <aelder@sgi.com>
fs/xfs/linux-2.6/xfs_lrw.c
fs/xfs/xfs_rw.c
fs/xfs/xfs_rw.h

index c80fa00d2ad795346c9ba0ddac6c667d84f0748d..eac6f80d786d5fa63834460c2f85ec905c8a99d4 100644 (file)
@@ -630,18 +630,9 @@ start:
         * by root.  This keeps people from modifying setuid and
         * setgid binaries.
         */
-
-       if (((xip->i_d.di_mode & S_ISUID) ||
-           ((xip->i_d.di_mode & (S_ISGID | S_IXGRP)) ==
-               (S_ISGID | S_IXGRP))) &&
-            !capable(CAP_FSETID)) {
-               error = xfs_write_clear_setuid(xip);
-               if (likely(!error))
-                       error = -file_remove_suid(file);
-               if (unlikely(error)) {
-                       goto out_unlock_internal;
-               }
-       }
+       error = -file_remove_suid(file);
+       if (unlikely(error))
+               goto out_unlock_internal;
 
        /* We can write back this queue in page reclaim */
        current->backing_dev_info = mapping->backing_dev_info;
index abb2c458b14806d42198154e09f7438d00c88c74..e336742a58a47a467a24abb0688b8c1fe7853207 100644 (file)
 #include "xfs_rw.h"
 #include "xfs_trace.h"
 
-/*
- * This is a subroutine for xfs_write() and other writers (xfs_ioctl)
- * which clears the setuid and setgid bits when a file is written.
- */
-int
-xfs_write_clear_setuid(
-       xfs_inode_t     *ip)
-{
-       xfs_mount_t     *mp;
-       xfs_trans_t     *tp;
-       int             error;
-
-       mp = ip->i_mount;
-       tp = xfs_trans_alloc(mp, XFS_TRANS_WRITEID);
-       if ((error = xfs_trans_reserve(tp, 0,
-                                     XFS_WRITEID_LOG_RES(mp),
-                                     0, 0, 0))) {
-               xfs_trans_cancel(tp, 0);
-               return error;
-       }
-       xfs_ilock(ip, XFS_ILOCK_EXCL);
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
-       ip->i_d.di_mode &= ~S_ISUID;
-
-       /*
-        * Note that we don't have to worry about mandatory
-        * file locking being disabled here because we only
-        * clear the S_ISGID bit if the Group execute bit is
-        * on, but if it was on then mandatory locking wouldn't
-        * have been enabled.
-        */
-       if (ip->i_d.di_mode & S_IXGRP) {
-               ip->i_d.di_mode &= ~S_ISGID;
-       }
-       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
-       xfs_trans_set_sync(tp);
-       error = xfs_trans_commit(tp, 0);
-       xfs_iunlock(ip, XFS_ILOCK_EXCL);
-       return 0;
-}
-
 /*
  * Force a shutdown of the filesystem instantly while keeping
  * the filesystem consistent. We don't do an unmount here; just shutdown
index a54c3b7cd376c9e3527d8e4a6021f42f598d60fe..11c41ec6ed75854dd0f59a974a2618c4c6c5f948 100644 (file)
@@ -39,7 +39,6 @@ xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb)
 /*
  * Prototypes for functions in xfs_rw.c.
  */
-extern int xfs_write_clear_setuid(struct xfs_inode *ip);
 extern int xfs_read_buf(struct xfs_mount *mp, xfs_buftarg_t *btp,
                        xfs_daddr_t blkno, int len, uint flags,
                        struct xfs_buf **bpp);