Skip to contentSkip to conversation

libsepol: Properly handle types associated to role attributes

PATCH In review James Carter 2 participants 3 messages Mar 9, 2021 – Mar 15, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Properly handle types associated to role attributes

Types associated to role attributes in optional blocks are not associated with the roles that have that attribute. The problem is that role_fix_callback is called before the avrule_decls are walked.

Example/
class CLASS1
sid kernel
class CLASS1 { PERM1 }
type TYPE1;
type TYPE1A;
allow TYPE1 self : CLASS1 PERM1;
attribute_role ROLE_ATTR1A;
role ROLE1;
role ROLE1A;
roleattribute ROLE1A ROLE_ATTR1A;
role ROLE1 types TYPE1;

  optional {
    require {
      class CLASS1 PERM1;
    }
    role ROLE_ATTR1A types TYPE1A;

}
user USER1 roles ROLE1;
sid kernel USER1:ROLE1:TYPE1

In this example ROLE1A will not have TYPE1A associated to it.

Call role_fix_callback() after the avrule_decls are walked.

---
 libsepol/src/expand.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
libsepol/src/expand.c +5 -4
index eac7e450..1ee3e48f 100644
@@ -3017,10 +3017,6 @@ int expand_module(sepol_handle_t * handle,
 	if (hashtab_map(state.base->p_roles.table,
 			role_bounds_copy_callback, &state))
 		goto cleanup;
-	/* escalate the type_set_t in a role attribute to all regular roles
-	 * that belongs to it. */
-	if (hashtab_map(state.base->p_roles.table, role_fix_callback, &state))
-		goto cleanup;
 
 	/* copy MLS's sensitivity level and categories - this needs to be done
 	 * before expanding users (they need to be indexed too) */
@@ -3086,6 +3082,11 @@ int expand_module(sepol_handle_t * handle,
 		goto cleanup;
 	}
 
+	/* escalate the type_set_t in a role attribute to all regular roles
+	 * that belongs to it. */
+	if (hashtab_map(state.base->p_roles.table, role_fix_callback, &state))
+		goto cleanup;
+
 	if (copy_and_expand_avrule_block(&state) < 0) {
 		ERR(handle, "Error during expand");
 		goto cleanup;
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 27 lines · James Carter

Types associated to role attributes in optional blocks are not associated with the roles that have that attribute. The problem is that role_fix_callback is called before the avrule_decls are walked.

Example/
class CLASS1
sid kernel
class CLASS1 { PERM1 }
type TYPE1;
type TYPE1A;
allow TYPE1 self : CLASS1 PERM1;
attribute_role ROLE_ATTR1A;
role ROLE1;
role ROLE1A;
roleattribute ROLE1A ROLE_ATTR1A;
role ROLE1 types TYPE1;

  optional {
    require {
      class CLASS1 PERM1;
    }
    role ROLE_ATTR1A types TYPE1A;

}
user USER1 roles ROLE1;
sid kernel USER1:ROLE1:TYPE1

Quoted 5 lines

In this example ROLE1A will not have TYPE1A associated to it.

Call role_fix_callback() after the avrule_decls are walked.

Thanks!
Nicolas

Quoted 34 lines
---
 libsepol/src/expand.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
libsepol/src/expand.c +5 -5
index eac7e450..1ee3e48f 100644
@@ -3017,10 +3017,6 @@ int expand_module(sepol_handle_t * handle,
        if (hashtab_map(state.base->p_roles.table,
                        role_bounds_copy_callback, &state))
                goto cleanup;
-       /* escalate the type_set_t in a role attribute to all regular roles
-        * that belongs to it. */
-       if (hashtab_map(state.base->p_roles.table, role_fix_callback, &state))
-               goto cleanup;
 
        /* copy MLS's sensitivity level and categories - this needs to be done
         * before expanding users (they need to be indexed too) */
@@ -3086,6 +3082,11 @@ int expand_module(sepol_handle_t * handle,
                goto cleanup;
        }
 
+       /* escalate the type_set_t in a role attribute to all regular roles
+        * that belongs to it. */
+       if (hashtab_map(state.base->p_roles.table, role_fix_callback, &state))
+               goto cleanup;
+
        if (copy_and_expand_avrule_block(&state) < 0) {
                ERR(handle, "Error during expand");
                goto cleanup;
--

2.26.2

#2 lore raw
Quoted 29 lines · Nicolas Iooss
Quoted 27 lines · James Carter

Types associated to role attributes in optional blocks are not associated with the roles that have that attribute. The problem is that role_fix_callback is called before the avrule_decls are walked.

Example/
class CLASS1
sid kernel
class CLASS1 { PERM1 }
type TYPE1;
type TYPE1A;
allow TYPE1 self : CLASS1 PERM1;
attribute_role ROLE_ATTR1A;
role ROLE1;
role ROLE1A;
roleattribute ROLE1A ROLE_ATTR1A;
role ROLE1 types TYPE1;

  optional {
    require {
      class CLASS1 PERM1;
    }
    role ROLE_ATTR1A types TYPE1A;

}
user USER1 roles ROLE1;
sid kernel USER1:ROLE1:TYPE1

Quoted 7 lines
Quoted 5 lines

In this example ROLE1A will not have TYPE1A associated to it.

Call role_fix_callback() after the avrule_decls are walked.

Merged.

Thanks!
Nicolas

Quoted 34 lines
Quoted 34 lines
---
 libsepol/src/expand.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
libsepol/src/expand.c +5 -5
index eac7e450..1ee3e48f 100644
@@ -3017,10 +3017,6 @@ int expand_module(sepol_handle_t * handle,
        if (hashtab_map(state.base->p_roles.table,
                        role_bounds_copy_callback, &state))
                goto cleanup;
-       /* escalate the type_set_t in a role attribute to all regular roles
-        * that belongs to it. */
-       if (hashtab_map(state.base->p_roles.table, role_fix_callback, &state))
-               goto cleanup;
 
        /* copy MLS's sensitivity level and categories - this needs to be done
         * before expanding users (they need to be indexed too) */
@@ -3086,6 +3082,11 @@ int expand_module(sepol_handle_t * handle,
                goto cleanup;
        }
 
+       /* escalate the type_set_t in a role attribute to all regular roles
+        * that belongs to it. */
+       if (hashtab_map(state.base->p_roles.table, role_fix_callback, &state))
+               goto cleanup;
+
        if (copy_and_expand_avrule_block(&state) < 0) {
                ERR(handle, "Error during expand");
                goto cleanup;
--

2.26.2