All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Brindle <method@manicmethod.com>
To: Daniel J Walsh <dwalsh@redhat.com>
Cc: SE Linux <selinux@tycho.nsa.gov>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	KaiGai Kohei <kaigai@ak.jp.nec.com>
Subject: Re: This policy causes checkmodule to segfault.
Date: Sun, 16 Nov 2008 18:58:57 -0500	[thread overview]
Message-ID: <4920B3C1.4000405@manicmethod.com> (raw)
In-Reply-To: <491DE60C.3040205@redhat.com>

Daniel J Walsh wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> policy_module(test, 1.0)
>
> gen_require(`
>   type a_t;
> ')
> type b_t alias a_t;
>   

Well, this doesn't look good. There are a couple issues here. The first 
is that when we changed the symtab_insert behavior to allow require then 
declare we missed the alias case, the patch below should fix that. The 
second problem is that type_write now treats primary as a boolean value 
(as of the typebounds patch). A while back we made primary not 
necessarily a boolean in the module case where an alias had a value 
already and we needed to keep track of what the primary value was. The 
typebounds patch combined multiple fields into a 'properties' bitmap, 
which includes primary, so the value is now lost.

We can change the module format to keep the primary field around, this 
particular piece of code is getting increasingly more confusing though 
(write.c:970)

diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c
index 25b06c1..8c04767 100644
--- a/checkpolicy/policy_define.c
+++ b/checkpolicy/policy_define.c
@@ -983,6 +983,7 @@ static int add_aliases_to_type(type_datum_t * type)
        char *id;
        type_datum_t *aliasdatum = NULL;
        int ret;
+       uint32_t val;
        while ((id = queue_remove(id_queue))) {
                if (id_has_dot(id)) {
                        free(id);
@@ -1000,7 +1001,7 @@ static int add_aliases_to_type(type_datum_t * type)
                aliasdatum->s.value = type->s.value;
 
                ret = declare_symbol(SYM_TYPES, id, aliasdatum,
-                                    NULL, &aliasdatum->s.value);
+                                    &val, &aliasdatum->s.value);
                switch (ret) {
                case -3:{
                                yyerror("Out of memory!");
@@ -1017,6 +1018,17 @@ static int add_aliases_to_type(type_datum_t * type)
                        }
                case 0:
                case 1:{
+                              /* ret == 1 means the alias was required 
and therefore already
+                               * has a value. Set it up as an alias 
with a different primary. */
+                               type_datum_destroy(aliasdatum);
+                               free(aliasdatum);
+                              
+                               aliasdatum = 
hashtab_search(policydbp->symtab[SYM_TYPES].table, id);
+                               assert(aliasdatum);
+                               aliasdatum->primary = type->s.value;
+                               aliasdatum->flavor = TYPE_ALIAS;
+
+                               free(id);
                                break;
                        }
                default:{





--
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-11-16 23:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-14 20:56 This policy causes checkmodule to segfault Daniel J Walsh
2008-11-16 23:58 ` Joshua Brindle [this message]
2008-11-17  6:42   ` KaiGai Kohei

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=4920B3C1.4000405@manicmethod.com \
    --to=method@manicmethod.com \
    --cc=dwalsh@redhat.com \
    --cc=kaigai@ak.jp.nec.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.