mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valdis.Kletnieks@vt.edu
To: daw-news@taverner.cs.berkeley.edu (David Wagner)
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] security/selinux: decrement sizeof size in strncmp
Date: Sat, 14 Nov 2009 00:08:27 -0500	[thread overview]
Message-ID: <9337.1258175307@turing-police.cc.vt.edu> (raw)
In-Reply-To: Your message of "Sat, 14 Nov 2009 00:41:15 GMT." <hdkubb$rdb$1@taverner.cs.berkeley.edu>

[-- Attachment #1: Type: text/plain, Size: 1629 bytes --]

On Sat, 14 Nov 2009 00:41:15 GMT, David Wagner said:

> 1) The particular code snippets under discussion here were of the
> form
>     strncmp(foo, "constant", sizeof("constant"))
> And the proposal is to replace this code with
>     strcmp(foo, "constant")
> Do you really mean to object to this proposal?

No, in that particular case strcmp() is Obviously Safe.

> 2) More generally, you seem to be concerned about bugs where one
> piece of code fails to '\0'-terminate a string, and another piece of
> code invokes some library function that relies upon '\0'-termination.

Exactly.

> That is not specifically a strcmp() issue; this is an issue with using
> any string library that assumes '\0'-termination, where the string is not
> '\0'-terminated.  That's a much broader issue that should be addressed by
> other means.

I know that - which is why I asked Julia if Cocinelle is able to do anything
in this area.  An awful lot of our \0-terminated strings end up that way
implicitly because somebody does a kzalloc() or bzero() of an entire
structure, which can be fragile if code is refactored.

By the same token, that implicit behavior means that it's probably quite
difficult for any programmatic correctness checkers to follow the behavior.

>              Saying "strcmp() is bad" is a poor response to this risk.

I didn't say "strcmp() is bad". I said it needs auditing.  The strn-
versions of functions have a guaranteed termination condition right there
in the call. For strcmp() and strcpy(), the termination guarantee is
often elsewhere, which is why code using them tends to be brittle and
is harder to audit.


[-- Attachment #2: Type: application/pgp-signature, Size: 227 bytes --]

  reply	other threads:[~2009-11-14  5:08 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 [this message]
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: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=9337.1258175307@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=daw-news@taverner.cs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    /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®