Skip to content

Commit c01638f

Browse files
author
Miklos Szeredi
committed
fuse: fix clearing suid, sgid for chown()
Basically, the pjdfstests set the ownership of a file to 06555, and then chowns it (as root) to a new uid/gid. Prior to commit a09f99e ("fuse: fix killing s[ug]id in setattr"), fuse would send down a setattr with both the uid/gid change and a new mode. Now, it just sends down the uid/gid change. Technically this is NOTABUG, since POSIX doesn't _require_ that we clear these bits for a privileged process, but Linux (wisely) has done that and I think we don't want to change that behavior here. This is caused by the use of should_remove_suid(), which will always return 0 when the process has CAP_FSETID. In fact we really don't need to be calling should_remove_suid() at all, since we've already been indicated that we should remove the suid, we just don't want to use a (very) stale mode for that. This patch should fix the above as well as simplify the logic. Reported-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Fixes: a09f99e ("fuse: fix killing s[ug]id in setattr") Cc: <stable@vger.kernel.org> Reviewed-by: Jeff Layton <jlayton@redhat.com>
1 parent 3e5de27 commit c01638f

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

fs/fuse/dir.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,8 +1739,6 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
17391739
* This should be done on write(), truncate() and chown().
17401740
*/
17411741
if (!fc->handle_killpriv) {
1742-
int kill;
1743-
17441742
/*
17451743
* ia_mode calculation may have used stale i_mode.
17461744
* Refresh and recalculate.
@@ -1750,12 +1748,11 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
17501748
return ret;
17511749

17521750
attr->ia_mode = inode->i_mode;
1753-
kill = should_remove_suid(entry);
1754-
if (kill & ATTR_KILL_SUID) {
1751+
if (inode->i_mode & S_ISUID) {
17551752
attr->ia_valid |= ATTR_MODE;
17561753
attr->ia_mode &= ~S_ISUID;
17571754
}
1758-
if (kill & ATTR_KILL_SGID) {
1755+
if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
17591756
attr->ia_valid |= ATTR_MODE;
17601757
attr->ia_mode &= ~S_ISGID;
17611758
}

0 commit comments

Comments
 (0)