From: "J. Bruce Fields" <bfields@fieldses.org>
To: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
Cc: linux-nfs@vger.kernel.org, vasily.isaenko@oracle.com,
hch@infradead.org, xfs@oss.sgi.com, sprabhu@redhat.com
Subject: Re: [PATCH] nfsd: revoking of suid/sgid bits after chown() in a consistent way
Date: Thu, 12 Dec 2013 11:01:28 -0500 [thread overview]
Message-ID: <20131212160128.GC11521@fieldses.org> (raw)
In-Reply-To: <1386756996-28083-1-git-send-email-stanislav.kholmanskikh@oracle.com>
Thanks, applying for 3.14.--b.
On Wed, Dec 11, 2013 at 02:16:36PM +0400, Stanislav Kholmanskikh wrote:
> There is an inconsistency in the handling of SUID/SGID file
> bits after chown() between NFS and other local file systems.
>
> Local file systems (for example, ext3, ext4, xfs, btrfs) revoke
> SUID/SGID bits after chown() on a regular file even if
> the owner/group of the file has not been changed:
>
> ~# touch file; chmod ug+s file; chmod u+x file
> ~# ls -l file
> -rwsr-Sr-- 1 root root 0 Dec 6 04:49 file
> ~# chown root file; ls -l file
> -rwxr-Sr-- 1 root root 0 Dec 6 04:49 file
>
> but NFS doesn't do that:
>
> ~# touch file; chmod ug+s file; chmod u+x file
> ~# ls -l file
> -rwsr-Sr-- 1 root root 0 Dec 6 04:49 file
> ~# chown root file; ls -l file
> -rwsr-Sr-- 1 root root 0 Dec 6 04:49 file
>
> NFS does that only if the owner/group has been changed:
>
> ~# touch file; chmod ug+s file; chmod u+x file
> ~# ls -l file
> -rwsr-Sr-- 1 root root 0 Dec 6 05:02 file
> ~# chown bin file; ls -l file
> -rwxr-Sr-- 1 bin root 0 Dec 6 05:02 file
>
> See: http://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html
>
> "If the specified file is a regular file, one or more of
> the S_IXUSR, S_IXGRP, or S_IXOTH bits of the file mode are set,
> and the process has appropriate privileges, it is
> implementation-defined whether the set-user-ID and set-group-ID
> bits are altered."
>
> So both variants are acceptable by POSIX.
>
> This patch makes NFS to behave like local file systems.
>
> Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
> ---
> fs/nfsd/vfs.c | 3 +--
> 1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index 72cb28e..8226991 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -348,8 +348,7 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap)
>
> /* Revoke setuid/setgid on chown */
> if (!S_ISDIR(inode->i_mode) &&
> - (((iap->ia_valid & ATTR_UID) && !uid_eq(iap->ia_uid, inode->i_uid)) ||
> - ((iap->ia_valid & ATTR_GID) && !gid_eq(iap->ia_gid, inode->i_gid)))) {
> + ((iap->ia_valid & ATTR_UID) || (iap->ia_valid & ATTR_GID))) {
> iap->ia_valid |= ATTR_KILL_PRIV;
> if (iap->ia_valid & ATTR_MODE) {
> /* we're setting mode too, just clear the s*id bits */
> --
> 1.7.1
>
prev parent reply other threads:[~2013-12-12 16:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-06 11:56 nfs vs xfstests 193 Christoph Hellwig
2013-12-06 13:20 ` Stanislav Kholmanskikh
2013-12-06 18:08 ` Christoph Hellwig
2013-12-06 20:44 ` J. Bruce Fields
2013-12-06 20:47 ` J. Bruce Fields
2013-12-10 14:43 ` Stanislav Kholmanskikh
2013-12-11 10:16 ` [PATCH] nfsd: revoking of suid/sgid bits after chown() in a consistent way Stanislav Kholmanskikh
2013-12-11 11:00 ` Stanislav Kholmanskikh
2013-12-12 3:38 ` J. Bruce Fields
2013-12-12 8:13 ` Christoph Hellwig
2013-12-12 11:44 ` Stanislav Kholmanskikh
2013-12-12 16:01 ` 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=20131212160128.GC11521@fieldses.org \
--to=bfields@fieldses.org \
--cc=hch@infradead.org \
--cc=linux-nfs@vger.kernel.org \
--cc=sprabhu@redhat.com \
--cc=stanislav.kholmanskikh@oracle.com \
--cc=vasily.isaenko@oracle.com \
--cc=xfs@oss.sgi.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).