linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] VFS: make notify_change pass ATTR_KILL_S*ID to setattr operations
@ 2007-08-30 15:06 Jeff Layton
  2007-08-30 16:03 ` Peter Staubach
  2007-08-30 16:33 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Jeff Layton @ 2007-08-30 15:06 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel; +Cc: nfs, linux-cifs-client

Make notify_change not clear the ATTR_KILL_S*ID bits in the ia_vaid that
gets passed to the setattr inode operation. This allows the filesystems
to reinterpret whether this mode change is simply intended to clear the
setuid/setgid bits.

This means that notify_change should never be called with both ATTR_MODE
and either of the ATTR_KILL_S*ID bits set, since the filesystem would
have no way to know what part of the mode change was intentional. If
it is called this way, consider it a BUG().

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/attr.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/fs/attr.c b/fs/attr.c
index ae58bd3..f98d10c 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -103,12 +103,11 @@ EXPORT_SYMBOL(inode_setattr);
 int notify_change(struct dentry * dentry, struct iattr * attr)
 {
 	struct inode *inode = dentry->d_inode;
-	mode_t mode;
+	mode_t mode = inode->i_mode;
 	int error;
 	struct timespec now;
 	unsigned int ia_valid = attr->ia_valid;
 
-	mode = inode->i_mode;
 	now = current_fs_time(inode->i_sb);
 
 	attr->ia_ctime = now;
@@ -125,18 +124,21 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
 		if (error)
 			return error;
 	}
+
+	/*
+	 * It's not valid to pass an iattr with both ATTR_MODE and
+	 * ATTR_KILL_S*ID set.
+	 */
+	if (ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID) && ia_valid & ATTR_MODE)
+		BUG();
+
 	if (ia_valid & ATTR_KILL_SUID) {
-		attr->ia_valid &= ~ATTR_KILL_SUID;
 		if (mode & S_ISUID) {
-			if (!(ia_valid & ATTR_MODE)) {
-				ia_valid = attr->ia_valid |= ATTR_MODE;
-				attr->ia_mode = inode->i_mode;
-			}
-			attr->ia_mode &= ~S_ISUID;
+			ia_valid = attr->ia_valid |= ATTR_MODE;
+			attr->ia_mode = (inode->i_mode & ~S_ISUID);
 		}
 	}
 	if (ia_valid & ATTR_KILL_SGID) {
-		attr->ia_valid &= ~ ATTR_KILL_SGID;
 		if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
 			if (!(ia_valid & ATTR_MODE)) {
 				ia_valid = attr->ia_valid |= ATTR_MODE;
@@ -145,7 +147,7 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
 			attr->ia_mode &= ~S_ISGID;
 		}
 	}
-	if (!attr->ia_valid)
+	if (!(attr->ia_valid & ~(ATTR_KILL_SUID | ATTR_KILL_SGID)))
 		return 0;
 
 	if (ia_valid & ATTR_SIZE)
-- 
1.5.2.1


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

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

* Re: [PATCH 1/3] VFS: make notify_change pass ATTR_KILL_S*ID to setattr operations
  2007-08-30 15:06 [PATCH 1/3] VFS: make notify_change pass ATTR_KILL_S*ID to setattr operations Jeff Layton
@ 2007-08-30 16:03 ` Peter Staubach
  2007-08-30 16:33 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Staubach @ 2007-08-30 16:03 UTC (permalink / raw)
  To: Jeff Layton; +Cc: linux-fsdevel, linux-cifs-client, nfs, linux-kernel

Jeff Layton wrote:
> Make notify_change not clear the ATTR_KILL_S*ID bits in the ia_vaid that
> gets passed to the setattr inode operation. This allows the filesystems
> to reinterpret whether this mode change is simply intended to clear the
> setuid/setgid bits.
>
> This means that notify_change should never be called with both ATTR_MODE
> and either of the ATTR_KILL_S*ID bits set, since the filesystem would
> have no way to know what part of the mode change was intentional. If
> it is called this way, consider it a BUG().
>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> ---
>  fs/attr.c |   22 ++++++++++++----------
>  1 files changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/fs/attr.c b/fs/attr.c
> index ae58bd3..f98d10c 100644
> --- a/fs/attr.c
> +++ b/fs/attr.c
> @@ -103,12 +103,11 @@ EXPORT_SYMBOL(inode_setattr);
>  int notify_change(struct dentry * dentry, struct iattr * attr)
>  {
>  	struct inode *inode = dentry->d_inode;
> -	mode_t mode;
> +	mode_t mode = inode->i_mode;
>  	int error;
>  	struct timespec now;
>  	unsigned int ia_valid = attr->ia_valid;
>  
> -	mode = inode->i_mode;
>  	now = current_fs_time(inode->i_sb);
>  
>  	attr->ia_ctime = now;
> @@ -125,18 +124,21 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
>  		if (error)
>  			return error;
>  	}
> +
> +	/*
> +	 * It's not valid to pass an iattr with both ATTR_MODE and
> +	 * ATTR_KILL_S*ID set.
> +	 */
> +	if (ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID) && ia_valid & ATTR_MODE)
>   

If you would, please add some parentheses to show and make
explicit what the bindings are.  This is:

       if ((ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) &&
           (ia_valid & ATTR_MODE))

Thanx...

       ps

> +		BUG();
> +
>  	if (ia_valid & ATTR_KILL_SUID) {
> -		attr->ia_valid &= ~ATTR_KILL_SUID;
>  		if (mode & S_ISUID) {
> -			if (!(ia_valid & ATTR_MODE)) {
> -				ia_valid = attr->ia_valid |= ATTR_MODE;
> -				attr->ia_mode = inode->i_mode;
> -			}
> -			attr->ia_mode &= ~S_ISUID;
> +			ia_valid = attr->ia_valid |= ATTR_MODE;
> +			attr->ia_mode = (inode->i_mode & ~S_ISUID);
>  		}
>  	}
>  	if (ia_valid & ATTR_KILL_SGID) {
> -		attr->ia_valid &= ~ ATTR_KILL_SGID;
>  		if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
>  			if (!(ia_valid & ATTR_MODE)) {
>  				ia_valid = attr->ia_valid |= ATTR_MODE;
> @@ -145,7 +147,7 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
>  			attr->ia_mode &= ~S_ISGID;
>  		}
>  	}
> -	if (!attr->ia_valid)
> +	if (!(attr->ia_valid & ~(ATTR_KILL_SUID | ATTR_KILL_SGID)))
>  		return 0;
>  
>  	if (ia_valid & ATTR_SIZE)
>   


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

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

* Re: [PATCH 1/3] VFS: make notify_change pass ATTR_KILL_S*ID to setattr operations
  2007-08-30 15:06 [PATCH 1/3] VFS: make notify_change pass ATTR_KILL_S*ID to setattr operations Jeff Layton
  2007-08-30 16:03 ` Peter Staubach
@ 2007-08-30 16:33 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2007-08-30 16:33 UTC (permalink / raw)
  To: Jeff Layton; +Cc: linux-kernel, linux-fsdevel, linux-cifs-client, nfs

On Thu, Aug 30, 2007 at 11:06:38AM -0400, Jeff Layton wrote:
> Make notify_change not clear the ATTR_KILL_S*ID bits in the ia_vaid that
> gets passed to the setattr inode operation. This allows the filesystems
> to reinterpret whether this mode change is simply intended to clear the
> setuid/setgid bits.
> 
> This means that notify_change should never be called with both ATTR_MODE
> and either of the ATTR_KILL_S*ID bits set, since the filesystem would
> have no way to know what part of the mode change was intentional. If
> it is called this way, consider it a BUG().

This one looks fine to, but you'll probably need an additional patch
to ecryptfs so it clears ATTR_MODE before calling notify_change for
the lower inode.


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

end of thread, other threads:[~2007-08-30 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-30 15:06 [PATCH 1/3] VFS: make notify_change pass ATTR_KILL_S*ID to setattr operations Jeff Layton
2007-08-30 16:03 ` Peter Staubach
2007-08-30 16:33 ` Christoph Hellwig

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).