All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]: NFS: fix inadvertent reversion of mode bits during chown
@ 2005-12-15 13:09 Neil Horman
  2005-12-15 14:14 ` Trond Myklebust
  0 siblings, 1 reply; 18+ messages in thread
From: Neil Horman @ 2005-12-15 13:09 UTC (permalink / raw)
  To: nfs; +Cc: neilb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3233 bytes --]

Hey all-
	This problem was reported to me recently that when a process is attempting
to change ownership (chown) on a file on a NFS share, it is possible that
permissions bits will be reverted to a previous state on the server, even if an
exclusive lock is held on the file.  I verified this, and came to find that this
occurs if the SUID bit is set on the file.  Basically when a file is chown-ed,
the chown_call forcibly strips the SUID/SGID bits from the mode (ostensibly for
security purposes).  The VFS then implements this stripping (if the SUID/SGID
bits are currently set on the inode in question) by updating the iattr structure
in notify_change to not only change the UID/GID of the inode, but also the MODE,
using the mode bits in the inode.  This works fine on locally mounted file
systems, in which the inodes in ram are only modified by one system, and are in
sync with disk contents.  However on NFS, its possible for the a files
attributes to be out of sync with the cached inode on a given system sharing the
NFS mount.  As such, if system A changes the mode bits on a file on the server,
system B preforming a chown on an inode cached locally can inadvertantly revert
permissions on the inode to whatever was most recently cached.

I don't think this hole can be 100% closed, as we can guarantee the order of
arival of packets to the server between nodes, but we can be sure that the
filesystem bits aren't reverted if the accessing programs participate in a
locking protocol.  The patch below refreshes the inode and strips the SUID/SGID
bits from the latest server side inode->i_mode bits.  This has been tested and
prevents the described problem from occuring.

An alternate solution (and one that generates less traffic) may be to simply
disallow the setting of ATTR_MODE and (ATTR_UID|ATTR_GID) at the same time in
nfs_setattr, but I haven't thought through what all the implications are there.

Thanks & Regards
Neil 

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>


 inode.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+)


diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -845,6 +845,23 @@ nfs_setattr(struct dentry *dentry, struc
 	if (attr->ia_valid == 0)
 		return 0;
 
+	/*
+	 * If we are changing UID/GID, lets be sure that we
+	 * have the latest mode attribute.  Conducting a chown,
+	 * causes the suid bits to get dropped, and that in turn 
+	 * can accidentally revert file permissions.
+	 */
+	if ((attr->ia_valid & (ATTR_UID|ATTR_GID)) &&
+	    (attr->ia_valid & ATTR_MODE)) {
+		/*
+		 * We're changing U/GIDS and the MODE.  lets be sure
+		 * we have the most up-to-date mode from the server
+		 * minus the SUID/SGID bits
+		 */
+		__nfs_revalidate_inode(NFS_SERVER(inode),inode);
+		attr->ia_mode = inode->i_mode & ~(S_ISUID|S_ISGID);
+	}
+
 	lock_kernel();
 	nfs_begin_data_update(inode);
 	/* Write all dirty data if we're changing file permissions or size */
-- 
/***************************************************
 *Neil Horman
 *Software Engineer
 *gpg keyid: 1024D / 0x92A74FA1 - http://pgp.mit.edu
 ***************************************************/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2006-01-24 13:27 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-15 13:09 [PATCH]: NFS: fix inadvertent reversion of mode bits during chown Neil Horman
2005-12-15 14:14 ` Trond Myklebust
2005-12-15 14:49   ` Neil Horman
2005-12-15 14:57     ` Trond Myklebust
2005-12-15 16:38       ` Neil Horman
2005-12-15 16:48         ` Peter Staubach
2005-12-15 17:32           ` Trond Myklebust
2005-12-15 18:17             ` Neil Horman
2005-12-15 18:51               ` Trond Myklebust
2005-12-15 19:43               ` Neil Horman
2005-12-15 19:46                 ` Trond Myklebust
2005-12-15 19:51                   ` Neil Horman
2005-12-16 16:14                     ` Neil Horman
2006-01-24 13:27                       ` Neil Horman
2005-12-15 18:19             ` Peter Staubach
2005-12-15 18:56               ` Trond Myklebust
2005-12-15 19:05                 ` Peter Staubach
2005-12-15 16:50         ` Trond Myklebust

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.