Skip to contentSkip to conversation

Fix the range_transition rule

PATCH In review Paul Moore 3 participants 4 messages Aug 5, 2005 – Aug 8, 2005 SELinux security module

lore
Share & tools
lore

Paul Moore

author
#0 lore raw

PATCH 1/1 Fix the range_transition rule

Below is a patch to libsepol/src/expand.c to fix a problem with MLS range transitions. The problem is that the function expand_module() reassigns numeric values for the types when copying them and the routine used to copy the range transitions, range_trans_clone(), simply copied the old type values leading to bad values in the resulting policy file.

This fix uses the old type value to look up the type name in the old symbol table and then uses the type name to lookup the new type value.

src/expand.c 2005-08-05 16:14:18.000000000 -0400 renamed from src/expand.c.orig 2005-08-05 15:33:26.000000000 -0400 +12 -2
@@ -1349,11 +1349,21 @@ static int range_trans_clone(expand_stat
 
         while (range != NULL) {
                 range_trans_t *new_range;
+                type_datum_t *type;
+                char *type_name;
+
                 if ((new_range = malloc(sizeof(*new_range))) == NULL) {
                         goto out_of_mem;
                 }
-                new_range->dom = range->dom;
-                new_range->type = range->type;
+
+                /* convert the range_transition domain and type */
+                type_name = state->base->p_type_val_to_name[range->dom - 1];
+                type = hashtab_search(state->out->p_types.table, type_name);
+                new_range->dom = type->value;
+                type_name = state->base->p_type_val_to_name[range->type - 1];
+                type = hashtab_search(state->out->p_types.table, type_name);
+                new_range->type = type->value;
+
                 if (mls_level_clone(&new_range->range.level[0], 

&range->range.level[0]) == -1 ||

                     mls_level_clone(&new_range->range.level[1], 
&range->range.level[1])) {
                         goto out_of_mem;
Signature · 8 lines
. paul moore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. [email protected]                                      hewlett packard
. (603) 884-5056                                          linux security

--
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.
#1 lore raw
Quoted 34 lines · Paul Moore

Below is a patch to libsepol/src/expand.c to fix a problem with MLS range transitions. The problem is that the function expand_module() reassigns numeric values for the types when copying them and the routine used to copy the range transitions, range_trans_clone(), simply copied the old type values leading to bad values in the resulting policy file.

This fix uses the old type value to look up the type name in the old symbol table and then uses the type name to lookup the new type value.

--- libsepol-1.7.9/src/expand.c.orig 2005-08-05 15:33:26.000000000
-0400
+++ libsepol-1.7.9/src/expand.c 2005-08-05 16:14:18.000000000 -0400

src/expand.c 2005-08-05 16:14:18.000000000 -0400 renamed from src/expand.c.orig 2005-08-05 15:33:26.000000000 -0400 +10 -2
@@ -1349,11 +1349,21 @@ static int range_trans_clone(expand_stat
 
         while (range != NULL) {
                 range_trans_t *new_range;
+                type_datum_t *type;
+                char *type_name;
+
                 if ((new_range = malloc(sizeof(*new_range))) == NULL) {
                         goto out_of_mem;
                 }
-                new_range->dom = range->dom;
-                new_range->type = range->type;
+
+                /* convert the range_transition domain and type */
+                type_name = 
 state->base->p_type_val_to_name[range->dom - 1];
+                type = hashtab_search(state->out->p_types.table, 
 type_name);
+                new_range->dom = type->value;
+                type_name = 
 state->base->p_type_val_to_name[range->type - 1];
+                type = hashtab_search(state->out->p_types.table, 

type_name);

src/expand.c 2005-08-05 16:14:18.000000000 -0400 renamed from src/expand.c.orig 2005-08-05 15:33:26.000000000 -0400 +2 -0
+                new_range->type = type->value;
+
                 if (mls_level_clone(&new_range->range.level[0], 

&range->range.level[0]) == -1 ||

Quoted 3 lines
                     mls_level_clone(&new_range->range.level[1], 
&range->range.level[1])) {
                         goto out_of_mem;

Thanks, however this should probably be using the typemap that already does this sort of thing. something like new_range->type = state->typemap[type->value - 1] should work correctly.

--
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 4 lines · Joshua Brindle

Thanks, however this should probably be using the typemap that already does this sort of thing.
something like new_range->type = state->typemap[type->value - 1] should work correctly.

How about this patch?

Index: libsepol/src/expand.c
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libsepol/src/expand.c,v retrieving revision 1.2

src/expand.c +2 -2
diff -u -p -r1.2 expand.c
@@ -1352,8 +1352,8 @@ static int range_trans_clone(expand_stat
                 if ((new_range = malloc(sizeof(*new_range))) == NULL) {
                         goto out_of_mem;
                 }
-                new_range->dom = range->dom;
-                new_range->type = range->type;
+                new_range->dom = state->typemap[range->dom-1];
+                new_range->type = state->typemap[range->type-1];
                 if (mls_level_clone(&new_range->range.level[0], &range->range.level[0]) == -1 ||
                     mls_level_clone(&new_range->range.level[1], &range->range.level[1])) {
                         goto out_of_mem;
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.
#3 lore raw
Quoted 21 lines · Stephen Smalley
Quoted 4 lines · Joshua Brindle

Thanks, however this should probably be using the typemap that already does this sort of thing. something like new_range->type = state->typemap[type->value - 1] should work correctly.

How about this patch?

Index: libsepol/src/expand.c
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libsepol/src/expand.c,v retrieving revision 1.2
diff -u -p -r1.2 expand.c

src/expand.c static int range_trans_clone(expand_stat · line 1359

Quoted 10 lines
src/expand.c +2 -2
@@ -1352,8 +1352,8 @@ static int range_trans_clone(expand_stat
                if ((new_range = malloc(sizeof(*new_range))) == NULL) {
                        goto out_of_mem;
                }
-                new_range->dom = range->dom;
-                new_range->type = range->type;
+                new_range->dom = state->typemap[range->dom-1];
+                new_range->type = state->typemap[range->type-1];
                if (mls_level_clone(&new_range->range.level[0], &range->range.level[0]) == -1 ||
                    mls_level_clone(&new_range->range.level[1], &range->range.level[1])) {
                        goto out_of_mem;

That looks correct.

--
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.