From: Julia Lawall <julia@diku.dk>
To: Valdis.Kletnieks@vt.edu
Cc: Casey Schaufler <casey@schaufler-ca.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serue@us.ibm.com>,
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: Sat, 14 Nov 2009 16:22:44 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.64.0911141621480.3898@ask.diku.dk> (raw)
In-Reply-To: <24306.1258153693@turing-police.cc.vt.edu>
On Fri, 13 Nov 2009, Valdis.Kletnieks@vt.edu wrote:
> On Fri, 13 Nov 2009 22:26:20 +0100, Julia Lawall said:
> > On Fri, 13 Nov 2009, Valdis.Kletnieks@vt.edu wrote:
> > > Julia, is there a way to use coccinelle to detect unsafe changes like that? Or
> > > is expressing those semantics too difficult?
> >
> > Could you give a concrete example of something that would be a problem?
> > If something like alias analysis is required, to know what strings a
> > variable might be bound to, that might be difficult. Coccinelle works
> > better when there is some concrete codeto match against.
>
> Here's a concrete example of how a previously audited strcmp() can go bad...
>
> struct foo {
> char[16] a; /* old code allows 15 chars and 1 more for the \0 */
> int b;
> int c;
> }
>
> bzero(foo,sizeof(foo));
>
> Now code can pretty safely mess with the first 15 bytes of foo->a and
> we know we're OK if we call strcmp(foo->a,....) because that bzero()
> nuked a[15] for us. It's safe to strncpy(foo->a,bar,15); and not worry
> about the fact that if bar is 15 chars long, a trailing \0 won't be put in.
>
> Now somebody comes along and does:
>
> struct foo {
> char *a; /* we need more than 15 chars for some oddball hardware */
> int b;
> int c;
> }
>
> bzero(foo,sizeof(foo));
> foo->a = kmalloc(32); /* whoops should have been kzmalloc */
>
> Now suddenly, strncpy(foo->a,bar,31); *isn't* safe....
>
> (Yes, I know there's plenty of blame to go around in this example - the failure
> to use kzmalloc, the use of strncpy() without an explicit \0 being assigned
> someplace, the use of strcmp() rather than strncmp()... But our tendency to
> intentionally omit several steps of this to produce more efficient code means
> it's easier to shoot ourselves in the foot...)
Thanks for the example. Coccinelle only finds patterns of code in one
version, while this would require considering two versions at once. Such
a thing could be interesting though.
julia
next prev parent reply other threads:[~2009-11-14 15:22 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-12 7:49 Julia Lawall
2009-11-12 8:16 ` James Morris
2009-11-12 14:53 ` Serge E. Hallyn
2009-11-12 14:57 ` Julia Lawall
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:59 ` Julia Lawall
2009-11-12 23:56 ` David Wagner
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:26 ` Julia Lawall
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 [this message]
2009-11-13 23:06 ` David Wagner
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=Pine.LNX.4.64.0911141621480.3898@ask.diku.dk \
--to=julia@diku.dk \
--cc=Valdis.Kletnieks@vt.edu \
--cc=casey@schaufler-ca.com \
--cc=eparis@parisplace.org \
--cc=jmorris@namei.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®