public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] smack: remove unnecessary xattr checks
@ 2008-07-01 20:47 Miklos Szeredi
  2008-07-01 21:47 ` Casey Schaufler
  2008-07-02  0:01 ` Casey Schaufler
  0 siblings, 2 replies; 4+ messages in thread
From: Miklos Szeredi @ 2008-07-01 20:47 UTC (permalink / raw)
  To: casey; +Cc: akpm, linux-security-module, linux-kernel

Hi Casey,

This is an untested patch, if it looks OK, can you please apply it to
your tree (or ACK it)?

Thanks,
Miklos

----
From: Miklos Szeredi <mszeredi@suse.cz>

getxattr() calls security_inode_permission(MAY_READ) so
smack_inode_getxattr() is unnecessary.

setxattr() and removexattr() call security_inode_permission(MAY_WRITE)
so the write permission checks in smack_inode_setxattr() and
smack_inode_removexattr() are unnecessary.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---
 security/smack/smack_lsm.c |   19 -------------------
 1 file changed, 19 deletions(-)

Index: linux-2.6/security/smack/smack_lsm.c
===================================================================
--- linux-2.6.orig/security/smack/smack_lsm.c	2008-07-01 21:44:05.000000000 +0200
+++ linux-2.6/security/smack/smack_lsm.c	2008-07-01 21:45:27.000000000 +0200
@@ -588,9 +588,6 @@ static int smack_inode_setxattr(struct d
 	} else
 		rc = cap_inode_setxattr(dentry, name, value, size, flags);
 
-	if (rc == 0)
-		rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
-
 	return rc;
 }
 
@@ -636,18 +633,6 @@ static void smack_inode_post_setxattr(st
 }
 
 /*
- * smack_inode_getxattr - Smack check on getxattr
- * @dentry: the object
- * @name: unused
- *
- * Returns 0 if access is permitted, an error code otherwise
- */
-static int smack_inode_getxattr(struct dentry *dentry, const char *name)
-{
-	return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
-}
-
-/*
  * smack_inode_removexattr - Smack check on removexattr
  * @dentry: the object
  * @name: name of the attribute
@@ -668,9 +653,6 @@ static int smack_inode_removexattr(struc
 	} else
 		rc = cap_inode_removexattr(dentry, name);
 
-	if (rc == 0)
-		rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
-
 	return rc;
 }
 
@@ -2606,7 +2588,6 @@ struct security_operations smack_ops = {
 	.inode_getattr = 		smack_inode_getattr,
 	.inode_setxattr = 		smack_inode_setxattr,
 	.inode_post_setxattr = 		smack_inode_post_setxattr,
-	.inode_getxattr = 		smack_inode_getxattr,
 	.inode_removexattr = 		smack_inode_removexattr,
 	.inode_need_killpriv =		cap_inode_need_killpriv,
 	.inode_killpriv =		cap_inode_killpriv,

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

* Re: [patch] smack: remove unnecessary xattr checks
  2008-07-01 20:47 [patch] smack: remove unnecessary xattr checks Miklos Szeredi
@ 2008-07-01 21:47 ` Casey Schaufler
  2008-07-02  0:01 ` Casey Schaufler
  1 sibling, 0 replies; 4+ messages in thread
From: Casey Schaufler @ 2008-07-01 21:47 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: akpm, linux-security-module, linux-kernel

Miklos Szeredi wrote:
> Hi Casey,
>
> This is an untested patch, if it looks OK, can you please apply it to
> your tree (or ACK it)?
>
>   

I will give it some review and a test or two
then let you know. Things are hopping right now,
so it may take a day or two.

Thank you for the work you've put into this.

> Thanks,
> Miklos
>
> ----
> From: Miklos Szeredi <mszeredi@suse.cz>
>
> getxattr() calls security_inode_permission(MAY_READ) so
> smack_inode_getxattr() is unnecessary.
>
> setxattr() and removexattr() call security_inode_permission(MAY_WRITE)
> so the write permission checks in smack_inode_setxattr() and
> smack_inode_removexattr() are unnecessary.
>
> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
> ---
>  security/smack/smack_lsm.c |   19 -------------------
>  1 file changed, 19 deletions(-)
>
> Index: linux-2.6/security/smack/smack_lsm.c
> ===================================================================
> --- linux-2.6.orig/security/smack/smack_lsm.c	2008-07-01 21:44:05.000000000 +0200
> +++ linux-2.6/security/smack/smack_lsm.c	2008-07-01 21:45:27.000000000 +0200
> @@ -588,9 +588,6 @@ static int smack_inode_setxattr(struct d
>  	} else
>  		rc = cap_inode_setxattr(dentry, name, value, size, flags);
>  
> -	if (rc == 0)
> -		rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
> -
>  	return rc;
>  }
>  
> @@ -636,18 +633,6 @@ static void smack_inode_post_setxattr(st
>  }
>  
>  /*
> - * smack_inode_getxattr - Smack check on getxattr
> - * @dentry: the object
> - * @name: unused
> - *
> - * Returns 0 if access is permitted, an error code otherwise
> - */
> -static int smack_inode_getxattr(struct dentry *dentry, const char *name)
> -{
> -	return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
> -}
> -
> -/*
>   * smack_inode_removexattr - Smack check on removexattr
>   * @dentry: the object
>   * @name: name of the attribute
> @@ -668,9 +653,6 @@ static int smack_inode_removexattr(struc
>  	} else
>  		rc = cap_inode_removexattr(dentry, name);
>  
> -	if (rc == 0)
> -		rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
> -
>  	return rc;
>  }
>  
> @@ -2606,7 +2588,6 @@ struct security_operations smack_ops = {
>  	.inode_getattr = 		smack_inode_getattr,
>  	.inode_setxattr = 		smack_inode_setxattr,
>  	.inode_post_setxattr = 		smack_inode_post_setxattr,
> -	.inode_getxattr = 		smack_inode_getxattr,
>  	.inode_removexattr = 		smack_inode_removexattr,
>  	.inode_need_killpriv =		cap_inode_need_killpriv,
>  	.inode_killpriv =		cap_inode_killpriv,
>
>
>   


-- 

----------------------

Casey Schaufler
casey@schaufler-ca.com
650.906.1780



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

* Re: [patch] smack: remove unnecessary xattr checks
  2008-07-01 20:47 [patch] smack: remove unnecessary xattr checks Miklos Szeredi
  2008-07-01 21:47 ` Casey Schaufler
@ 2008-07-02  0:01 ` Casey Schaufler
  2008-07-02  7:30   ` Miklos Szeredi
  1 sibling, 1 reply; 4+ messages in thread
From: Casey Schaufler @ 2008-07-02  0:01 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: akpm, linux-security-module, linux-kernel

Miklos Szeredi wrote:
> Hi Casey,
>
> This is an untested patch, if it looks OK, can you please apply it to
> your tree (or ACK it)?
>
> Thanks,
> Miklos
>
> ----
> From: Miklos Szeredi <mszeredi@suse.cz>
>
> getxattr() calls security_inode_permission(MAY_READ) so
> smack_inode_getxattr() is unnecessary.
>
> setxattr() and removexattr() call security_inode_permission(MAY_WRITE)
> so the write permission checks in smack_inode_setxattr() and
> smack_inode_removexattr() are unnecessary.
>
> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
>   
Nacked-by: Casey Schaufler <casey@schaufler-ca.com>

I tried your patch without looking at it and found that
getxattr is too permissive with your changes. I found that

   % ls -l foo

will fail while

   % attr -S -g SMACK64 foo

will succeed. Of course if stat() fails due to a Smack
access check getxattr() ought to as well. So it would
appear that the call to security_inode_permission is not
sufficient.


> ---
>  security/smack/smack_lsm.c |   19 -------------------
>  1 file changed, 19 deletions(-)
>
> Index: linux-2.6/security/smack/smack_lsm.c
> ===================================================================
> --- linux-2.6.orig/security/smack/smack_lsm.c	2008-07-01 21:44:05.000000000 +0200
> +++ linux-2.6/security/smack/smack_lsm.c	2008-07-01 21:45:27.000000000 +0200
> @@ -588,9 +588,6 @@ static int smack_inode_setxattr(struct d
>  	} else
>  		rc = cap_inode_setxattr(dentry, name, value, size, flags);
>  
> -	if (rc == 0)
> -		rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
> -
>  	return rc;
>  }
>  
> @@ -636,18 +633,6 @@ static void smack_inode_post_setxattr(st
>  }
>  
>  /*
> - * smack_inode_getxattr - Smack check on getxattr
> - * @dentry: the object
> - * @name: unused
> - *
> - * Returns 0 if access is permitted, an error code otherwise
> - */
> -static int smack_inode_getxattr(struct dentry *dentry, const char *name)
> -{
> -	return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
> -}
> -
> -/*
>   * smack_inode_removexattr - Smack check on removexattr
>   * @dentry: the object
>   * @name: name of the attribute
> @@ -668,9 +653,6 @@ static int smack_inode_removexattr(struc
>  	} else
>  		rc = cap_inode_removexattr(dentry, name);
>  
> -	if (rc == 0)
> -		rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
> -
>  	return rc;
>  }
>  
> @@ -2606,7 +2588,6 @@ struct security_operations smack_ops = {
>  	.inode_getattr = 		smack_inode_getattr,
>  	.inode_setxattr = 		smack_inode_setxattr,
>  	.inode_post_setxattr = 		smack_inode_post_setxattr,
> -	.inode_getxattr = 		smack_inode_getxattr,
>  	.inode_removexattr = 		smack_inode_removexattr,
>  	.inode_need_killpriv =		cap_inode_need_killpriv,
>  	.inode_killpriv =		cap_inode_killpriv,
>
>
>   


-- 

----------------------

Casey Schaufler
casey@schaufler-ca.com
650.906.1780



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

* Re: [patch] smack: remove unnecessary xattr checks
  2008-07-02  0:01 ` Casey Schaufler
@ 2008-07-02  7:30   ` Miklos Szeredi
  0 siblings, 0 replies; 4+ messages in thread
From: Miklos Szeredi @ 2008-07-02  7:30 UTC (permalink / raw)
  To: casey; +Cc: miklos, akpm, linux-security-module, linux-kernel

On Tue, 01 Jul 2008, Casey Schaufler wrote:
> I tried your patch without looking at it and found that
> getxattr is too permissive with your changes. I found that
> 
>    % ls -l foo
> 
> will fail while
> 
>    % attr -S -g SMACK64 foo
> 
> will succeed. Of course if stat() fails due to a Smack
> access check getxattr() ought to as well. So it would
> appear that the call to security_inode_permission is not
> sufficient.

Hmm, I missed the fact that security_inode_permission() is only called
for xattrs not in the speclial (security.*, system.*, trusted.*)
namespaces.  So yes the patch is incorrect.

Thanks,
Miklos

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

end of thread, other threads:[~2008-07-02  7:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-01 20:47 [patch] smack: remove unnecessary xattr checks Miklos Szeredi
2008-07-01 21:47 ` Casey Schaufler
2008-07-02  0:01 ` Casey Schaufler
2008-07-02  7:30   ` Miklos Szeredi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox