All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karl MacMillan <kmacmillan@mentalrootkit.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: SE Linux <selinux@tycho.nsa.gov>
Subject: Re: policyrep questions
Date: Wed, 09 May 2007 11:51:00 -0400	[thread overview]
Message-ID: <1178725860.19377.16.camel@localhost.localdomain> (raw)
In-Reply-To: <1178724555.16433.19.camel@moss-spartans.epoch.ncsc.mil>

On Wed, 2007-05-09 at 11:29 -0400, Stephen Smalley wrote:
> On Tue, 2007-05-08 at 18:29 -0400, Karl MacMillan wrote:
> > I have a few questions as I continue to do the policyrep patches.
> > 
> > 1) The free functions for the objects may need to return an error (which
> > I hate, but there is no good way to avoid this). This will break
> > compatibility with the existing string based sepol objects (like
> > sepol_bool). Any problems breaking this compatibility?
> 
> Not a problem (.so version has already changed in -policyrep and we have
> already made other incompatible changes).
> 
> OTOH, what could/would a caller do if a free function failed?

It's not clear - it will be _very_ hard to guarantee that the data
structures are in some sort of semi-valid state so that the free
function could be called again.

>   At that
> point, it will leak memory unless it aborts altogether, right?  So
> possibly we gain nothing from returning an error status to the caller?

Basically - the worst case is a leak. And bear in mind, this is a
failure case caused by the inability to allocate a couple of bytes.
Chances are we are about to hit many other unrecoverable errors.

To make this worse - there are several cases where I ignore failures in
free functions. In error paths that free an object I usually want to
return the original error and not the error on free - so I ignore the
return from the free functions.

> What do other libraries do under similar conditions?  Or do they avoid
> it through different data structure and API design?
> 

No idea. It is hard to fully encapsulate all structs and avoid this
issue I think. Even if I made it so that the library could internally
put all of the structs on the stack users of the library would be faced
with exactly the same set of issues.

I vote to suppress all of these free errors (which don't occur often -
most of these functions have error returns just for the consistency that
is needed for the object system).

> 
> > 4) We assume NULL-terminated strings all over the place - should we be
> > providing apis with length? Alternatively, should we provide a better
> > string object (since we are currently re-inventing the wheel, why not?).
> > We could pull in something like James Antills Vstr library -
> > http://www.and.org/vstr/ (read and be amazed at the diligence of James).
> > It just seems crazy that our apis are not the safest.
> 
> I'm not clear that tracking length separately is advantageous for these
> APIs.

It might be more efficient in many cases. Obviously we can't protect
against malicious callers, but forcing people to pass length makes them
aware of the issues I think.

>   What specific advantages would accrue to libsepol from using
> vstr?

We are going to start wanting to build up some complex strings as part
of the policyrep work. That kind of concatenation is painful with the C
string APIS (and inefficient). Vstr is also designed to be easy /
efficient to use to push strings across the network.

>   What is the cost (incl. dependencies)?
> 

I don't think there are any deps. It's not in fedora yet, but it will be
soon.

Karl


--
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:[~2007-05-09 15:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-08 22:29 policyrep questions Karl MacMillan
2007-05-09 14:13 ` Karl MacMillan
2007-05-09 15:30   ` Stephen Smalley
2007-05-09 15:29 ` Stephen Smalley
2007-05-09 15:51   ` Karl MacMillan [this message]
2007-05-09 16:34   ` James Antill

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=1178725860.19377.16.camel@localhost.localdomain \
    --to=kmacmillan@mentalrootkit.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.