All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: "Sachin S. Prabhu" <sprabhu@redhat.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH] Inconsistent setattr behaviour
Date: Wed, 18 Mar 2009 17:39:17 -0400	[thread overview]
Message-ID: <20090318213917.GD18894@fieldses.org> (raw)
In-Reply-To: <49A2CD2B.50607@redhat.com>

On Mon, Feb 23, 2009 at 04:22:03PM +0000, Sachin S. Prabhu wrote:
> There is an inconsistency seen in the behaviour of nfs compared to other local
> filesystems on linux when changing owner or group of a directory. If the
> directory has SUID/SGID flags set, on changing owner or group on the directory,
> the flags are stripped off on nfs. These flags are maintained on other
> filesystems such as ext3.
> 
> To reproduce on a nfs share or local filesystem, run the following commands
> mkdir test; chmod +s+g test; chown user1 test; ls -ld test
> 
> On the nfs share, the flags are stripped and the output seen is
> drwxr-xr-x 2 user1 root 4096 Feb 23  2009 test
> 
> On other local filesystems(ex: ext3), the flags are not stripped and the output
> seen is
> drwsr-sr-x 2 user1 root 4096 Feb 23 13:57 test
> 
> chown_common() called from sys_chown() will only strip the flags if the inode is
> not a directory.
> static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
> {
> ..
>         if (!S_ISDIR(inode->i_mode))
>                 newattrs.ia_valid |=
>                         ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV;
> ..
> }
> 
> See: http://www.opengroup.org/onlinepubs/7990989775/xsh/chown.html
> 
> "If the path argument refers to a regular file, the set-user-ID (S_ISUID) and
> set-group-ID (S_ISGID) bits of the file mode are cleared upon successful return
> from chown(), unless the call is made by a process with appropriate privileges,
> in which case it is implementation-dependent whether these bits are altered. If
> chown() is successfully invoked on a file that is not a regular file, these
> bits may be cleared. These bits are defined in <sys/stat.h>."
> 
> The behaviour as it stands does not appear to violate POSIX.  However the
> actions performed are inconsistent when comparing ext3 and nfs.

Makes sense, thanks!--applied for 2.6.30.--b.

> 
> Sachin Prabhu

> Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
> Acked-by: Jeff Layton <jlayton@redhat.com>
> --- linux-2.6.29-rc2/fs/nfsd/vfs.c.orig	2009-02-23 06:45:20.000000000 -0500
> +++ linux-2.6.29-rc2/fs/nfsd/vfs.c	2009-02-23 11:10:10.000000000 -0500
> @@ -366,8 +366,9 @@
>  	}
>  
>  	/* Revoke setuid/setgid on chown */
> -	if (((iap->ia_valid & ATTR_UID) && iap->ia_uid != inode->i_uid) ||
> -	    ((iap->ia_valid & ATTR_GID) && iap->ia_gid != inode->i_gid)) {
> +	if (!S_ISDIR(inode->i_mode) &&
> +	    (((iap->ia_valid & ATTR_UID) && iap->ia_uid != inode->i_uid) ||
> +	     ((iap->ia_valid & ATTR_GID) && iap->ia_gid != inode->i_gid))) {
>  		iap->ia_valid |= ATTR_KILL_PRIV;
>  		if (iap->ia_valid & ATTR_MODE) {
>  			/* we're setting mode too, just clear the s*id bits */


      parent reply	other threads:[~2009-03-18 21:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-23 16:22 [PATCH] Inconsistent setattr behaviour Sachin S. Prabhu
2009-02-23 16:52 ` Trond Myklebust
     [not found]   ` <1235407975.7598.4.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-02-23 16:58     ` Sachin S. Prabhu
2009-02-23 17:01       ` Trond Myklebust
2009-03-18 21:39 ` J. Bruce Fields [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090318213917.GD18894@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=sprabhu@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.