platform_external_selinux/libsepol/src
Joshua Brindle e61b36a5c7 Author: Joshua Brindle
Email: method@manicmethod.com
Subject: BUGREPORT: A type alias of invisible primary one
Date: Mon, 22 Sep 2008 16:43:04 -0400

KaiGai Kohei wrote:
> Joshua Brindle wrote:
>> KaiGai Kohei wrote:
>>> I found a strange type_datum_t object which has 0 for its s.value
>>> during development of new type hierarchy checks.
>>>
>>> The strange one is "xguest_javaplugin_default_xproperty_t" which
>>> is an alias type of "xguest_javaplugin_xproperty_t".
>>>
>>> I doubted my patch at first, but it can be reproduced on the normal
>>> libsepol. It seems to me an original matter which is not exposed yet,
>>> and I am innocence. :-)
>>>
>>> During tracing the matter, I noticed the primary type is invisible
>>> at expand_module(), but the aliased one is visible. It can make the
>>> strange type_datum_t object.
>>>
>>> * at the expand_module()
>>> 1. The expand_state_t which includes typemap is initialized.
>>>
>>> 2. The type_copy_callback is invoked for any types via hashtab_map.
>>>    It only copies primary and visible types into newer hashtab,
>>>    and set up typemap to translate between old and new s.value.
>>>    Thus, the given primary type is invisible, its slot of typemap
>>>    is kept to zero.
>>>    (*) is_id_enabled() for "xguest_javaplugin_xproperty_t" returned false.
>>>
>>> 3. The alias_copy_callback is invoked for any types via hashtab_map.
>>>    It only copies alias and visible types into newer hashtab.
>>>    Here is no check whether the primary side is visible, or not.
>>>    A copied type_datum_t object for the given alias has new s.value
>>>    which is picked up from state->typemap.
>>>
>>> 4. However, the target slot of state->typemap was zero, because
>>>    its primary one is invisible. The aliased type has a strange
>>>    s.value.
>>>
>>> 5. Type hierarchy checks got a segmentation fault, due to
>>>    "p->type_val_to_name[datum->s.value - 1]".
>>>                         ^^^^^^^^^^^^^^^^^^ == -1
>>> Yes, we can identify cause of the matter.
>> Do you have a policy that can be used to reproduce this?
>
> Yes, the following policy can reproduce the matter.
> - - - - [ cut here ] - - - -
> policy_module(baz, 1.0)
>
> optional_policy(`
>         gen_require(`
>                 type invisible_primary_t;
>         ')
>         typealias invisible_primary_t alias visible_alias_t;
> ')
> - - - - - - - - - - - - - - -
>
> The attached patch can inject some of printf()'s.
> You can see that invisible_primary_t is skipped at type_copy_callback()
> and an incorrect s.value is assigned at alias_copy_callback().
>
> Thanks,
>

This should fix it. I tested with and without your patchset on a few policies. Let me know if it doesn't work for you:
2008-10-07 09:51:54 -04:00
..
assertion.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
av_permissions.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
avrule_block.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
avtab.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
boolean_internal.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
boolean_record.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
booleans.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
conditional.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
constraint.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
context.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
context.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
context_internal.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
context_record.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
debug.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
debug.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
dso.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
ebitmap.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
expand.c Author: Joshua Brindle 2008-10-07 09:51:54 -04:00
expand.c.rej Author: Joshua Brindle 2008-10-07 09:51:54 -04:00
genbools.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
genusers.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
handle.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
handle.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
hashtab.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
hierarchy.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
iface_internal.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
iface_record.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
interfaces.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
libsepol.map initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
link.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
Makefile initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
mls.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
mls.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
module.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
module_internal.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
node_internal.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
node_record.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
nodes.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
polcaps.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
policydb.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
policydb_convert.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
policydb_internal.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
policydb_public.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
port_internal.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
port_record.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
ports.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
private.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
roles.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
services.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
sidtab.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
symtab.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
user_internal.h initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
user_record.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
users.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
util.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00
write.c initial import from svn trunk revision 2950 2008-08-19 15:30:36 -04:00