All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Moore <paul.moore@hp.com>
To: "Todd Miller" <Tmiller@tresys.com>
Cc: "James Antill" <james.antill@redhat.com>,
	"Stephen Smalley" <sds@tycho.nsa.gov>,
	selinux@tycho.nsa.gov
Subject: Re: [RFC PATCH] SELinux: Cleanup the secid/secctx conversion functions
Date: Fri, 29 Feb 2008 13:58:56 -0500	[thread overview]
Message-ID: <200802291358.57146.paul.moore@hp.com> (raw)
In-Reply-To: <6FE441CD9F0C0C479F2D88F959B015880195CD04@exchange.columbia.tresys.com>

On Friday 29 February 2008 1:41:54 pm Todd Miller wrote:
> Paul Moore wrote:
> > The strlcpy() implementation does a strlen() and a memcpy() call
> > along with two comparisons and some trivial math.  The strcat()
> > implementation does pretty much the same thing but with less
> > comparisons and no additional math.  The strcpy() implementation
> > only does a byte-by-byte copy which should be faster then strlcpy()
> > even when one factors in an optimized memcpy() implementation due
> > to the strlen() call.
>
> The difference is that with strcat() you are also finding the length
> of dest whereas which strlcpy() you only need to find the length of
> src.

True, strcat() does do a strlen() on dest while strlcpy() does a 
strlen() on src and in this case dest is almost always going to be 
bigger then src.

> I really doubt it makes a measurable difference and things may 
> be muddied by gcc inlining some of the standard str* functions.

Agree.

Also, (this starts getting into architecture specifics) on x86 (not 
x86_64) I'm pretty sure all function arguments are passed on the stack 
and strlcpy() requires three arguments versus strcat()/strcpy() which 
require only two.  However, at this point I think the argument is 
starting to get a bit ridiculous.

> However, you definately do not need the final strlen(ctx) in either
> case since you know that *scontext_len - 1 == strlen(ctx).

Disagree.  At the point in time of the final strlen(ctx) call ctx looks 
like this (note the lack of MLS range):

    user_u:role_r:type_t

... where as scontext_len is equal to the strlen() of the full context 
(MLS included).  The results of strlen(*scontext) and *scontext_len are 
not the same until after the call to mls_sid_to_context().

> I'm not sanctioning James' abuse of strlcpy(); I think it is
> pointless to try and guess which is faster without actually
> benchmarking it.

Yep ... slow news day and this discussion seems a lot safer then the 
current labeled NFS discussion ;)

-- 
paul moore
linux security @ hp

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

      reply	other threads:[~2008-02-29 18:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-28 21:41 [RFC PATCH] SELinux: Cleanup the secid/secctx conversion functions Paul Moore
2008-02-29  9:49 ` James Morris
2008-02-29 13:27   ` Paul Moore
2008-02-29 13:54 ` Stephen Smalley
2008-02-29 14:13   ` Stephen Smalley
2008-02-29 14:23     ` Paul Moore
2008-02-29 16:40     ` James Antill
2008-02-29 17:03       ` Paul Moore
2008-02-29 18:41         ` Todd Miller
2008-02-29 18:58           ` Paul Moore [this message]

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=200802291358.57146.paul.moore@hp.com \
    --to=paul.moore@hp.com \
    --cc=Tmiller@tresys.com \
    --cc=james.antill@redhat.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    /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.