From: James Antill <jantill@redhat.com>
To: Mark Goldman <mgoldman@tresys.com>
Cc: Karl MacMillan <kmacmillan@mentalrootkit.com>,
SE Linux <selinux@tycho.nsa.gov>
Subject: Re: [patch 1/3] libsemanage: genhomedircon replacement
Date: Thu, 24 May 2007 12:00:12 -0400 [thread overview]
Message-ID: <1180022412.24418.58.camel@code.and.org> (raw)
In-Reply-To: <1180015458.3930.173.camel@tresys-winxppro>
[-- Attachment #1: Type: text/plain, Size: 3037 bytes --]
On Thu, 2007-05-24 at 10:04 -0400, Mark Goldman wrote:
> <snip>
> > > +static int write_home_dir_context(FILE * out, list_t * tpl, char *user,
> > > + char *seuser, char *home, char *prefix)
> > > +{
> > > + char *temp;
> > > + char *line;
> > > +
> > > + fprintf(out, "\n\n#\n# Home Context for user %s\n#\n\n", user);
> > > + for (; tpl; tpl = tpl->next) {
> > > + temp = semanage_sed(tpl->data, "HOME_DIR", home);
> >
> > Wow - I understand that this string handling in C is painful, but is
> > this really the best alternative? Perhaps parsing the input to make the
> > substitution easier would be better? Perhaps we should look for some
> > library code to do this?
> I am not really sure what the problem with this is. We need to replace
> arbitrary substrings. I searched in the C libraries for something that
> might do what I want. I couldn't find anything, so I wrote a function
> to do it.
I feel your pain, doing anything non-trivial with strings in C is
always a major PITA.
As a personal project I've almost got ustr[1] in a 1.0 release, which I
hope could be used in the SELinux libraries (being able to easily
integrate it into libraries, is one of it's main points), and would
solve this problem and others in the SELinux libs. (like the strdup() +
a bit more data).
> As for parsing the input to make the substitution easier, I think it
> would be a lot more work to write or use a full fledged parser. What
> we want in this situation is what I wrote in my opinion, although I am
> open to suggestions.
Saying that, there were more than a few problems with semanage_sed()
even if you discount the genericness of the name:
1. You pre-allocate a bad amount of space:
+ srclen = strlen(src);
+ maxdest = 2 * srclen;
+ dest = malloc(maxdest);
...consider:
HOME_DIR -d system_u:object_r:user_home_dir_t:s0
strlen("HOME_DIR") == 8, *2 == 16
strlen("/home/kmacmillan") == 16
...I think, you really want something like:
+ maxdest = srclen + (replen - vallen) * 2 + 1;
2. You pre-reallocate if there isn't enough room to insert a new val,
even if it's not possible to insert a new val:
+ min_increment = (dindex + replen + 1) - maxdest;
+ if (min_increment >= 0) {
...consider:
HOME_DIR/.+ system_u:object_r:user_home_t:s0
strlen("HOME_DIR/.+") == 11, *2 == 22
strlen("/home/james") == 11
...now when you are at '.' in the above substitution, you'll have
dindex=11 and replen=11 which will trigger a realloc() even though you
only have 2 bytes left in src (so HOME_DIR will never match, obviously).
3. You should probably be calling strstr() instead of walking the
string.
4. All the sizes are signed int's, and no overflow/underflow checking is
done. This might be safe due to current usage, but it seems like a bad
idea to leave it this way in a core security lib.
[1] http://www.and.org/ustr/
--
James Antill <jantill@redhat.com>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2007-05-24 16:00 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-21 9:54 [patch 0/3] genhomedircon replacement in libsemanage jbrindle
2007-05-21 9:54 ` [patch 1/3] libsemanage: genhomedircon replacement jbrindle
2007-05-22 21:08 ` Karl MacMillan
2007-05-24 14:04 ` Mark Goldman
2007-05-24 14:45 ` Karl MacMillan
2007-05-24 15:44 ` Daniel J Walsh
2007-05-24 19:20 ` Mark Goldman
2007-05-25 15:52 ` Karl MacMillan
2007-05-25 17:06 ` Joshua Brindle
2007-05-26 0:02 ` Karl MacMillan
2007-05-29 20:25 ` audit2allow module generation Anand Patel
2007-05-29 21:11 ` Karl MacMillan
2007-05-30 14:44 ` Anand Patel
2007-05-31 16:05 ` Karl MacMillan
2007-06-08 15:36 ` Karl MacMillan
2007-06-11 13:47 ` Anand Patel
2007-08-30 13:43 ` Anand Patel
2007-09-03 16:13 ` Karl MacMillan
2007-09-10 14:10 ` Anand Patel
2007-09-10 16:01 ` Karl MacMillan
2007-06-19 15:09 ` [patch 1/3] libsemanage: genhomedircon replacement Joshua Brindle
2007-06-21 16:29 ` Karl MacMillan
2007-06-21 16:49 ` Joshua Brindle
2007-06-21 18:04 ` Karl MacMillan
2007-06-21 18:09 ` Joshua Brindle
2007-06-21 18:18 ` Karl MacMillan
2007-06-21 18:25 ` Joshua Brindle
2007-06-21 18:35 ` Karl MacMillan
2007-06-21 20:54 ` Eamon Walsh
2007-06-22 11:50 ` Daniel J Walsh
2007-06-22 15:22 ` Karl MacMillan
2007-06-22 15:31 ` Joshua Brindle
2007-06-22 16:04 ` Karl MacMillan
2007-06-22 16:58 ` Eamon Walsh
2007-06-22 19:30 ` Karl MacMillan
2007-06-22 20:55 ` Eamon Walsh
2007-07-02 14:00 ` Joshua Brindle
2007-07-02 14:23 ` Karl MacMillan
2007-07-02 15:54 ` Joshua Brindle
2007-07-02 21:26 ` Joshua Brindle
2007-07-03 1:12 ` James Antill
2007-07-03 11:15 ` Can someone please assist me with selinux issue David Cottle
[not found] ` <1183464455.12218.243.camel@moss-spartans.epoch.ncs! c.mil>
2007-07-03 12:07 ` Stephen Smalley
2007-07-04 23:30 ` David Cottle
2007-07-05 12:33 ` Stephen Smalley
2007-07-12 19:03 ` Libsemanage dependency on version of Linux Hasan Rezaul-CHR010
2007-07-12 19:39 ` Stephen Smalley
2007-07-12 19:48 ` Hasan Rezaul-CHR010
2007-07-12 19:57 ` Stephen Smalley
2007-07-12 19:49 ` Stephen Smalley
2007-07-02 14:54 ` [patch 1/3] libsemanage: genhomedircon replacement James Antill
2007-06-22 20:00 ` James Antill
2007-05-24 15:05 ` Steve G
2007-05-24 15:27 ` Karl MacMillan
2007-05-24 16:00 ` James Antill [this message]
2007-05-25 14:22 ` Mark Goldman
2007-05-21 9:54 ` [patch 2/3] libsemanage: test functions jbrindle
2007-05-21 9:54 ` [patch 3/3] Remove legacy genhomedircon python script jbrindle
2007-05-22 17:23 ` [patch 0/3] genhomedircon replacement in libsemanage Daniel J Walsh
2007-05-22 17:35 ` Joshua Brindle
2007-05-22 21:10 ` Karl MacMillan
2007-05-22 21:11 ` Karl MacMillan
-- strict thread matches above, loose matches on Subject: below --
2007-08-08 20:22 [patch 0/3] libsemanage: genhomedircon replacement tmiller
2007-08-08 20:22 ` [patch 1/3] " tmiller
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=1180022412.24418.58.camel@code.and.org \
--to=jantill@redhat.com \
--cc=kmacmillan@mentalrootkit.com \
--cc=mgoldman@tresys.com \
--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.