Skip to contentSkip to conversation

Segfault on duplicate require of sensitivity

BUG B Topscher 5 participants 9 messages Apr 19, 2007 – May 31, 2007 SELinux security module

lore
Share & tools
lore

B Topscher

author
#0 lore raw

When I have sensitivity required in two different locations I get segmentation faults when I try and load the module. For example, because s0 and s15 are already declared on other files if I require them in the TE file I get a segfault. I looked in the module.tmp file that was created on build and saw that s0 and s15 are declared somewhere. However, if I comment out my require in the TE file it loads the module fine.

if in the TE I have:

require {
     sensitivity s0;
}

function( domain_t )

and the IF I have

interface(function',

             gen_require(`
                         sensitivity s0;
                         ')
             .......

')

When I build and then semodule -i module.pp, I get a segfault when committing changes (according to semodule -v).

Thank you
Bryan

#1 lore raw

It turns out that level_datum_t is not defined as an actual datum:

/* Sensitivity attributes */
typedef struct level_datum {
mls_level_t *level; /* sensitivity and associated categories
*/
unsigned char isalias; /* is this sensitivity an alias for
another? */

        unsigned char defined;
} level_datum_t;

All *_datum_t should have the form:

typedef struct *_datum {
        symtab_datum_t s;
        *
} *_datum_t;

This assumption causes problems in module_compiler.c:require_symbol when the symbol is a duplicate (retval == 1 means duplicate symbol):

int require_symbol(uint32_t symbol_type,
hashtab_key_t key, hashtab_datum_t datum, uint32_t * dest_value, uint32_t * datum_value)
{

<snip>

        if (retval == 1) {
                symtab_datum_t *s =
                    (symtab_datum_t *) hashtab_search(policydbp->

symtab[symbol_type].table,

                                                      key);
                assert(s != NULL);
                *dest_value = s->value;
        } else if (retval == -2) {

<snip>

}

Which results in *dest_value being the address of level_datum->level and not the value of the sens (which would be level_datum->level->sens. See module_compiler.c:require_sens for more context.

The options I see here are not good. One option: the level_datum_t should be changed into a conforming *_datum_t and the fallout of this change handled in the rest of the code which expects to see a level_datum_t->level. Second option: level_datum_t is treated specially in require_symbol (using the symbol_type as the switch).

Quoted 31 lines · B Topscher

When I have sensitivity required in two different locations I get segmentation faults when I try and load the module. For example, because s0 and s15 are already declared on other files if I require them in the TE file I get a segfault. I looked in the module.tmp file that was created on build and saw that s0 and s15 are declared somewhere. However, if I comment out my require in the TE file it loads the module fine.

if in the TE I have:

require { 
      sensitivity s0;
}

function( domain_t )

and the IF I have

interface(function',

              gen_require(`
                          sensitivity s0;
                          ') 
              .......

')

When I build and then semodule -i module.pp, I get a segfault when committing changes (according to semodule -v).

Thank you
Bryan

Signature · 8 lines
Caleb Case
Tresys Technology
410-290-1411 x144

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
Quoted 2 lines · Caleb Case

It turns out that level_datum_t is not defined as an actual datum:

[...]

Quoted 7 lines

The options I see here are not good. One option: the level_datum_t should be changed into a conforming *_datum_t and the fallout of this change handled in the rest of the code which expects to see a level_datum_t->level. Second option: level_datum_t is treated specially in require_symbol (using the symbol_type as the switch).

Making it a _datum_t seems to be the right choice - what is your concern about following that path?

Karl

Quoted 27 lines · B Topscher
Quoted 26 lines

When I have sensitivity required in two different locations I get segmentation faults when I try and load the module. For example, because s0 and s15 are already declared on other files if I require them in the TE file I get a segfault. I looked in the module.tmp file that was created on build and saw that s0 and s15 are declared somewhere. However, if I comment out my require in the TE file it loads the module fine.

if in the TE I have:

require { 
      sensitivity s0;
}

function( domain_t )

and the IF I have

interface(function',

              gen_require(`
                          sensitivity s0;
                          ') 
              .......

')

Quoted 5 lines
Quoted 5 lines

When I build and then semodule -i module.pp, I get a segfault when committing changes (according to semodule -v).

Thank you
Bryan

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
Quoted 14 lines · Karl MacMillan
Quoted 2 lines · Caleb Case

It turns out that level_datum_t is not defined as an actual datum:

[...]

Quoted 7 lines

The options I see here are not good. One option: the level_datum_t should be changed into a conforming *_datum_t and the fallout of this change handled in the rest of the code which expects to see a level_datum_t->level. Second option: level_datum_t is treated specially in require_symbol (using the symbol_type as the switch).

Quoted 4 lines

Making it a _datum_t seems to be the right choice - what is your concern about following that path?

Karl

Mainly I am concerned because level_datum_t is exported in libsepol's protected headers and will require changes to anything that statically links to libsepol.

Quoted 34 lines
Quoted 33 lines · B Topscher
Quoted 31 lines

When I have sensitivity required in two different locations I get segmentation faults when I try and load the module. For example, because s0 and s15 are already declared on other files if I require them in the TE file I get a segfault. I looked in the module.tmp file that was created on build and saw that s0 and s15 are declared somewhere. However, if I comment out my require in the TE file it loads the module fine.

if in the TE I have:

require { 
      sensitivity s0;
}

function( domain_t )

and the IF I have

interface(function',

              gen_require(`
                          sensitivity s0;
                          ') 
              .......

')

When I build and then semodule -i module.pp, I get a segfault when committing changes (according to semodule -v).

Thank you
Bryan

Signature · 8 lines
Caleb Case
Tresys Technology
410-290-1411 x144

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw
Quoted 20 lines · Caleb Case
Quoted 18 lines · Karl MacMillan
Quoted 3 lines · Caleb Case

It turns out that level_datum_t is not defined as an actual datum:

[...]

Quoted 7 lines

The options I see here are not good. One option: the level_datum_t should be changed into a conforming *_datum_t and the fallout of this change handled in the rest of the code which expects to see a level_datum_t->level. Second option: level_datum_t is treated specially in require_symbol (using the symbol_type as the switch).

Making it a _datum_t seems to be the right choice - what is your concern about following that path?

Quoted 8 lines
Quoted 2 lines

Karl

Mainly I am concerned because level_datum_t is exported in libsepol's protected headers and will require changes to anything that statically links to libsepol.

Err, I don't think this is the main issue. The level datum references the sens_datum, which exists independantly of the level_datum. I think it would cause all sorts of problems to try to change that in the current code base.

Another option is to just punt on this and it should be handled naturally in the policyrep branch.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw
Quoted 29 lines · Joshua Brindle
Quoted 20 lines · Caleb Case
Quoted 18 lines · Karl MacMillan
Quoted 3 lines · Caleb Case

It turns out that level_datum_t is not defined as an actual datum:

[...]

Quoted 7 lines

The options I see here are not good. One option: the level_datum_t should be changed into a conforming *_datum_t and the fallout of this change handled in the rest of the code which expects to see a level_datum_t->level. Second option: level_datum_t is treated specially in require_symbol (using the symbol_type as the switch).

Making it a _datum_t seems to be the right choice - what is your concern about following that path?

Quoted 8 lines
Quoted 2 lines

Karl

Mainly I am concerned because level_datum_t is exported in libsepol's protected headers and will require changes to anything that statically links to libsepol.

Quoted 5 lines

Err, I don't think this is the main issue. The level datum references the sens_datum, which exists independantly of the level_datum. I think it would cause all sorts of problems to try to change that in the current code base.

What kind of problems?

Quoted 2 lines

Another option is to just punt on this and it should be handled naturally in the policyrep branch.

We can't punt on a reproducible segfault - it needs to be fixed in stable.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#6 lore raw
Quoted 38 lines · Karl MacMillan
Quoted 36 lines · Joshua Brindle
Quoted 34 lines · Caleb Case
Quoted 19 lines · Karl MacMillan
Quoted 4 lines · Caleb Case

It turns out that level_datum_t is not defined as an actual datum:

[...]

Quoted 8 lines

The options I see here are not good. One option: the level_datum_t should be changed into a conforming *_datum_t and the fallout of this change handled in the rest of the code which expects to see a level_datum_t->level. Second option: level_datum_t is treated specially in require_symbol (using the symbol_type as the switch).

Quoted 6 lines

Making it a _datum_t seems to be the right choice - what is your concern about following that path?

Karl

Mainly I am concerned because level_datum_t is exported in libsepol's protected headers and will require changes to anything that statically links to libsepol.

Quoted 7 lines
Quoted 3 lines

Err, I don't think this is the main issue. The level datum references the sens_datum, which exists independantly of the level_datum. I think it would cause all sorts of problems to try to change that in the current code base.

What kind of problems?

What do we put in the symtab_datum? Do we reproduce what is in the sens_datum? They aren't the same data, I'm not totally sure why they are separated (Darrell, want to chime in on this?). The really crappy thing is that we decided to support mls in require statements by just using the whole string (eg., s0:c0.c126-s15:c0.c128) so that whole string gets a level datum (iirc). I guess we can try adding a symtab_datum and see what the fallout is but I think there are alot of assumptions about how level_datum and sens_datum relate.

Quoted 6 lines
Quoted 2 lines

Another option is to just punt on this and it should be handled naturally in the policyrep branch.

We can't punt on a reproducible segfault - it needs to be fixed in stable.

I know, I was half joking...

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#7 lore raw
In reply to Joshua Brindle
Quoted 29 lines · Joshua Brindle
Quoted 20 lines · Caleb Case
Quoted 18 lines · Karl MacMillan
Quoted 3 lines · Caleb Case

It turns out that level_datum_t is not defined as an actual datum:

[...]

Quoted 7 lines

The options I see here are not good. One option: the level_datum_t should be changed into a conforming *_datum_t and the fallout of this change handled in the rest of the code which expects to see a level_datum_t->level. Second option: level_datum_t is treated specially in require_symbol (using the symbol_type as the switch).

Making it a _datum_t seems to be the right choice - what is your concern about following that path?

Quoted 8 lines
Quoted 2 lines

Karl

Mainly I am concerned because level_datum_t is exported in libsepol's protected headers and will require changes to anything that statically links to libsepol.

Quoted 7 lines

Err, I don't think this is the main issue. The level datum references the sens_datum, which exists independantly of the level_datum. I think it would cause all sorts of problems to try to change that in the current code base.

Another option is to just punt on this and it should be handled naturally in the policyrep branch.

This is option 2: special case the level_datum_t handling.

module_compiler.c +12 -2
Index: checkpolicy/module_compiler.c
===================================================================
@@ -142,7 +142,12 @@
 						      symtab[symbol_type].table,
 						      key);
 		assert(s != NULL);
-		*dest_value = s->value;
+		
+		if (symbol_type == SYM_LEVELS) {
+			*dest_value = ((level_datum_t *)s)->level->sens;
+		} else {
+			*dest_value = s->value;
+		}
 	} else if (retval == -2) {
 		return -2;
 	} else if (retval < 0) {
@@ -496,7 +501,12 @@
 						      symtab[symbol_type].table,
 						      key);
 		assert(s != NULL);
-		*dest_value = s->value;
+		
+		if (symbol_type == SYM_LEVELS) {
+			*dest_value = ((level_datum_t *)s)->level->sens;
+		} else {
+			*dest_value = s->value;
+		}
 	} else if (retval == -2) {
 		/* ignore require statements if that symbol was
 		 * previously declared and is in current scope */
Signature · 8 lines
Caleb Case
Tresys Technology
410-290-1411 x144

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#8 lore raw
Quoted 62 lines · Caleb Case
Quoted 29 lines · Joshua Brindle
Quoted 20 lines · Caleb Case
Quoted 18 lines · Karl MacMillan
Quoted 3 lines · Caleb Case

It turns out that level_datum_t is not defined as an actual datum:

[...]

Quoted 7 lines

The options I see here are not good. One option: the level_datum_t should be changed into a conforming *_datum_t and the fallout of this change handled in the rest of the code which expects to see a level_datum_t->level. Second option: level_datum_t is treated specially in require_symbol (using the symbol_type as the switch).

Making it a _datum_t seems to be the right choice - what is your concern about following that path?

Quoted 8 lines
Quoted 2 lines

Karl

Mainly I am concerned because level_datum_t is exported in libsepol's protected headers and will require changes to anything that statically links to libsepol.

Quoted 7 lines

Err, I don't think this is the main issue. The level datum references the sens_datum, which exists independantly of the level_datum. I think it would cause all sorts of problems to try to change that in the current code base.

Another option is to just punt on this and it should be handled naturally in the policyrep branch.

This is option 2: special case the level_datum_t handling.

Index: checkpolicy/module_compiler.c
===================================================================

module_compiler.c +6 -1
@@ -142,7 +142,12 @@
 						      symtab[symbol_type].table,
 						      key);
 		assert(s != NULL);
-		*dest_value = s->value;
+		
+		if (symbol_type == SYM_LEVELS) {
+			*dest_value = ((level_datum_t *)s)->level->sens;
+		} else {
+			*dest_value = s->value;
+		}
 	} else if (retval == -2) {
 		return -2;
 	} else if (retval < 0) {
@@ -496,7 +501,12 @@
 						      symtab[symbol_type].table,
 						      key);
 		assert(s != NULL);

module_compiler.c line 512

Quoted 10 lines
module_compiler.c +6 -1
-		*dest_value = s->value;
+		
+		if (symbol_type == SYM_LEVELS) {
+			*dest_value = ((level_datum_t *)s)->level->sens;
+		} else {
+			*dest_value = s->value;
+		}
 	} else if (retval == -2) {
 		/* ignore require statements if that symbol was
 		 * previously declared and is in current scope */

I'm merging this patch, but it occurs to me that this doesn't fully solve the bug - it ensures that checkmodule will generate a well-formed module, but it is still the case that an ill-formed module can cause a segfault in libsepol at module link time, right? We should be properly checking those values during module link in libsepol too.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.