Commit 87185517de81101da5afbc82cefdeed6eeaa38fb

Authored by Christoph Hellwig
Committed by Alex Elder
1 parent 5322892d86

xfs: only clear the suid bit once in xfs_write

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>

Showing 3 changed files with 3 additions and 55 deletions Side-by-side Diff

fs/xfs/linux-2.6/xfs_lrw.c
... ... @@ -630,18 +630,9 @@
630 630 * by root. This keeps people from modifying setuid and
631 631 * setgid binaries.
632 632 */
633   -
634   - if (((xip->i_d.di_mode & S_ISUID) ||
635   - ((xip->i_d.di_mode & (S_ISGID | S_IXGRP)) ==
636   - (S_ISGID | S_IXGRP))) &&
637   - !capable(CAP_FSETID)) {
638   - error = xfs_write_clear_setuid(xip);
639   - if (likely(!error))
640   - error = -file_remove_suid(file);
641   - if (unlikely(error)) {
642   - goto out_unlock_internal;
643   - }
644   - }
  633 + error = -file_remove_suid(file);
  634 + if (unlikely(error))
  635 + goto out_unlock_internal;
645 636  
646 637 /* We can write back this queue in page reclaim */
647 638 current->backing_dev_info = mapping->backing_dev_info;
... ... @@ -47,48 +47,6 @@
47 47 #include "xfs_trace.h"
48 48  
49 49 /*
50   - * This is a subroutine for xfs_write() and other writers (xfs_ioctl)
51   - * which clears the setuid and setgid bits when a file is written.
52   - */
53   -int
54   -xfs_write_clear_setuid(
55   - xfs_inode_t *ip)
56   -{
57   - xfs_mount_t *mp;
58   - xfs_trans_t *tp;
59   - int error;
60   -
61   - mp = ip->i_mount;
62   - tp = xfs_trans_alloc(mp, XFS_TRANS_WRITEID);
63   - if ((error = xfs_trans_reserve(tp, 0,
64   - XFS_WRITEID_LOG_RES(mp),
65   - 0, 0, 0))) {
66   - xfs_trans_cancel(tp, 0);
67   - return error;
68   - }
69   - xfs_ilock(ip, XFS_ILOCK_EXCL);
70   - xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
71   - xfs_trans_ihold(tp, ip);
72   - ip->i_d.di_mode &= ~S_ISUID;
73   -
74   - /*
75   - * Note that we don't have to worry about mandatory
76   - * file locking being disabled here because we only
77   - * clear the S_ISGID bit if the Group execute bit is
78   - * on, but if it was on then mandatory locking wouldn't
79   - * have been enabled.
80   - */
81   - if (ip->i_d.di_mode & S_IXGRP) {
82   - ip->i_d.di_mode &= ~S_ISGID;
83   - }
84   - xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
85   - xfs_trans_set_sync(tp);
86   - error = xfs_trans_commit(tp, 0);
87   - xfs_iunlock(ip, XFS_ILOCK_EXCL);
88   - return 0;
89   -}
90   -
91   -/*
92 50 * Force a shutdown of the filesystem instantly while keeping
93 51 * the filesystem consistent. We don't do an unmount here; just shutdown
94 52 * the shop, make sure that absolutely nothing persistent happens to
... ... @@ -39,7 +39,6 @@
39 39 /*
40 40 * Prototypes for functions in xfs_rw.c.
41 41 */
42   -extern int xfs_write_clear_setuid(struct xfs_inode *ip);
43 42 extern int xfs_read_buf(struct xfs_mount *mp, xfs_buftarg_t *btp,
44 43 xfs_daddr_t blkno, int len, uint flags,
45 44 struct xfs_buf **bpp);