public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Smack: check for SMACK xattr max size in  smack_inode_setxattr
@ 2009-04-14 18:28 Etienne Basset
  2009-04-15  4:25 ` Casey Schaufler
  0 siblings, 1 reply; 6+ messages in thread
From: Etienne Basset @ 2009-04-14 18:28 UTC (permalink / raw)
  To: Casey Schaufler, LSM; +Cc: Linux Kernel Mailing List

the following patch move the check for SMACK xattr size >= SMK_LABELLEN
from  smack_inode_post_setxattr (which cannot return an error to the user)
to smack_inode_setxattr (which can return an error).

without patch a SMACK setxattr with size >= SMK_LABELLEN returns success although it doesn't 

Signed-off-by: Etienne Basset <etienne.basset@numericable.fr>
---
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 9215149..da6954d 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -610,7 +610,8 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
 		if (!capable(CAP_MAC_ADMIN))
 			rc = -EPERM;
 		/* a label cannot be void and cannot begin with '-' */
-		if (size == 0 || (size > 0 && ((char *)value)[0] == '-'))
+		if (size == 0 || size >= SMK_LABELLEN ||
+		   (size > 0 && ((char *)value)[0] == '-'))
 			rc = -EINVAL;
 	} else
 		rc = cap_inode_setxattr(dentry, name, value, size, flags);
@@ -644,9 +645,6 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
 	if (strcmp(name, XATTR_NAME_SMACK))
 		return;
 
-	if (size >= SMK_LABELLEN)
-		return;
-
 	isp = dentry->d_inode->i_security;
 
 	/*


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

* Re: [PATCH] Smack: check for SMACK xattr max size in  smack_inode_setxattr
  2009-04-14 18:28 [PATCH] Smack: check for SMACK xattr max size in smack_inode_setxattr Etienne Basset
@ 2009-04-15  4:25 ` Casey Schaufler
  2009-04-15  6:26   ` Etienne Basset
  0 siblings, 1 reply; 6+ messages in thread
From: Casey Schaufler @ 2009-04-15  4:25 UTC (permalink / raw)
  To: Etienne Basset; +Cc: LSM, Linux Kernel Mailing List, Casey Schaufler

Etienne Basset wrote:
> the following patch move the check for SMACK xattr size >= SMK_LABELLEN
> from  smack_inode_post_setxattr (which cannot return an error to the user)
> to smack_inode_setxattr (which can return an error).
>
> without patch a SMACK setxattr with size >= SMK_LABELLEN returns success although it doesn't 
>   

How about an early call to smk_import() to determine if the
label if legitimate, rather than checking the length? That
could save grief for other "invalid label" issues.

> Signed-off-by: Etienne Basset <etienne.basset@numericable.fr>
> ---
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index 9215149..da6954d 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -610,7 +610,8 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
>  		if (!capable(CAP_MAC_ADMIN))
>  			rc = -EPERM;
>  		/* a label cannot be void and cannot begin with '-' */
> -		if (size == 0 || (size > 0 && ((char *)value)[0] == '-'))
> +		if (size == 0 || size >= SMK_LABELLEN ||
> +		   (size > 0 && ((char *)value)[0] == '-'))
>  			rc = -EINVAL;
>  	} else
>  		rc = cap_inode_setxattr(dentry, name, value, size, flags);
> @@ -644,9 +645,6 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
>  	if (strcmp(name, XATTR_NAME_SMACK))
>  		return;
>  
> -	if (size >= SMK_LABELLEN)
> -		return;
> -
>  	isp = dentry->d_inode->i_security;
>  
>  	/*
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
>
>   


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

* Re: [PATCH] Smack: check for SMACK xattr max size in  smack_inode_setxattr
  2009-04-15  4:25 ` Casey Schaufler
@ 2009-04-15  6:26   ` Etienne Basset
  2009-04-15 16:28     ` Casey Schaufler
  0 siblings, 1 reply; 6+ messages in thread
From: Etienne Basset @ 2009-04-15  6:26 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: LSM, Linux Kernel Mailing List

Casey Schaufler wrote:
> Etienne Basset wrote:
>> the following patch move the check for SMACK xattr size >= SMK_LABELLEN
>> from  smack_inode_post_setxattr (which cannot return an error to the user)
>> to smack_inode_setxattr (which can return an error).
>>
>> without patch a SMACK setxattr with size >= SMK_LABELLEN returns success although it doesn't 
>>   
> 
> How about an early call to smk_import() to determine if the
> label if legitimate, rather than checking the length? That
> could save grief for other "invalid label" issues.

Hi,

both are needed. And we'll need one call in setxattr to check the validity and one in
postsetxattr/ inode_setsecurity (to set the security blob)
(which make me think we should split smk_import in 2,  smk_check/smk_import_nocheck or whatever)

The harder issue is that smk_import can change the value/size of the xattr
and smk_import can fail for 2 reasons : ENOMEM or EINVAL (not sure this is an issue though)
(we should really split)

root@etienne-desktop:/tmp# attr -S -s SMACK64 -V '123////' toto
Attribute "SMACK64" set to a 7 byte value for toto:
123////
root@etienne-desktop:/tmp# attr -S -g SMACK64 toto
Attribute "SMACK64" had a 4 byte value for toto:
123

maybe it would be nicer to fail than change the label under the foot of the-user-who-hasnt-read-the-doc?

Etienne
> 
>> Signed-off-by: Etienne Basset <etienne.basset@numericable.fr>
>> ---
>> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
>> index 9215149..da6954d 100644
>> --- a/security/smack/smack_lsm.c
>> +++ b/security/smack/smack_lsm.c
>> @@ -610,7 +610,8 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
>>  		if (!capable(CAP_MAC_ADMIN))
>>  			rc = -EPERM;
>>  		/* a label cannot be void and cannot begin with '-' */
>> -		if (size == 0 || (size > 0 && ((char *)value)[0] == '-'))
>> +		if (size == 0 || size >= SMK_LABELLEN ||
>> +		   (size > 0 && ((char *)value)[0] == '-'))
>>  			rc = -EINVAL;
>>  	} else
>>  		rc = cap_inode_setxattr(dentry, name, value, size, flags);
>> @@ -644,9 +645,6 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
>>  	if (strcmp(name, XATTR_NAME_SMACK))
>>  		return;
>>  
>> -	if (size >= SMK_LABELLEN)
>> -		return;
>> -
>>  	isp = dentry->d_inode->i_security;
>>  
>>  	/*
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>>
>>
>>   
> 
> 


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

* Re: [PATCH] Smack: check for SMACK xattr max size in  smack_inode_setxattr
  2009-04-15  6:26   ` Etienne Basset
@ 2009-04-15 16:28     ` Casey Schaufler
  2009-04-16 21:58       ` [PATCH] Smack: check for SMACK xattr validity " Etienne Basset
  0 siblings, 1 reply; 6+ messages in thread
From: Casey Schaufler @ 2009-04-15 16:28 UTC (permalink / raw)
  To: Etienne Basset; +Cc: LSM, Linux Kernel Mailing List, Casey Schaufler

Etienne Basset wrote:
> Casey Schaufler wrote:
>   
>> Etienne Basset wrote:
>>     
>>> the following patch move the check for SMACK xattr size >= SMK_LABELLEN
>>> from  smack_inode_post_setxattr (which cannot return an error to the user)
>>> to smack_inode_setxattr (which can return an error).
>>>
>>> without patch a SMACK setxattr with size >= SMK_LABELLEN returns success although it doesn't 
>>>   
>>>       
>> How about an early call to smk_import() to determine if the
>> label if legitimate, rather than checking the length? That
>> could save grief for other "invalid label" issues.
>>     
>
> Hi,
>
> both are needed. And we'll need one call in setxattr to check the validity and one in
> postsetxattr/ inode_setsecurity (to set the security blob)
> (which make me think we should split smk_import in 2,  smk_check/smk_import_nocheck or whatever)
>
> The harder issue is that smk_import can change the value/size of the xattr
> and smk_import can fail for 2 reasons : ENOMEM or EINVAL (not sure this is an issue though)
> (we should really split)
>
> root@etienne-desktop:/tmp# attr -S -s SMACK64 -V '123////' toto
> Attribute "SMACK64" set to a 7 byte value for toto:
> 123////
> root@etienne-desktop:/tmp# attr -S -g SMACK64 toto
> Attribute "SMACK64" had a 4 byte value for toto:
> 123
>
> maybe it would be nicer to fail than change the label under the foot of the-user-who-hasnt-read-the-doc?
>   

Clumsy attribute setting (trailing spaces, NULLs, etc) is just too easy.
I like the existing behavior.

> Etienne
>   
>>> Signed-off-by: Etienne Basset <etienne.basset@numericable.fr>
>>> ---
>>> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
>>> index 9215149..da6954d 100644
>>> --- a/security/smack/smack_lsm.c
>>> +++ b/security/smack/smack_lsm.c
>>> @@ -610,7 +610,8 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
>>>  		if (!capable(CAP_MAC_ADMIN))
>>>  			rc = -EPERM;
>>>  		/* a label cannot be void and cannot begin with '-' */
>>> -		if (size == 0 || (size > 0 && ((char *)value)[0] == '-'))
>>> +		if (size == 0 || size >= SMK_LABELLEN ||
>>> +		   (size > 0 && ((char *)value)[0] == '-'))
>>>  			rc = -EINVAL;
>>>  	} else
>>>  		rc = cap_inode_setxattr(dentry, name, value, size, flags);
>>> @@ -644,9 +645,6 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
>>>  	if (strcmp(name, XATTR_NAME_SMACK))
>>>  		return;
>>>  
>>> -	if (size >= SMK_LABELLEN)
>>> -		return;
>>> -
>>>  	isp = dentry->d_inode->i_security;
>>>  
>>>  	/*
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>> Please read the FAQ at  http://www.tux.org/lkml/
>>>
>>>
>>>   
>>>       
>>     
>
>
>   


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

* [PATCH] Smack: check for SMACK xattr validity in smack_inode_setxattr
  2009-04-15 16:28     ` Casey Schaufler
@ 2009-04-16 21:58       ` Etienne Basset
  2009-04-17  3:48         ` Casey Schaufler
  0 siblings, 1 reply; 6+ messages in thread
From: Etienne Basset @ 2009-04-16 21:58 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: LSM, Linux Kernel Mailing List

the following patch moves checks for SMACK xattr validity
from smack_inode_post_setxattr (which cannot return an error to the user)
to smack_inode_setxattr (which can return an error).

Signed-off-by: Etienne Basset <etienne.basset@numericable.fr>
---
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 9215149..98b3195 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -609,8 +609,12 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
 	    strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
 		if (!capable(CAP_MAC_ADMIN))
 			rc = -EPERM;
-		/* a label cannot be void and cannot begin with '-' */
-		if (size == 0 || (size > 0 && ((char *)value)[0] == '-'))
+		/*
+		 * check label validity here so import wont fail on
+		 * post_setxattr
+		 */
+		if (size == 0 || size >= SMK_LABELLEN ||
+		    smk_import(value, size) == NULL)
 			rc = -EINVAL;
 	} else
 		rc = cap_inode_setxattr(dentry, name, value, size, flags);
@@ -644,9 +648,6 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
 	if (strcmp(name, XATTR_NAME_SMACK))
 		return;
 
-	if (size >= SMK_LABELLEN)
-		return;
-
 	isp = dentry->d_inode->i_security;
 
 	/*



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

* Re: [PATCH] Smack: check for SMACK xattr validity in smack_inode_setxattr
  2009-04-16 21:58       ` [PATCH] Smack: check for SMACK xattr validity " Etienne Basset
@ 2009-04-17  3:48         ` Casey Schaufler
  0 siblings, 0 replies; 6+ messages in thread
From: Casey Schaufler @ 2009-04-17  3:48 UTC (permalink / raw)
  To: Etienne Basset; +Cc: LSM, Linux Kernel Mailing List

Etienne Basset wrote:
> the following patch moves checks for SMACK xattr validity
> from smack_inode_post_setxattr (which cannot return an error to the user)
> to smack_inode_setxattr (which can return an error).
>
> Signed-off-by: Etienne Basset <etienne.basset@numericable.fr>
>   

Acked-by: Casey Schaufler <casey@schaufler-ca.com>

> ---
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index 9215149..98b3195 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -609,8 +609,12 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
>  	    strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
>  		if (!capable(CAP_MAC_ADMIN))
>  			rc = -EPERM;
> -		/* a label cannot be void and cannot begin with '-' */
> -		if (size == 0 || (size > 0 && ((char *)value)[0] == '-'))
> +		/*
> +		 * check label validity here so import wont fail on
> +		 * post_setxattr
> +		 */
> +		if (size == 0 || size >= SMK_LABELLEN ||
> +		    smk_import(value, size) == NULL)
>  			rc = -EINVAL;
>  	} else
>  		rc = cap_inode_setxattr(dentry, name, value, size, flags);
> @@ -644,9 +648,6 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
>  	if (strcmp(name, XATTR_NAME_SMACK))
>  		return;
>  
> -	if (size >= SMK_LABELLEN)
> -		return;
> -
>  	isp = dentry->d_inode->i_security;
>  
>  	/*
>
>
>
>   


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

end of thread, other threads:[~2009-04-17  3:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-14 18:28 [PATCH] Smack: check for SMACK xattr max size in smack_inode_setxattr Etienne Basset
2009-04-15  4:25 ` Casey Schaufler
2009-04-15  6:26   ` Etienne Basset
2009-04-15 16:28     ` Casey Schaufler
2009-04-16 21:58       ` [PATCH] Smack: check for SMACK xattr validity " Etienne Basset
2009-04-17  3:48         ` Casey Schaufler

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