From: Darrel Goeddel <dgoeddel@TrustedCS.com>
To: Karl MacMillan <kmacmillan@mentalrootkit.com>
Cc: "'SELinux List'" <SELinux@tycho.nsa.gov>,
Stephen Smalley <sds@tycho.nsa.gov>,
Eric Paris <eparis@redhat.com>,
Joshua Brindle <jbrindle@tresys.com>
Subject: Re: [PATCH 2/2] userland support for new range_transition statements
Date: Mon, 31 Jul 2006 13:54:00 -0500 [thread overview]
Message-ID: <44CE51C8.6080805@trustedcs.com> (raw)
In-Reply-To: <1154370592.26550.144.camel@localhost.localdomain>
Karl MacMillan wrote:
> On Fri, 2006-07-28 at 10:13 -0500, Darrel Goeddel wrote:
> <snip>
>
>>+typedef struct range_trans_rule {
>>+ type_set_t stypes;
>>+ type_set_t ttypes;
>>+ class_perm_node_t *classes; /* only class is used */
>
>
> Is class_perm_node_t the correct choice? What about an ebitmap for the
> classes? It is easier to manage and you don't end up wasting space for
> perms when they aren't used.
Using an ebitmap for classes does seem much nicer. I looked at the type transition
rules before writing this and the list of classes from the avtab rules stuck with
me. I'll make the change and see how it looks.
> <snip>
>
>>+static int expand_range_trans(expand_state_t *state, range_trans_rule_t *rules)
>>+{
>>+ unsigned int i, j;
>>+ range_trans_t *rt, *lrt, *cur_rt;
>>+ range_trans_rule_t *rule;
>>+ class_perm_node_t *cp;
>>+
>>+ ebitmap_t stypes, ttypes;
>>+ ebitmap_node_t *snode, *tnode;
>>+
>>+ /* start appending at the end of the current list */
>>+ for (lrt = state->out->range_tr; lrt && lrt->next; lrt = lrt->next)
>>+ ;
>>+
>>+ for (rule = rules; rule; rule = rule->next) {
>>+ ebitmap_init(&stypes);
>>+ ebitmap_init(&ttypes);
>>+
>>+ /* expand the type sets */
>>+ if (expand_convert_type_set(state->out, state->typemap,
>>+ &rule->stypes, &stypes, 1)) {
>>+ ERR(state->handle, "Out of memory!");
>>+ return -1;
>>+ }
>>+ if (expand_convert_type_set(state->out, state->typemap,
>>+ &rule->ttypes, &ttypes, 1)) {
>>+ ERR(state->handle, "Out of memory!");
>>+ return -1;
>>+ }
>>+
>>+ /* loop on source type */
>>+ ebitmap_for_each_bit(&stypes, snode, i) {
>>+ if (!ebitmap_node_get_bit(snode, i))
>>+ continue;
>>+ /* loop on target type */
>>+ ebitmap_for_each_bit(&ttypes, tnode, j) {
>>+ if (!ebitmap_node_get_bit(tnode, j))
>>+ continue;
>>+ /* loop on target class */
>>+ for (cp = rule->classes; cp; cp = cp->next) {
>>+
>>+ /* check for duplicates/conflicts */
>>+ for (cur_rt = state->out->range_tr; cur_rt; cur_rt = cur_rt->next) {
>>+ if ((cur_rt->source_type == i + 1) &&
>>+ (cur_rt->target_type == j + 1) &&
>>+ (cur_rt->target_class == cp->class)) {
>>+ if (mls_range_eq(&cur_rt->target_range, &rule->trange)) {
>>+ /* duplicate */
>>+ break;
>>+ } else {
>>+ /* conflict */
>>+ ERR(state->handle,
>>+ "Conflicting range trans rule %s %s : %s",
>>+ state->out->p_type_val_to_name[i],
>>+ state->out->p_type_val_to_name[j],
>>+ state->out->p_class_val_to_name[cp->class]);
>>+ return -1;
>>+ }
>>+ }
>>+ }
>>+ if (cur_rt) /* this is a dup - skip */
>>+ continue;
>>+
>>+ rt = (range_trans_t *)malloc(sizeof(range_trans_t));
>>+ if (!rt) {
>>+ ERR(state->handle, "Out of memory!");
>>+ return -1;
>>+ }
>>+ memset(rt, 0, sizeof(range_trans_t));
>>+ rt->source_type = i + 1;
>>+ rt->target_type = j + 1;
>>+ rt->target_class = cp->class;
>>+ if (mls_range_cpy(&rt->target_range, &rule->trange)) {
>>+ ERR(state->handle, "Out of memory!");
>>+ return -1;
>>+ }
>>+ if (lrt) {
>>+ lrt->next = rt;
>>+ } else {
>>+ state->out->range_tr = rt;
>>+ }
>>+ lrt = rt;
>>+ }
>>+ }
>>+ }
>>+
>>+ ebitmap_destroy(&stypes);
>>+ ebitmap_destroy(&ttypes);
>>+ }
>>+
>>+ return 0;
>>+}
>>+
>
>
> Splitting this into some helper functions would make it more readable.
Yeah. I tried some breakups before but I really didn't find much that helped.
I'll try again. I still code at the console sometimes and I hate yelling at
myself for things like this ;)
> <snip>
>
>>Index: libsepol/src/write.c
>>===================================================================
>>--- libsepol/src/write.c (revision 38)
>>+++ libsepol/src/write.c (working copy)
>>@@ -39,6 +39,7 @@
>> #include <sepol/policydb/policydb.h>
>> #include <sepol/policydb/conditional.h>
>> #include <sepol/policydb/expand.h>
>>+#include <sepol/policydb/flask.h>
>>
>> #include "debug.h"
>> #include "private.h"
>>@@ -1124,21 +1125,36 @@
>> {
>> size_t nel, items;
>> struct range_trans *rt;
>>- uint32_t buf[32];
>>+ uint32_t buf[2];
>>+ int new_rangetr = (p->policy_type == POLICY_KERN &&
>>+ p->policyvers >= POLICYDB_VERSION_RANGETRANS);
>> nel = 0;
>>- for (rt = p->range_tr; rt; rt = rt->next)
>>- nel++;
>>+ for (rt = p->range_tr; rt; rt = rt->next) {
>>+ /* all range_transitions are written for the new format, only
>>+ process related range_transitions are written for the old
>>+ format, so count accordingly */
>>+ if (new_rangetr || rt->target_class == SECCLASS_PROCESS)
>>+ nel++;
>>+ }
>
>
> So there is no warning or indication that rules are being dropped? At
> some point it would be nice to let the user know that they are compiling
> a policy aimed at the new format but outputting an older policy.
Correct. I think you inadvertently pointed out some tests I forgot to run -
I have not compiled/tested monolithic policies with this patchset. I am
assuming that you can still specify an older output format when compiling
monolithically unlike the modular case where it always writes the newest
formats. There we would be able to print out a warning about unsupported
bits being discarded. The case I have tested with this code path is
libselinux downgrading a version 21 policy to version 20 for use in an older
kernel. In that case, I really don't see an appropriate feedback mechanism.
Any thoughts on that case? Warn about policy downgrades in some manner?
> Overall this looks good - again, thanks for taking the time to make it
> more complete. Seems like once we can require MLS symbols in modules it
> won't be too difficult to get range trans working with this change.
Cool. Thanks for taking at look at that.
> Karl
--
Darrel
--
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.
next prev parent reply other threads:[~2006-07-31 18:54 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-28 15:13 [PATCH 2/2] userland support for new range_transition statements Darrel Goeddel
2006-07-31 16:40 ` Stephen Smalley
2006-07-31 18:25 ` Darrel Goeddel
2006-07-31 18:29 ` Karl MacMillan
2006-07-31 18:54 ` Darrel Goeddel [this message]
2006-07-31 20:52 ` Stephen Smalley
2006-08-01 13:14 ` Joshua Brindle
2006-08-02 16:38 ` Darrel Goeddel
2006-08-02 19:51 ` Karl MacMillan
2006-08-02 21:59 ` Darrel Goeddel
2006-08-03 12:01 ` Joshua Brindle
2006-08-03 15:55 ` Joshua Brindle
2006-08-04 16:13 ` Darrel Goeddel
2006-08-07 13:18 ` Joshua Brindle
2006-08-08 14:48 ` Darrel Goeddel
2006-08-08 22:45 ` Joshua Brindle
2006-08-09 15:00 ` Darrel Goeddel
2006-08-04 17:10 ` [PATCH 2/2 take 2] " Darrel Goeddel
2006-08-08 22:25 ` Joshua Brindle
2006-08-09 13:09 ` Karl MacMillan
2006-08-09 13:31 ` Joshua Brindle
2006-08-09 15:06 ` Darrel Goeddel
2006-08-09 15:13 ` Karl MacMillan
2006-08-09 15:39 ` [PATCH 2/2 take 2] userland support for new range_transitionstatements Joshua Brindle
2006-08-09 14:29 ` [PATCH 2/2 take 2] userland support for new range_transition statements Darrel Goeddel
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=44CE51C8.6080805@trustedcs.com \
--to=dgoeddel@trustedcs.com \
--cc=SELinux@tycho.nsa.gov \
--cc=eparis@redhat.com \
--cc=jbrindle@tresys.com \
--cc=kmacmillan@mentalrootkit.com \
--cc=sds@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.