All of lore.kernel.org
 help / color / mirror / Atom feed
From: Casey Schaufler <casey@schaufler-ca.com>
To: Julia Lawall <julia@diku.dk>
Cc: "Serge E. Hallyn" <serue@us.ibm.com>,
	James Morris <jmorris@namei.org>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	Eric Paris <eparis@parisplace.org>,
	linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 3/4] security/selinux: decrement sizeof size in strncmp
Date: Thu, 12 Nov 2009 16:21:52 +0000	[thread overview]
Message-ID: <4AFC3620.2020809@schaufler-ca.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0911121556390.19779@ask.diku.dk>

Julia Lawall wrote:
> On Thu, 12 Nov 2009, Serge E. Hallyn wrote:
>
>   
>> Quoting James Morris (jmorris@namei.org):
>>     
>>> On Thu, 12 Nov 2009, Julia Lawall wrote:
>>>
>>>       
>>>> From: Julia Lawall <julia@diku.dk>
>>>>
>>>> As observed by Joe Perches, sizeof of a constant string includes the
>>>> trailing 0.  If what is wanted is to check the initial characters of
>>>> another string, this trailing 0 should not be taken into account.  If an
>>>> exact match is wanted, strcmp should be used instead.
>>>>         
>>>> --- a/security/selinux/hooks.c
>>>> +++ b/security/selinux/hooks.c
>>>> @@ -448,7 +448,7 @@ static int sb_finish_set_opts(struct sup
>>>>  		sbsec->flags &= ~SE_SBLABELSUPP;
>>>>  
>>>>  	/* Special handling for sysfs. Is genfs but also has setxattr handler*/
>>>> -	if (strncmp(sb->s_type->name, "sysfs", sizeof("sysfs")) = 0)
>>>> +	if (strncmp(sb->s_type->name, "sysfs", sizeof("sysfs") - 1) = 0)
>>>>  		sbsec->flags |= SE_SBLABELSUPP;
>>>>         
>>> Shouldn't this be a simple strcmp() ?
>>>       
>> Yes I think so.
>>
>> Julia seems to be arguing that if a module introduces a new fs with
>> name 'sysfs_foo' then this check should match that fs too (since
>> for sysfs, sb->s_type->name = "sysfs" which also has a trailing \0,
>> so for the regular sysfs her patch makes no practical difference).
>>     
>
> If strcmp is what is wanted, I can make a patch for that.
>   

I strongly suggest that this is not what is wanted.
    strcmp(x,y)
and
    strncmp(x,y,sizeof(y))

are functionally equivalent and strcmp has a bad reputation in
the security community because it is associated with potential
buffer overrun issues.

    strncmp(x,y,sizeof(y)-1)

is not the same and is more cluttered as well. This code
does not need to be changed. It does what it is intended
to do in a strait-forward manner.
> julia
> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>   


WARNING: multiple messages have this Message-ID (diff)
From: Casey Schaufler <casey@schaufler-ca.com>
To: Julia Lawall <julia@diku.dk>
Cc: "Serge E. Hallyn" <serue@us.ibm.com>,
	James Morris <jmorris@namei.org>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	Eric Paris <eparis@parisplace.org>,
	linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 3/4] security/selinux: decrement sizeof size in strncmp
Date: Thu, 12 Nov 2009 08:21:52 -0800	[thread overview]
Message-ID: <4AFC3620.2020809@schaufler-ca.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0911121556390.19779@ask.diku.dk>

Julia Lawall wrote:
> On Thu, 12 Nov 2009, Serge E. Hallyn wrote:
>
>   
>> Quoting James Morris (jmorris@namei.org):
>>     
>>> On Thu, 12 Nov 2009, Julia Lawall wrote:
>>>
>>>       
>>>> From: Julia Lawall <julia@diku.dk>
>>>>
>>>> As observed by Joe Perches, sizeof of a constant string includes the
>>>> trailing 0.  If what is wanted is to check the initial characters of
>>>> another string, this trailing 0 should not be taken into account.  If an
>>>> exact match is wanted, strcmp should be used instead.
>>>>         
>>>> --- a/security/selinux/hooks.c
>>>> +++ b/security/selinux/hooks.c
>>>> @@ -448,7 +448,7 @@ static int sb_finish_set_opts(struct sup
>>>>  		sbsec->flags &= ~SE_SBLABELSUPP;
>>>>  
>>>>  	/* Special handling for sysfs. Is genfs but also has setxattr handler*/
>>>> -	if (strncmp(sb->s_type->name, "sysfs", sizeof("sysfs")) == 0)
>>>> +	if (strncmp(sb->s_type->name, "sysfs", sizeof("sysfs") - 1) == 0)
>>>>  		sbsec->flags |= SE_SBLABELSUPP;
>>>>         
>>> Shouldn't this be a simple strcmp() ?
>>>       
>> Yes I think so.
>>
>> Julia seems to be arguing that if a module introduces a new fs with
>> name 'sysfs_foo' then this check should match that fs too (since
>> for sysfs, sb->s_type->name = "sysfs" which also has a trailing \0,
>> so for the regular sysfs her patch makes no practical difference).
>>     
>
> If strcmp is what is wanted, I can make a patch for that.
>   

I strongly suggest that this is not what is wanted.
    strcmp(x,y)
and
    strncmp(x,y,sizeof(y))

are functionally equivalent and strcmp has a bad reputation in
the security community because it is associated with potential
buffer overrun issues.

    strncmp(x,y,sizeof(y)-1)

is not the same and is more cluttered as well. This code
does not need to be changed. It does what it is intended
to do in a strait-forward manner.
> julia
> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>   


  reply	other threads:[~2009-11-12 16:21 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-12  7:49 [PATCH 3/4] security/selinux: decrement sizeof size in strncmp Julia Lawall
2009-11-12  7:49 ` Julia Lawall
2009-11-12  8:16 ` James Morris
2009-11-12  8:16   ` James Morris
2009-11-12 14:53   ` Serge E. Hallyn
2009-11-12 14:53     ` Serge E. Hallyn
2009-11-12 14:57     ` Julia Lawall
2009-11-12 14:57       ` Julia Lawall
2009-11-12 16:21       ` Casey Schaufler [this message]
2009-11-12 16:21         ` Casey Schaufler
2009-11-12 18:28         ` David Wagner
2009-11-12 21:41         ` James Morris
2009-11-12 21:41           ` James Morris
2009-11-12 21:59           ` Julia Lawall
2009-11-12 21:59             ` Julia Lawall
2009-11-12 23:56             ` David Wagner
2009-11-13  2:11           ` Casey Schaufler
2009-11-13  2:11             ` Casey Schaufler
2009-11-13 20:32             ` David Wagner
2009-11-13 21:23             ` Valdis.Kletnieks
2009-11-13 21:23               ` Valdis.Kletnieks
2009-11-13 21:26               ` Julia Lawall
2009-11-13 21:26                 ` Julia Lawall
2009-11-13 23:08                 ` Valdis.Kletnieks
2009-11-13 23:08                   ` Valdis.Kletnieks
2009-11-14  0:41                   ` David Wagner
2009-11-14  5:08                     ` Valdis.Kletnieks
2009-11-14 15:22                   ` Julia Lawall
2009-11-14 15:22                     ` Julia Lawall
2009-11-13 23:06               ` David Wagner
2009-11-14  3:06               ` Casey Schaufler
2009-11-14  3:06                 ` Casey Schaufler
2009-11-14  3:44                 ` David Wagner
2009-11-14  3:48                   ` Joe Perches
2009-11-14  5:12                     ` Casey Schaufler
2009-11-14  5:26                       ` Joe Perches
2009-11-14  7:20                         ` Casey Schaufler
2009-11-15  7:45                           ` Raja R Harinath
2009-11-15 18:44                             ` Casey Schaufler

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=4AFC3620.2020809@schaufler-ca.com \
    --to=casey@schaufler-ca.com \
    --cc=eparis@parisplace.org \
    --cc=jmorris@namei.org \
    --cc=julia@diku.dk \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sds@tycho.nsa.gov \
    --cc=serue@us.ibm.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 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.