Skip to contentSkip to conversation

Revert the prefix/suffix filename transition patches

PATCH In review James Carter 3 participants 12 messages Jul 26, 2023 – Aug 4, 2023 SELinux security module

lore
Share & tools
lore
#0 lore raw

cover Revert the prefix/suffix filename transition patches

Since the kernel patches have not been accepted yet, it seems better to revert these patches while they can still be cleanly reverted just in case the kernel patches are not accepted.

If the kernel patches get accepted, then I will re-apply these patches.

I should have waited for the kernel patches to be accepted before committing these in the first place.

James Carter (8):
Revert "libsepol/cil: add support for prefix/suffix filename
transtions to CIL"
Revert "checkpolicy,libsepol: add prefix/suffix support to module
policy"
Revert "checkpolicy,libsepol: add prefix/suffix support to kernel
policy"
Revert "libsepol: implement new module binary format of avrule" Revert "libsepol: implement new kernel binary format for avtab" Revert "checkpolicy,libsepol: move filename transition rules to
avrule"
Revert "checkpolicy,libsepol: move filename transitions to avtab" Revert "checkpolicy,libsepol: move transition to separate structure in
avtab"

 checkpolicy/checkmodule.c                  |   9 -
 checkpolicy/module_compiler.c              |  12 +
 checkpolicy/module_compiler.h              |   1 +
 checkpolicy/policy_define.c                | 211 +++++-
 checkpolicy/policy_define.h                |   3 +-
 checkpolicy/policy_parse.y                 |  13 +-
 checkpolicy/policy_scan.l                  |   4 -
 checkpolicy/test/dismod.c                  |  39 +-
 checkpolicy/test/dispol.c                  | 106 ++-
 libsepol/cil/src/cil.c                     |   6 -
 libsepol/cil/src/cil_binary.c              |  63 +-
 libsepol/cil/src/cil_build_ast.c           |  26 +-
 libsepol/cil/src/cil_copy_ast.c            |   1 -
 libsepol/cil/src/cil_internal.h            |   4 -
 libsepol/cil/src/cil_policy.c              |  17 +-
 libsepol/cil/src/cil_resolve_ast.c         |  10 -
 libsepol/cil/src/cil_write_ast.c           |   2 -
 libsepol/include/sepol/policydb/avtab.h    |  19 +-
 libsepol/include/sepol/policydb/hashtab.h  |   8 -
 libsepol/include/sepol/policydb/policydb.h |  50 +-
 libsepol/src/avrule_block.c                |   1 +
 libsepol/src/avtab.c                       | 338 +---------
 libsepol/src/conditional.c                 |   6 +-
 libsepol/src/expand.c                      | 153 +++--
 libsepol/src/kernel_to_cil.c               | 182 +++--
 libsepol/src/kernel_to_common.h            |  10 -
 libsepol/src/kernel_to_conf.c              | 178 +++--
 libsepol/src/link.c                        |  57 +-
 libsepol/src/module_to_cil.c               |  86 ++-
 libsepol/src/optimize.c                    |   8 -
 libsepol/src/policydb.c                    | 479 +++++++++++---
 libsepol/src/policydb_validate.c           | 101 ++-
 libsepol/src/services.c                    |   5 +-
 libsepol/src/write.c                       | 735 +++++----------------
 34 files changed, 1390 insertions(+), 1553 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/8 Revert "libsepol/cil: add support for prefix/suffix filename transtions to CIL"

This reverts commit 0c50de03cd38ef80dc6c5df9acef027f4b5c9526.

---
 libsepol/cil/src/cil.c             |  6 ------
 libsepol/cil/src/cil_binary.c      |  8 ++++----
 libsepol/cil/src/cil_build_ast.c   | 26 +++++---------------------
 libsepol/cil/src/cil_copy_ast.c    |  1 -
 libsepol/cil/src/cil_internal.h    |  4 ----
 libsepol/cil/src/cil_policy.c      | 17 +----------------
 libsepol/cil/src/cil_resolve_ast.c | 10 ----------
 libsepol/cil/src/cil_write_ast.c   |  2 --
 8 files changed, 10 insertions(+), 64 deletions(-)
libsepol/cil/src/cil.c +0 -6
index fa693020..38edcf8e 100644
@@ -95,8 +95,6 @@ char *CIL_KEY_TUNABLEIF;
 char *CIL_KEY_ALLOW;
 char *CIL_KEY_DONTAUDIT;
 char *CIL_KEY_TYPETRANSITION;
-char *CIL_KEY_PREFIX;
-char *CIL_KEY_SUFFIX;
 char *CIL_KEY_TYPECHANGE;
 char *CIL_KEY_CALL;
 char *CIL_KEY_TUNABLE;
@@ -266,8 +264,6 @@ static void cil_init_keys(void)
 	CIL_KEY_ALLOW = cil_strpool_add("allow");
 	CIL_KEY_DONTAUDIT = cil_strpool_add("dontaudit");
 	CIL_KEY_TYPETRANSITION = cil_strpool_add("typetransition");
-	CIL_KEY_PREFIX = cil_strpool_add("prefix");
-	CIL_KEY_SUFFIX = cil_strpool_add("suffix");
 	CIL_KEY_TYPECHANGE = cil_strpool_add("typechange");
 	CIL_KEY_CALL = cil_strpool_add("call");
 	CIL_KEY_TUNABLE = cil_strpool_add("tunable");
@@ -2391,8 +2387,6 @@ void cil_nametypetransition_init(struct cil_nametypetransition **nametypetrans)
 	(*nametypetrans)->obj = NULL;
 	(*nametypetrans)->name_str = NULL;
 	(*nametypetrans)->name = NULL;
-	(*nametypetrans)->name_match_str = NULL;
-	(*nametypetrans)->name_match = NAME_TRANS_MATCH_EXACT;
 	(*nametypetrans)->result_str = NULL;
 	(*nametypetrans)->result = NULL;
 }
libsepol/cil/src/cil_binary.c +4 -4
index ea0cef32..ffa44be7 100644
@@ -1193,7 +1193,7 @@ static int __cil_typetransition_to_avtab_helper(policydb_t *pdb,
 						type_datum_t *sepol_src,
 						type_datum_t *sepol_tgt,
 						struct cil_list *class_list,
-						char *name, uint8_t name_match,
+						char *name,
 						type_datum_t *sepol_result)
 {
 	int rc;
@@ -1211,7 +1211,7 @@ static int __cil_typetransition_to_avtab_helper(policydb_t *pdb,
 		avt_key.target_type = sepol_tgt->s.value;
 		avt_key.target_class = sepol_obj->s.value;
 		rc = avtab_insert_filename_trans(&pdb->te_avtab, &avt_key,
-			sepol_result->s.value, name, name_match,
+			sepol_result->s.value, name, NAME_TRANS_MATCH_EXACT,
 			&otype);
 		if (rc != SEPOL_OK) {
 			if (rc == SEPOL_EEXIST) {
@@ -1280,7 +1280,7 @@ static int __cil_typetransition_to_avtab(policydb_t *pdb, const struct cil_db *d
 
 			rc = __cil_typetransition_to_avtab_helper(
 				pdb, sepol_src, sepol_src, class_list,
-				name, typetrans->name_match, sepol_result
+				name, sepol_result
 			);
 			if (rc != SEPOL_OK) goto exit;
 		}
@@ -1298,7 +1298,7 @@ static int __cil_typetransition_to_avtab(policydb_t *pdb, const struct cil_db *d
 
 				rc = __cil_typetransition_to_avtab_helper(
 					pdb, sepol_src, sepol_tgt, class_list,
-					name, typetrans->name_match, sepol_result
+					name, sepol_result
 				);
 				if (rc != SEPOL_OK) goto exit;
 			}
libsepol/cil/src/cil_build_ast.c +5 -21
index 67bbdcab..4177c9f6 100644
@@ -3334,11 +3334,10 @@ int cil_gen_typetransition(struct cil_db *db, struct cil_tree_node *parse_curren
 		CIL_SYN_STRING,
 		CIL_SYN_STRING,
 		CIL_SYN_STRING | CIL_SYN_END,
-		CIL_SYN_STRING | CIL_SYN_END,
-		CIL_SYN_END,
+		CIL_SYN_END
 	};
 	size_t syntax_len = sizeof(syntax)/sizeof(*syntax);
-	char *s1, *s2, *s3, *s4, *s5, *s6;
+	char *s1, *s2, *s3, *s4, *s5;
 
 	if (db == NULL || parse_current == NULL || ast_node == NULL ) {
 		goto exit;
@@ -3354,22 +3353,12 @@ int cil_gen_typetransition(struct cil_db *db, struct cil_tree_node *parse_curren
 	s3 = parse_current->next->next->next->data;
 	s4 = parse_current->next->next->next->next->data;
 	s5 = NULL;
-	s6 = NULL;
 
 	if (parse_current->next->next->next->next->next) {
 		if (s4 == CIL_KEY_STAR) {
-			if (parse_current->next->next->next->next->next->next) {
-				s4 = parse_current->next->next->next->next->next->next->data;
-			} else {
-				s4 = parse_current->next->next->next->next->next->data;
-			}
+			s4 = parse_current->next->next->next->next->next->data;
 		} else {
-			if (parse_current->next->next->next->next->next->next) {
-				s5 = parse_current->next->next->next->next->next->data;
-				s6 = parse_current->next->next->next->next->next->next->data;
-			} else {
-				s5 = parse_current->next->next->next->next->next->data;
-			}
+			s5 = parse_current->next->next->next->next->next->data;
 		}
 	}
 
@@ -3381,13 +3370,8 @@ int cil_gen_typetransition(struct cil_db *db, struct cil_tree_node *parse_curren
 		nametypetrans->src_str = s1;
 		nametypetrans->tgt_str = s2;
 		nametypetrans->obj_str = s3;
+		nametypetrans->result_str = s5;
 		nametypetrans->name_str = s4;
-		if (s6) {
-			nametypetrans->name_match_str = s5;
-			nametypetrans->result_str = s6;
-		} else {
-			nametypetrans->result_str = s5;
-		}
 
 		ast_node->data = nametypetrans;
 		ast_node->flavor = CIL_NAMETYPETRANSITION;
libsepol/cil/src/cil_copy_ast.c +0 -1
index a2d2fe40..17f05021 100644
@@ -726,7 +726,6 @@ int cil_copy_nametypetransition(__attribute__((unused)) struct cil_db *db, void
 	new->tgt_str = orig->tgt_str;
 	new->obj_str = orig->obj_str;
 	new->name_str = orig->name_str;
-	new->name_match_str = orig->name_match_str;
 	new->result_str = orig->result_str;
 
 
libsepol/cil/src/cil_internal.h +0 -4
index a5ff808b..a7604762 100644
@@ -112,8 +112,6 @@ extern char *CIL_KEY_TUNABLEIF;
 extern char *CIL_KEY_ALLOW;
 extern char *CIL_KEY_DONTAUDIT;
 extern char *CIL_KEY_TYPETRANSITION;
-extern char *CIL_KEY_PREFIX;
-extern char *CIL_KEY_SUFFIX;
 extern char *CIL_KEY_TYPECHANGE;
 extern char *CIL_KEY_CALL;
 extern char *CIL_KEY_TUNABLE;
@@ -577,8 +575,6 @@ struct cil_nametypetransition {
 	struct cil_class *obj;
 	char *name_str;
 	struct cil_name *name;
-	char *name_match_str;
-	uint8_t name_match;
 	char *result_str;
 	void *result; /* type or alias */
 
libsepol/cil/src/cil_policy.c +1 -16
index 9ee40ba7..feb97868 100644
@@ -1260,7 +1260,6 @@ static void cil_nametypetransition_to_policy(FILE *out, struct cil_nametypetrans
 	struct cil_name *name;
 	struct cil_list *class_list;
 	struct cil_list_item *i1;
-	const char *name_match_str = "";
 
 	src = trans->src;
 	tgt = trans->tgt;
@@ -1269,21 +1268,7 @@ static void cil_nametypetransition_to_policy(FILE *out, struct cil_nametypetrans
 
 	class_list = cil_expand_class(trans->obj);
 	cil_list_for_each(i1, class_list) {
-		switch (trans->name_match) {
-		case NAME_TRANS_MATCH_EXACT:
-			name_match_str = "";
-			break;
-		case NAME_TRANS_MATCH_PREFIX:
-			name_match_str = " PREFIX";
-			break;
-		case NAME_TRANS_MATCH_SUFFIX:
-			name_match_str = " SUFFIX";
-			break;
-		default:
-			name_match_str = "???";
-			break;
-		}
-		fprintf(out, "type_transition %s %s : %s %s \"%s\"%s;\n", src->fqn, tgt->fqn, DATUM(i1->data)->fqn, res->fqn, name->datum.fqn, name_match_str);
+		fprintf(out, "type_transition %s %s : %s %s \"%s\";\n", src->fqn, tgt->fqn, DATUM(i1->data)->fqn, res->fqn, name->datum.fqn);
 	}
 	cil_list_destroy(&class_list, CIL_FALSE);
 }
libsepol/cil/src/cil_resolve_ast.c +0 -10
index 1ef0986c..d2bfdc81 100644
@@ -668,16 +668,6 @@ int cil_resolve_nametypetransition(struct cil_tree_node *current, void *extra_ar
 		nametypetrans->name = (struct cil_name *)name_datum;
 	}
 
-	if (nametypetrans->name_match_str == NULL) {
-		nametypetrans->name_match = NAME_TRANS_MATCH_EXACT;
-	} else if (nametypetrans->name_match_str == CIL_KEY_PREFIX) {
-		nametypetrans->name_match = NAME_TRANS_MATCH_PREFIX;
-	} else if (nametypetrans->name_match_str == CIL_KEY_SUFFIX) {
-		nametypetrans->name_match = NAME_TRANS_MATCH_SUFFIX;
-	} else {
-		cil_tree_log(current, CIL_ERR, "Invalid name match type \"%s\"", nametypetrans->name_match_str);
-	}
-
 	rc = cil_resolve_name(current, nametypetrans->result_str, CIL_SYM_TYPES, extra_args, &result_datum);
 	if (rc != SEPOL_OK) {
 		goto exit;
libsepol/cil/src/cil_write_ast.c +0 -2
index d96f6c39..b75784ef 100644
@@ -1168,8 +1168,6 @@ void cil_write_ast_node(FILE *out, struct cil_tree_node *node)
 		fprintf(out, "%s ", datum_or_str(DATUM(rule->tgt), rule->tgt_str));
 		fprintf(out, "%s ", datum_or_str(DATUM(rule->obj), rule->obj_str));
 		fprintf(out, "\"%s\" ", datum_or_str(DATUM(rule->name), rule->name_str));
-		if (rule->name_match != NAME_TRANS_MATCH_EXACT)
-			fprintf(out, "%s ", rule->name_match_str);
 		fprintf(out, "%s", datum_or_str(DATUM(rule->result), rule->result_str));
 		fprintf(out, ")\n");
 		break;
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/8 Revert "checkpolicy,libsepol: add prefix/suffix support to module policy"

In reply to James Carter

This reverts commit c39ebd07acd030a59a432797ed4da7733266a305.

---
 checkpolicy/policy_define.c                | 13 +++----
 checkpolicy/policy_define.h                |  2 +-
 checkpolicy/policy_parse.y                 | 13 +++----
 checkpolicy/policy_scan.l                  |  4 ---
 checkpolicy/test/dismod.c                  | 14 --------
 checkpolicy/test/dispol.c                  |  2 +-
 libsepol/cil/src/cil_binary.c              |  4 +--
 libsepol/include/sepol/policydb/avtab.h    |  1 -
 libsepol/include/sepol/policydb/policydb.h | 13 +++----
 libsepol/src/avtab.c                       | 30 ++++------------
 libsepol/src/expand.c                      |  6 +---
 libsepol/src/kernel_to_common.h            |  2 +-
 libsepol/src/link.c                        |  1 -
 libsepol/src/module_to_cil.c               | 25 +++-----------
 libsepol/src/policydb.c                    | 23 +------------
 libsepol/src/write.c                       | 40 ++++++----------------
 16 files changed, 43 insertions(+), 150 deletions(-)
checkpolicy/policy_define.c +4 -9
index 8421b253..25dbf25d 100644
@@ -1601,8 +1601,7 @@ static int set_types(type_set_t * set, char *id, int *add, char starallowed)
 	return -1;
 }
 
-static int define_compute_type_helper(int which, avrule_t ** rule,
-				      int has_filename, uint8_t name_match)
+static int define_compute_type_helper(int which, avrule_t ** rule, int has_filename)
 {
 	char *id;
 	type_datum_t *datum;
@@ -1677,7 +1676,6 @@ static int define_compute_type_helper(int which, avrule_t ** rule,
 			goto bad;
 		}
 	}
-	avrule->name_match = name_match;
 
 	ebitmap_for_each_positive_bit(&tclasses, node, i) {
 		perm = malloc(sizeof(class_perm_node_t));
@@ -1702,7 +1700,7 @@ static int define_compute_type_helper(int which, avrule_t ** rule,
 	return -1;
 }
 
-int define_compute_type(int which, int has_filename, uint8_t name_match)
+int define_compute_type(int which, int has_filename)
 {
 	char *id;
 	avrule_t *avrule;
@@ -1723,8 +1721,7 @@ int define_compute_type(int which, int has_filename, uint8_t name_match)
 		return 0;
 	}
 
-	if (define_compute_type_helper(which, &avrule, has_filename,
-				       name_match))
+	if (define_compute_type_helper(which, &avrule, has_filename))
 		return -1;
 
 	append_avrule(avrule);
@@ -1748,8 +1745,7 @@ avrule_t *define_cond_compute_type(int which)
 		return (avrule_t *) 1;
 	}
 
-	if (define_compute_type_helper(which, &avrule, 0,
-				       NAME_TRANS_MATCH_EXACT))
+	if (define_compute_type_helper(which, &avrule, 0))
 		return COND_ERR;
 
 	return avrule;
@@ -2398,7 +2394,6 @@ static int avrule_cpy(avrule_t *dest, const avrule_t *src)
 			return -1;
 		}
 	}
-	dest->name_match = src->name_match;
 	dest->line = src->line;
 	dest->source_filename = strdup(source_file);
 	if (!dest->source_filename) {
checkpolicy/policy_define.h +1 -1
index c1314871..5d0f70e4 100644
@@ -28,7 +28,7 @@ int define_default_role(int which);
 int define_default_type(int which);
 int define_default_range(int which);
 int define_common_perms(void);
-int define_compute_type(int which, int has_filename, uint8_t name_match);
+int define_compute_type(int which, int has_filename);
 int define_conditional(cond_expr_t *expr, avrule_t *t_list, avrule_t *f_list );
 int define_constraint(constraint_expr_t *expr);
 int define_dominance(void);
checkpolicy/policy_parse.y +4 -9
index 6b6890a3..2a14fc1e 100644
@@ -108,7 +108,6 @@ typedef int (* require_func_t)(int pass);
 %token IF
 %token ELSE
 %token TYPE_TRANSITION
-%token PREFIX SUFFIX
 %token TYPE_MEMBER
 %token TYPE_CHANGE
 %token ROLE_TRANSITION
@@ -452,17 +451,13 @@ cond_dontaudit_def	: DONTAUDIT names names ':' names names ';'
 		        ;
 			;
 transition_def		: TYPE_TRANSITION  names names ':' names identifier filename ';'
-			{if (define_compute_type(AVRULE_TRANSITION, 1, NAME_TRANS_MATCH_EXACT)) return -1;}
-            | TYPE_TRANSITION names names ':' names identifier filename PREFIX ';'
-            {if (define_compute_type(AVRULE_TRANSITION, 1, NAME_TRANS_MATCH_PREFIX)) return -1;}
-            | TYPE_TRANSITION names names ':' names identifier filename SUFFIX ';'
-            {if (define_compute_type(AVRULE_TRANSITION, 1, NAME_TRANS_MATCH_SUFFIX)) return -1;}
+			{if (define_compute_type(AVRULE_TRANSITION, 1)) return -1; }
 			| TYPE_TRANSITION names names ':' names identifier ';'
-                        {if (define_compute_type(AVRULE_TRANSITION, 0, NAME_TRANS_MATCH_EXACT)) return -1;}
+                        {if (define_compute_type(AVRULE_TRANSITION, 0)) return -1;}
                         | TYPE_MEMBER names names ':' names identifier ';'
-                        {if (define_compute_type(AVRULE_MEMBER, 0, NAME_TRANS_MATCH_EXACT)) return -1;}
+                        {if (define_compute_type(AVRULE_MEMBER, 0)) return -1;}
                         | TYPE_CHANGE names names ':' names identifier ';'
-                        {if (define_compute_type(AVRULE_CHANGE, 0, NAME_TRANS_MATCH_EXACT)) return -1;}
+                        {if (define_compute_type(AVRULE_CHANGE, 0)) return -1;}
     			;
 range_trans_def		: RANGE_TRANSITION names names mls_range_def ';'
 			{ if (define_range_trans(0)) return -1; }
checkpolicy/policy_scan.l +0 -4
index 9ffac353..2c025b61 100644
@@ -123,10 +123,6 @@ EXPANDATTRIBUTE |
 expandattribute                 { return(EXPANDATTRIBUTE); }
 TYPE_TRANSITION |
 type_transition			{ return(TYPE_TRANSITION); }
-PREFIX |
-prefix				{ return(PREFIX); }
-SUFFIX |
-suffix				{ return(SUFFIX); }
 TYPE_MEMBER |
 type_member			{ return(TYPE_MEMBER); }
 TYPE_CHANGE |
checkpolicy/test/dismod.c +0 -14
index 011191c3..8bab207c 100644
@@ -345,20 +345,6 @@ static int display_avrule(avrule_t * avrule, policydb_t * policy,
 		display_id(policy, fp, SYM_TYPES, avrule->perms->data - 1, "");
 		if (avrule->object_name)
 			fprintf(fp, " \"%s\"", avrule->object_name);
-		switch (avrule->name_match) {
-		case NAME_TRANS_MATCH_EXACT:
-			/* do nothing */
-			break;
-		case NAME_TRANS_MATCH_PREFIX:
-			fprintf(fp, " PREFIX");
-			break;
-		case NAME_TRANS_MATCH_SUFFIX:
-			fprintf(fp, " SUFFIX");
-			break;
-		default:
-			fprintf(fp, "     ERROR: no valid name match type specified\n");
-			return -1;
-		}
 	} else if (avrule->specified & AVRULE_XPERMS) {
 		avtab_extended_perms_t xperms;
 		int i;
checkpolicy/test/dispol.c +1 -1
index b5a41c1f..776bf54d 100644
@@ -129,7 +129,7 @@ typedef struct {
 	avtab_key_t *key;
 	policydb_t *p;
 	FILE *fp;
-	uint8_t match;
+	name_trans_match_t match;
 } render_name_trans_args_t;
 
 static int render_name_trans_helper(hashtab_key_t k, hashtab_datum_t d, void *a)
libsepol/cil/src/cil_binary.c +1 -3
index ffa44be7..996bad70 100644
@@ -1211,8 +1211,7 @@ static int __cil_typetransition_to_avtab_helper(policydb_t *pdb,
 		avt_key.target_type = sepol_tgt->s.value;
 		avt_key.target_class = sepol_obj->s.value;
 		rc = avtab_insert_filename_trans(&pdb->te_avtab, &avt_key,
-			sepol_result->s.value, name, NAME_TRANS_MATCH_EXACT,
-			&otype);
+			sepol_result->s.value, name, &otype);
 		if (rc != SEPOL_OK) {
 			if (rc == SEPOL_EEXIST) {
 				if (sepol_result->s.value!= otype) {
@@ -4652,7 +4651,6 @@ static avrule_t *__cil_init_sepol_avrule(uint32_t kind, struct cil_tree_node *no
 	__cil_init_sepol_type_set(&avrule->ttypes);
 	avrule->perms = NULL;
 	avrule->object_name = NULL;
-	avrule->name_match = NAME_TRANS_MATCH_EXACT;
 	avrule->line = node->line;
 
 	avrule->source_filename = NULL;
libsepol/include/sepol/policydb/avtab.h +0 -1
index 7d892879..870fb08a 100644
@@ -156,7 +156,6 @@ extern avtab_ptr_t avtab_search_node_next(avtab_ptr_t node, int specified);
 
 extern int avtab_insert_filename_trans(avtab_t *a, avtab_key_t *key,
 				       uint32_t otype, const char *name,
-				       uint8_t name_match,
 				       uint32_t *present_otype);
 extern int avtab_filename_trans_read(void *fp, uint32_t vers, avtab_t *a);
 
libsepol/include/sepol/policydb/policydb.h +7 -6
index 48b7b8bb..a2df4a62 100644
@@ -252,6 +252,12 @@ typedef struct av_extended_perms {
 	uint32_t perms[EXTENDED_PERMS_LEN];
 } av_extended_perms_t;
 
+typedef enum name_trans_match {
+	NAME_TRANS_MATCH_EXACT,
+	NAME_TRANS_MATCH_PREFIX,
+	NAME_TRANS_MATCH_SUFFIX,
+} name_trans_match_t;
+
 typedef struct avrule {
 /* these typedefs are almost exactly the same as those in avtab.h - they are
  * here because of the need to include neverallow and dontaudit messages */
@@ -279,10 +285,6 @@ typedef struct avrule {
 	type_set_t ttypes;
 	class_perm_node_t *perms;
 	char *object_name;	/* optional object name */
-#define NAME_TRANS_MATCH_EXACT 0
-#define NAME_TRANS_MATCH_PREFIX 1
-#define NAME_TRANS_MATCH_SUFFIX 2
-	uint8_t name_match;
 	av_extended_perms_t *xperms;
 	unsigned long line;	/* line number from policy.conf where
 				 * this rule originated  */
@@ -755,10 +757,9 @@ extern int policydb_set_target_platform(policydb_t *p, int platform);
 #define MOD_POLICYDB_VERSION_GLBLUB		20
 #define MOD_POLICYDB_VERSION_SELF_TYPETRANS	21
 #define MOD_POLICYDB_VERSION_AVRULE_FTRANS	22
-#define MOD_POLICYDB_VERSION_PREFIX_SUFFIX	23 /* preffix/suffix support for filename transitions */
 
 #define MOD_POLICYDB_VERSION_MIN MOD_POLICYDB_VERSION_BASE
-#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_PREFIX_SUFFIX
+#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_AVRULE_FTRANS
 
 #define POLICYDB_CONFIG_MLS    1
 
libsepol/src/avtab.c +7 -23
index 99fdaa87..90cfb90b 100644
@@ -771,7 +771,7 @@ int avtab_read(avtab_t * a, struct policy_file *fp, uint32_t vers)
 
 int avtab_insert_filename_trans(avtab_t *a, avtab_key_t *key,
 				uint32_t otype, const char *name,
-				uint8_t name_match, uint32_t *present_otype)
+				uint32_t *present_otype)
 {
 	int rc = SEPOL_ENOMEM;
 	avtab_trans_t new_trans = {0};
@@ -780,7 +780,6 @@ int avtab_insert_filename_trans(avtab_t *a, avtab_key_t *key,
 	avtab_ptr_t node;
 	char *name_key = NULL;
 	uint32_t *otype_datum = NULL;
-	symtab_t *target_symtab;
 
 	datum = avtab_search(a, key);
 	if (!datum) {
@@ -794,22 +793,8 @@ int avtab_insert_filename_trans(avtab_t *a, avtab_key_t *key,
 		datum = &node->datum;
 	}
 
-	switch (name_match) {
-	case NAME_TRANS_MATCH_EXACT:
-		target_symtab = &datum->trans->name_trans;
-		break;
-	case NAME_TRANS_MATCH_PREFIX:
-		target_symtab = &datum->trans->prefix_trans;
-		break;
-	case NAME_TRANS_MATCH_SUFFIX:
-		target_symtab = &datum->trans->suffix_trans;
-		break;
-	default:
-		return SEPOL_ERR;
-	}
-
-	if (!target_symtab->table) {
-		rc = symtab_init(target_symtab, 1 << 8);
+	if (!datum->trans->name_trans.table) {
+		rc = symtab_init(&datum->trans->name_trans, 1 << 8);
 		if (rc < 0)
 			return rc;
 	}
@@ -825,7 +810,8 @@ int avtab_insert_filename_trans(avtab_t *a, avtab_key_t *key,
 		goto bad;
 	*otype_datum = otype;
 
-	rc = hashtab_insert(target_symtab->table, name_key, otype_datum);
+	rc = hashtab_insert(datum->trans->name_trans.table, name_key,
+			    otype_datum);
 	if (rc < 0)
 		goto bad;
 
@@ -870,8 +856,7 @@ static int filename_trans_read_one(avtab_t *a, void *fp)
 	key.target_class = le32_to_cpu(buf[2]);
 	otype = le32_to_cpu(buf[3]);
 
-	rc = avtab_insert_filename_trans(a, &key, otype, name,
-					 NAME_TRANS_MATCH_EXACT, NULL);
+	rc = avtab_insert_filename_trans(a, &key, otype, name, NULL);
 	if (rc)
 		goto err;
 
@@ -924,8 +909,7 @@ static int filename_trans_comp_read_one(avtab_t *a, void *fp)
 			key.source_type = bit + 1;
 
 			rc = avtab_insert_filename_trans(a, &key, otype, name,
-							 NAME_TRANS_MATCH_EXACT,
-							 NULL);
+				NULL);
 			if (rc < 0)
 				goto err_ebitmap;
 		}
libsepol/src/expand.c +1 -5
index 7a011508..a4c92f4f 100644
@@ -1620,8 +1620,7 @@ static int expand_terule_helper(sepol_handle_t * handle,
 				uint32_t specified, cond_av_list_t ** cond,
 				cond_av_list_t ** other, uint32_t stype,
 				uint32_t ttype, class_perm_node_t * perms,
-				char *object_name, uint8_t name_match,
-				avtab_t * avtab, int enabled)
+				char *object_name, avtab_t * avtab, int enabled)
 {
 	avtab_key_t avkey;
 	avtab_datum_t *avdatump;
@@ -1653,7 +1652,6 @@ static int expand_terule_helper(sepol_handle_t * handle,
 			int rc = avtab_insert_filename_trans(avtab, &avkey,
 							     remapped_data,
 							     object_name,
-							     name_match,
 							     &oldtype);
 			if (rc == SEPOL_EEXIST) {
 				ERR(handle, "conflicting filename transition %s %s:%s \"%s\": %s vs %s",
@@ -1887,7 +1885,6 @@ static int expand_rule_helper(sepol_handle_t * handle,
 							      source_rule->specified, cond,
 							      other, i, i, source_rule->perms,
 							      source_rule->object_name,
-							      source_rule->name_match,
 							      dest_avtab, enabled);
 				if (retval != EXPAND_RULE_SUCCESS)
 					return retval;
@@ -1905,7 +1902,6 @@ static int expand_rule_helper(sepol_handle_t * handle,
 							      source_rule->specified, cond,
 							      other, i, j, source_rule->perms,
 							      source_rule->object_name,
-							      source_rule->name_match,
 							      dest_avtab, enabled);
 				if (retval != EXPAND_RULE_SUCCESS)
 					return retval;
libsepol/src/kernel_to_common.h +1 -1
index 353eb78f..07869e3d 100644
@@ -90,7 +90,7 @@ typedef struct {
 	const char *src;
 	const char *tgt;
 	const char *class;
-	uint8_t match;
+	name_trans_match_t match;
 } name_trans_to_strs_args_t;
 
 void sepol_indent(FILE *out, int indent);
libsepol/src/link.c +0 -1
index 332d62b2..88b23594 100644
@@ -1254,7 +1254,6 @@ static int copy_avrule_list(avrule_t * list, avrule_t ** dst,
 			if (!new_rule->object_name)
 				goto cleanup;
 		}
-		new_rule->name_match = cur->name_match;
 
 		cur_perm = cur->perms;
 		tail_perm = NULL;
libsepol/src/module_to_cil.c +5 -20
index 3fbb4af5..ca96bb67 100644
@@ -547,13 +547,12 @@ static int semantic_level_to_cil(struct policydb *pdb, int sens_offset, struct m
 	return 0;
 }
 
-static int avrule_to_cil(int indent, struct policydb *pdb, uint32_t type, const char *src, const char *tgt, const char *object_name, uint8_t name_match, const struct class_perm_node *classperms)
+static int avrule_to_cil(int indent, struct policydb *pdb, uint32_t type, const char *src, const char *tgt, const char *object_name, const struct class_perm_node *classperms)
 {
 	int rc = -1;
 	const char *rule;
 	const struct class_perm_node *classperm;
 	char *perms;
-	const char *match_str = "";
 
 	switch (type) {
 	case AVRULE_ALLOWED:
@@ -599,24 +598,10 @@ static int avrule_to_cil(int indent, struct policydb *pdb, uint32_t type, const
 					pdb->p_class_val_to_name[classperm->tclass - 1],
 					perms + 1);
 		} else if (object_name) {
-			switch (name_match) {
-			case NAME_TRANS_MATCH_EXACT:
-				match_str = "";
-				break;
-			case NAME_TRANS_MATCH_PREFIX:
-				match_str = " prefix";
-				break;
-			case NAME_TRANS_MATCH_SUFFIX:
-				match_str = " suffix";
-				break;
-			default:
-				ERR(NULL, "Unknown name match type: %" PRIu8,
-						name_match);
-			}
-			cil_println(indent, "(%s %s %s %s \"%s\"%s %s)",
+			cil_println(indent, "(%s %s %s %s \"%s\" %s)",
 					rule, src, tgt,
 					pdb->p_class_val_to_name[classperm->tclass - 1],
-					object_name, match_str,
+					object_name,
 					pdb->p_type_val_to_name[classperm->data - 1]);
 		} else {
 			cil_println(indent, "(%s %s %s %s %s)",
@@ -1220,7 +1205,7 @@ static int avrule_list_to_cil(int indent, struct policydb *pdb, struct avrule *a
 				if (avrule->specified & AVRULE_XPERMS) {
 					rc = avrulex_to_cil(indent, pdb, avrule->specified, snames[s], tnames[t], avrule->perms, avrule->xperms);
 				} else {
-					rc = avrule_to_cil(indent, pdb, avrule->specified, snames[s], tnames[t], avrule->object_name, avrule->name_match, avrule->perms);
+					rc = avrule_to_cil(indent, pdb, avrule->specified, snames[s], tnames[t], avrule->object_name, avrule->perms);
 				}
 				if (rc != 0) {
 					goto exit;
@@ -1231,7 +1216,7 @@ static int avrule_list_to_cil(int indent, struct policydb *pdb, struct avrule *a
 				if (avrule->specified & AVRULE_XPERMS) {
 					rc = avrulex_to_cil(indent, pdb, avrule->specified, snames[s], "self", avrule->perms, avrule->xperms);
 				} else {
-					rc = avrule_to_cil(indent, pdb, avrule->specified, snames[s], "self", avrule->object_name, avrule->name_match, avrule->perms);
+					rc = avrule_to_cil(indent, pdb, avrule->specified, snames[s], "self", avrule->object_name, avrule->perms);
 				}
 				if (rc != 0) {
 					goto exit;
libsepol/src/policydb.c +1 -22
index 552eb77a..f1f6cec6 100644
@@ -355,13 +355,6 @@ static const struct policydb_compat_info policydb_compat[] = {
 	 .ocon_num = OCON_IBENDPORT + 1,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
-	{
-	 .type = POLICY_BASE,
-	 .version = MOD_POLICYDB_VERSION_PREFIX_SUFFIX,
-	 .sym_num = SYM_NUM,
-	 .ocon_num = OCON_IBENDPORT + 1,
-	 .target_platform = SEPOL_TARGET_SELINUX,
-	},
 	{
 	 .type = POLICY_MOD,
 	 .version = MOD_POLICYDB_VERSION_BASE,
@@ -495,13 +488,6 @@ static const struct policydb_compat_info policydb_compat[] = {
 	 .ocon_num = 0,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
-	{
-	 .type = POLICY_MOD,
-	 .version = MOD_POLICYDB_VERSION_PREFIX_SUFFIX,
-	 .sym_num = SYM_NUM,
-	 .ocon_num = 0,
-	 .target_platform = SEPOL_TARGET_SELINUX,
-	},
 };
 
 #if 0
@@ -3185,7 +3171,6 @@ common_read, class_read, role_read, type_read, user_read,
 static avrule_t *avrule_read(policydb_t * p, struct policy_file *fp)
 {
 	unsigned int i;
-	uint8_t buf8;
 	uint32_t buf[2], len;
 	class_perm_node_t *cur, *tail = NULL;
 	avrule_t *avrule;
@@ -3249,15 +3234,10 @@ static avrule_t *avrule_read(policydb_t * p, struct policy_file *fp)
 			if (rc < 0)
 				goto bad;
 		}
-		if (p->policyvers >= MOD_POLICYDB_VERSION_PREFIX_SUFFIX) {
-			rc = next_entry(&buf8, fp, sizeof(uint8_t));
-			if (rc < 0)
-				goto bad;
-			avrule->name_match = buf8;
-		}
 	}
 
 	if (avrule->specified & AVRULE_XPERMS) {
+		uint8_t buf8;
 		size_t nel = ARRAY_SIZE(avrule->xperms->perms);
 		uint32_t buf32[nel];
 
@@ -3566,7 +3546,6 @@ static int filename_trans_rule_read(policydb_t *p, avrule_t **r,
 		rc = str_read(&cur->object_name, fp, len);
 		if (rc)
 			return -1;
-		cur->name_match = NAME_TRANS_MATCH_EXACT;
 
 		if (type_set_read(&cur->stypes, fp))
 			return -1;
libsepol/src/write.c +10 -30
index f0ed9e33..df47197c 100644
@@ -2071,7 +2071,6 @@ static int avrule_write(policydb_t *p, avrule_t * avrule,
 			struct policy_file *fp)
 {
 	size_t items, items2;
-	uint8_t buf8;
 	uint32_t buf[32], len;
 	class_perm_node_t *cur;
 
@@ -2079,11 +2078,6 @@ static int avrule_write(policydb_t *p, avrule_t * avrule,
 	if (p->policyvers < MOD_POLICYDB_VERSION_AVRULE_FTRANS &&
 	    avrule->specified & AVRULE_TRANSITION && avrule->object_name)
 		return POLICYDB_SUCCESS;
-	/* skip prefix/suffix name transition if writing older version */
-	if (p->policyvers < MOD_POLICYDB_VERSION_PREFIX_SUFFIX &&
-	    avrule->specified & AVRULE_TRANSITION &&
-	    avrule->object_name && avrule->name_match != NAME_TRANS_MATCH_EXACT)
-		return POLICYDB_SUCCESS;
 
 	if (p->policyvers < MOD_POLICYDB_VERSION_SELF_TYPETRANS &&
 	    (avrule->specified & AVRULE_TYPE) &&
@@ -2142,17 +2136,12 @@ static int avrule_write(policydb_t *p, avrule_t * avrule,
 			if (items != len)
 				return POLICYDB_ERROR;
 		}
-		if (p->policyvers >= MOD_POLICYDB_VERSION_PREFIX_SUFFIX) {
-			buf8 = avrule->name_match;
-			items = put_entry(&buf8, sizeof(uint8_t), 1, fp);
-			if (items != 1)
-				return POLICYDB_ERROR;
-		}
 	}
 
 	if (avrule->specified & AVRULE_XPERMS) {
 		size_t nel = ARRAY_SIZE(avrule->xperms->perms);
 		uint32_t buf32[nel];
+		uint8_t buf8;
 		unsigned int i;
 
 		if (p->policyvers < MOD_POLICYDB_VERSION_XPERMS_IOCTL) {
@@ -2197,17 +2186,12 @@ static int avrule_write_list(policydb_t *p, avrule_t * avrules,
 
 	avrule = avrules;
 	len = 0;
-	for (avrule = avrules; avrule; avrule = avrule->next) {
-		if (p->policyvers < MOD_POLICYDB_VERSION_AVRULE_FTRANS &&
-		    (avrule->specified & AVTAB_TRANSITION) &&
-		    avrule->object_name)
-			continue;
-		if (p->policyvers < MOD_POLICYDB_VERSION_PREFIX_SUFFIX &&
-		    (avrule->specified & AVTAB_TRANSITION) &&
-		    avrule->object_name &&
-		    avrule->name_match != NAME_TRANS_MATCH_EXACT)
-			continue;
-		len++;
+	while (avrule) {
+		if (p->policyvers >= MOD_POLICYDB_VERSION_AVRULE_FTRANS ||
+		    !(avrule->specified & AVRULE_TRANSITION &&
+		      avrule->object_name))
+			len++;
+		avrule = avrule->next;
 	}
 
 	buf[0] = cpu_to_le32(len);
@@ -2315,8 +2299,7 @@ static int filename_trans_rule_write(policydb_t *p, avrule_t *rules,
 	class_perm_node_t *perm;
 
 	for (rule = rules; rule; rule = rule->next) {
-		if (rule->specified & AVRULE_TRANSITION && rule->object_name &&
-		    rule->name_match == NAME_TRANS_MATCH_EXACT) {
+		if (rule->specified & AVRULE_TRANSITION && rule->object_name) {
 			for (perm = rule->perms; perm; perm = perm->next) {
 				nel++;
 			}
@@ -2329,9 +2312,7 @@ static int filename_trans_rule_write(policydb_t *p, avrule_t *rules,
 		return POLICYDB_ERROR;
 
 	for (rule = rules; rule; rule = rule->next) {
-		if (!(rule->specified & AVRULE_TRANSITION &&
-		      rule->object_name &&
-		      rule->name_match == NAME_TRANS_MATCH_EXACT))
+		if (!(rule->specified & AVRULE_TRANSITION && rule->object_name))
 			continue;
 		len = strlen(rule->object_name);
 		for (perm = rule->perms; perm; perm = perm->next) {
@@ -2770,8 +2751,7 @@ int policydb_write(policydb_t * p, struct policy_file *fp)
 	if (p->policy_type == POLICY_KERN) {
 		if (avtab_write(p, &p->te_avtab, fp))
 			return POLICYDB_ERROR;
-		if (p->policyvers < POLICYDB_VERSION_PREFIX_SUFFIX &&
-		    avtab_has_prefix_suffix_filename_transitions(&p->te_avtab)) {
+		if (avtab_has_prefix_suffix_filename_transitions(&p->te_avtab)) {
 			WARN(fp->handle,
 			     "Discarding filename prefix/suffix type transition rules");
 		}
Signature · 1 line
2.41.0
#3 lore raw

PATCH 3/8 Revert "checkpolicy,libsepol: add prefix/suffix support to kernel policy"

In reply to James Carter

This reverts commit 1174483d2924dc700673363b240fca2b9fe45786.

---
 checkpolicy/test/dispol.c                  |  25 +----
 libsepol/include/sepol/policydb/avtab.h    |   2 -
 libsepol/include/sepol/policydb/policydb.h |   9 +-
 libsepol/src/avtab.c                       |  13 ---
 libsepol/src/kernel_to_cil.c               |  30 +-----
 libsepol/src/kernel_to_common.h            |   1 -
 libsepol/src/kernel_to_conf.c              |  30 +-----
 libsepol/src/policydb.c                    |   7 --
 libsepol/src/policydb_validate.c           |  11 +-
 libsepol/src/write.c                       | 113 ++++-----------------
 10 files changed, 30 insertions(+), 211 deletions(-)
checkpolicy/test/dispol.c +1 -24
index 776bf54d..861fa903 100644
@@ -129,7 +129,6 @@ typedef struct {
 	avtab_key_t *key;
 	policydb_t *p;
 	FILE *fp;
-	name_trans_match_t match;
 } render_name_trans_args_t;
 
 static int render_name_trans_helper(hashtab_key_t k, hashtab_datum_t d, void *a)
@@ -141,22 +140,7 @@ static int render_name_trans_helper(hashtab_key_t k, hashtab_datum_t d, void *a)
 	fprintf(args->fp, "type_transition ");
 	render_key(args->key, args->p, args->fp);
 	render_type(*otype, args->p, args->fp);
-	const char *match_str = "";
-	switch (args->match) {
-	case NAME_TRANS_MATCH_EXACT:
-		match_str = "";
-		break;
-	case NAME_TRANS_MATCH_PREFIX:
-		match_str = " PREFIX";
-		break;
-	case NAME_TRANS_MATCH_SUFFIX:
-		match_str = " SUFFIX";
-		break;
-	default:
-		fprintf(args->fp, "     ERROR: no valid name match type specified\n");
-		return -1;
-	}
-	fprintf(args->fp, " \"%s\"%s;\n", name, match_str);
+	fprintf(args->fp, " \"%s\";\n", name);
 
 	return 0;
 }
@@ -223,16 +207,9 @@ static int render_av_rule(avtab_key_t * key, avtab_datum_t * datum, uint32_t wha
 				.key = key,
 				.p = p,
 				.fp = fp,
-				.match = NAME_TRANS_MATCH_EXACT,
 			};
 			hashtab_map(datum->trans->name_trans.table,
 				    render_name_trans_helper, &args);
-			args.match = NAME_TRANS_MATCH_PREFIX;
-			hashtab_map(datum->trans->prefix_trans.table,
-				    render_name_trans_helper, &args);
-			args.match = NAME_TRANS_MATCH_SUFFIX;
-			hashtab_map(datum->trans->suffix_trans.table,
-				    render_name_trans_helper, &args);
 		}
 		if (key->specified & AVTAB_MEMBER) {
 			fprintf(fp, "type_member ");
libsepol/include/sepol/policydb/avtab.h +0 -2
index 870fb08a..5dc720cc 100644
@@ -74,8 +74,6 @@ typedef struct avtab_key {
 typedef struct avtab_trans {
 	uint32_t otype;		/* resulting type of the new object */
 	symtab_t name_trans;	/* filename transitions */
-	symtab_t prefix_trans;	/* prefix filename transitions */
-	symtab_t suffix_trans;	/* prefix filename transitions */
 } avtab_trans_t;
 
 typedef struct avtab_extended_perms {
libsepol/include/sepol/policydb/policydb.h +1 -8
index a2df4a62..5efd0a47 100644
@@ -252,12 +252,6 @@ typedef struct av_extended_perms {
 	uint32_t perms[EXTENDED_PERMS_LEN];
 } av_extended_perms_t;
 
-typedef enum name_trans_match {
-	NAME_TRANS_MATCH_EXACT,
-	NAME_TRANS_MATCH_PREFIX,
-	NAME_TRANS_MATCH_SUFFIX,
-} name_trans_match_t;
-
 typedef struct avrule {
 /* these typedefs are almost exactly the same as those in avtab.h - they are
  * here because of the need to include neverallow and dontaudit messages */
@@ -729,11 +723,10 @@ extern int policydb_set_target_platform(policydb_t *p, int platform);
 #define POLICYDB_VERSION_GLBLUB		32
 #define POLICYDB_VERSION_COMP_FTRANS	33 /* compressed filename transitions */
 #define POLICYDB_VERSION_AVTAB_FTRANS	34 /* filename transitions moved to avtab */
-#define POLICYDB_VERSION_PREFIX_SUFFIX	35 /* prefix/suffix support for filename transitions */
 
 /* Range of policy versions we understand*/
 #define POLICYDB_VERSION_MIN	POLICYDB_VERSION_BASE
-#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_PREFIX_SUFFIX
+#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_AVTAB_FTRANS
 
 /* Module versions and specific changes*/
 #define MOD_POLICYDB_VERSION_BASE		4
libsepol/src/avtab.c +0 -13
index 90cfb90b..2a9564ba 100644
@@ -327,10 +327,6 @@ void avtab_trans_destroy(avtab_trans_t *trans)
 {
 	hashtab_map(trans->name_trans.table, avtab_trans_destroy_helper, NULL);
 	symtab_destroy(&trans->name_trans);
-	hashtab_map(trans->prefix_trans.table, avtab_trans_destroy_helper, NULL);
-	symtab_destroy(&trans->prefix_trans);
-	hashtab_map(trans->suffix_trans.table, avtab_trans_destroy_helper, NULL);
-	symtab_destroy(&trans->suffix_trans);
 }
 
 void avtab_destroy(avtab_t * h)
@@ -524,15 +520,6 @@ static int avtab_trans_read(policy_file_t *fp, uint32_t vers,
 	if (rc < 0)
 		goto bad;
 
-	if (vers >= POLICYDB_VERSION_PREFIX_SUFFIX) {
-		rc = avtab_read_name_trans(fp, &trans->prefix_trans);
-		if (rc < 0)
-			goto bad;
-		rc = avtab_read_name_trans(fp, &trans->suffix_trans);
-		if (rc < 0)
-			goto bad;
-	}
-
 	return SEPOL_OK;
 
 bad:
libsepol/src/kernel_to_cil.c +2 -28
index 30a67017..8ed695f1 100644
@@ -1705,24 +1705,9 @@ static int name_trans_to_strs_helper(hashtab_key_t k, hashtab_datum_t d, void *a
 	char *name = k;
 	uint32_t *otype = d;
 	name_trans_to_strs_args_t *args = a;
-	const char *match_str = "";
-	switch (args->match) {
-	case NAME_TRANS_MATCH_EXACT:
-		match_str = "";
-		break;
-	case NAME_TRANS_MATCH_PREFIX:
-		match_str = " prefix";
-		break;
-	case NAME_TRANS_MATCH_SUFFIX:
-		match_str = " suffix";
-		break;
-	default:
-		ERR(NULL, "Unknown name match type: %" PRIu8, args->match);
-		return SEPOL_ERR;
-	}
-	return strs_create_and_add(args->strs, "(%s %s %s %s \"%s\"%s %s)", 7,
+	return strs_create_and_add(args->strs, "(%s %s %s %s \"%s\" %s)", 6,
 				   args->flavor, args->src, args->tgt,
-				   args->class, name, match_str,
+				   args->class, name,
 				   args->pdb->p_type_val_to_name[*otype - 1]);
 }
 
@@ -1810,20 +1795,9 @@ static int avtab_node_to_strs(struct policydb *pdb, avtab_key_t *key, avtab_datu
 			.src = src,
 			.tgt = tgt,
 			.class = class,
-			.match = NAME_TRANS_MATCH_EXACT,
 		};
 		rc = hashtab_map(datum->trans->name_trans.table,
 				 name_trans_to_strs_helper, &args);
-		if (rc < 0)
-			return rc;
-		args.match = NAME_TRANS_MATCH_PREFIX;
-		rc = hashtab_map(datum->trans->prefix_trans.table,
-				 name_trans_to_strs_helper, &args);
-		if (rc < 0)
-			return rc;
-		args.match = NAME_TRANS_MATCH_SUFFIX;
-		rc = hashtab_map(datum->trans->suffix_trans.table,
-				 name_trans_to_strs_helper, &args);
 	} else {
 		new = pdb->p_type_val_to_name[data - 1];
 
libsepol/src/kernel_to_common.h +0 -1
index 07869e3d..b8ea237d 100644
@@ -90,7 +90,6 @@ typedef struct {
 	const char *src;
 	const char *tgt;
 	const char *class;
-	name_trans_match_t match;
 } name_trans_to_strs_args_t;
 
 void sepol_indent(FILE *out, int indent);
libsepol/src/kernel_to_conf.c +2 -28
index b1699b39..eb14ccf1 100644
@@ -1683,26 +1683,11 @@ static int name_trans_to_strs_helper(hashtab_key_t k, hashtab_datum_t d, void *a
 	char *name = k;
 	uint32_t *otype = d;
 	name_trans_to_strs_args_t *args = a;
-	const char *match_str = "";
-	switch (args->match) {
-	case NAME_TRANS_MATCH_EXACT:
-		match_str = "";
-		break;
-	case NAME_TRANS_MATCH_PREFIX:
-		match_str = " PREFIX";
-		break;
-	case NAME_TRANS_MATCH_SUFFIX:
-		match_str = " SUFFIX";
-		break;
-	default:
-		ERR(NULL, "Unknown name match type: %" PRIu8, args->match);
-		return SEPOL_ERR;
-	}
-	return strs_create_and_add(args->strs, "%s %s %s:%s %s \"%s\"%s;", 7,
+	return strs_create_and_add(args->strs, "%s %s %s:%s %s \"%s\";", 6,
 				   args->flavor, args->src, args->tgt,
 				   args->class,
 				   args->pdb->p_type_val_to_name[*otype - 1],
-				   name, match_str);
+				   name);
 }
 
 static int avtab_node_to_strs(struct policydb *pdb, avtab_key_t *key, avtab_datum_t *datum, struct strs *strs)
@@ -1786,20 +1771,9 @@ static int avtab_node_to_strs(struct policydb *pdb, avtab_key_t *key, avtab_datu
 			.src = src,
 			.tgt = tgt,
 			.class = class,
-			.match = NAME_TRANS_MATCH_EXACT,
 		};
 		rc = hashtab_map(datum->trans->name_trans.table,
 				 name_trans_to_strs_helper, &args);
-		if (rc < 0)
-			return rc;
-		args.match = NAME_TRANS_MATCH_PREFIX;
-		rc = hashtab_map(datum->trans->prefix_trans.table,
-				 name_trans_to_strs_helper, &args);
-		if (rc < 0)
-			return rc;
-		args.match = NAME_TRANS_MATCH_SUFFIX;
-		rc = hashtab_map(datum->trans->suffix_trans.table,
-				 name_trans_to_strs_helper, &args);
 	} else {
 		new = pdb->p_type_val_to_name[data - 1];
 
libsepol/src/policydb.c +0 -7
index f1f6cec6..37bb97a1 100644
@@ -215,13 +215,6 @@ static const struct policydb_compat_info policydb_compat[] = {
 	 .ocon_num = OCON_IBENDPORT + 1,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
-	{
-	 .type = POLICY_KERN,
-	 .version = POLICYDB_VERSION_PREFIX_SUFFIX,
-	 .sym_num = SYM_NUM,
-	 .ocon_num = OCON_IBENDPORT + 1,
-	 .target_platform = SEPOL_TARGET_SELINUX,
-	},
 	{
 	 .type = POLICY_BASE,
 	 .version = MOD_POLICYDB_VERSION_BASE,
libsepol/src/policydb_validate.c +2 -9
index 08b4a477..0b8e8eee 100644
@@ -855,18 +855,11 @@ static int validate_avtab_key_and_datum(avtab_key_t *k, avtab_datum_t *d, void *
 
 		/* also each transition must be non empty */
 		if (!d->trans->otype &&
-		    !hashtab_nel(d->trans->name_trans.table) &&
-		    !hashtab_nel(d->trans->name_trans.table) &&
-		    !hashtab_nel(d->trans->prefix_trans.table) &&
-		    !hashtab_nel(d->trans->suffix_trans.table))
+		    !hashtab_nel(d->trans->name_trans.table))
 			return -1;
 
-		/* and each name transition must be also valid */
+		/* and each filename transition must be also valid */
 		if (hashtab_map(d->trans->name_trans.table,
-				validate_name_trans_helper, margs) ||
-		    hashtab_map(d->trans->prefix_trans.table,
-				validate_name_trans_helper, margs) ||
-		    hashtab_map(d->trans->suffix_trans.table,
 				validate_name_trans_helper, margs))
 			return -1;
 	} else if ((k->specified & AVTAB_TYPE) && validate_simpletype(d->data, margs->policy, margs->flavors)) {
libsepol/src/write.c +22 -91

150 lines not on this page · raw message

Signature · 1 line
2.41.0
#4 lore raw

PATCH 4/8 Revert "libsepol: implement new module binary format of avrule"

In reply to James Carter

This reverts commit 11013986ac484586e50ce318f4f10c1edf39e746.

---
 libsepol/include/sepol/policydb/policydb.h |  3 +--
 libsepol/src/policydb.c                    | 28 ----------------------
 libsepol/src/write.c                       | 24 +++----------------
 3 files changed, 4 insertions(+), 51 deletions(-)
libsepol/include/sepol/policydb/policydb.h +1 -2
index 5efd0a47..528c1cad 100644
@@ -749,10 +749,9 @@ extern int policydb_set_target_platform(policydb_t *p, int platform);
 #define MOD_POLICYDB_VERSION_INFINIBAND		19
 #define MOD_POLICYDB_VERSION_GLBLUB		20
 #define MOD_POLICYDB_VERSION_SELF_TYPETRANS	21
-#define MOD_POLICYDB_VERSION_AVRULE_FTRANS	22
 
 #define MOD_POLICYDB_VERSION_MIN MOD_POLICYDB_VERSION_BASE
-#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_AVRULE_FTRANS
+#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_SELF_TYPETRANS
 
 #define POLICYDB_CONFIG_MLS    1
 
libsepol/src/policydb.c +0 -28
index 37bb97a1..b15d4163 100644
@@ -341,13 +341,6 @@ static const struct policydb_compat_info policydb_compat[] = {
 	 .ocon_num = OCON_IBENDPORT + 1,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
-	{
-	 .type = POLICY_BASE,
-	 .version = MOD_POLICYDB_VERSION_AVRULE_FTRANS,
-	 .sym_num = SYM_NUM,
-	 .ocon_num = OCON_IBENDPORT + 1,
-	 .target_platform = SEPOL_TARGET_SELINUX,
-	},
 	{
 	 .type = POLICY_MOD,
 	 .version = MOD_POLICYDB_VERSION_BASE,
@@ -474,13 +467,6 @@ static const struct policydb_compat_info policydb_compat[] = {
 	 .ocon_num = 0,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
-	{
-	 .type = POLICY_MOD,
-	 .version = MOD_POLICYDB_VERSION_AVRULE_FTRANS,
-	 .sym_num = SYM_NUM,
-	 .ocon_num = 0,
-	 .target_platform = SEPOL_TARGET_SELINUX,
-	},
 };
 
 #if 0
@@ -3216,19 +3202,6 @@ static avrule_t *avrule_read(policydb_t * p, struct policy_file *fp)
 		tail = cur;
 	}
 
-	if (p->policyvers >= MOD_POLICYDB_VERSION_AVRULE_FTRANS &&
-	    avrule->specified & AVRULE_TRANSITION) {
-		rc = next_entry(buf, fp, sizeof(uint32_t));
-		if (rc < 0)
-			goto bad;
-		len = le32_to_cpu(*buf);
-		if (len) {
-			rc = str_read(&avrule->object_name, fp, len);
-			if (rc < 0)
-				goto bad;
-		}
-	}
-
 	if (avrule->specified & AVRULE_XPERMS) {
 		uint8_t buf8;
 		size_t nel = ARRAY_SIZE(avrule->xperms->perms);
@@ -3660,7 +3633,6 @@ static int avrule_decl_read(policydb_t * p, avrule_decl_t * decl,
 	}
 
 	if (p->policyvers >= MOD_POLICYDB_VERSION_FILENAME_TRANS &&
-	    p->policyvers < MOD_POLICYDB_VERSION_AVRULE_FTRANS &&
 	    filename_trans_rule_read(p, &decl->avrules, fp))
 		return -1;
 
libsepol/src/write.c +3 -21
index d7f47c8d..68495198 100644
@@ -2025,9 +2025,8 @@ static int avrule_write(policydb_t *p, avrule_t * avrule,
 	uint32_t buf[32], len;
 	class_perm_node_t *cur;
 
-	/* skip filename transitions if writing older version without name */
-	if (p->policyvers < MOD_POLICYDB_VERSION_AVRULE_FTRANS &&
-	    avrule->specified & AVRULE_TRANSITION && avrule->object_name)
+	/* skip filename transitions for now */
+	if (avrule->specified & AVRULE_TRANSITION && avrule->object_name)
 		return POLICYDB_SUCCESS;
 
 	if (p->policyvers < MOD_POLICYDB_VERSION_SELF_TYPETRANS &&
@@ -2074,21 +2073,6 @@ static int avrule_write(policydb_t *p, avrule_t * avrule,
 		cur = cur->next;
 	}
 
-	if (p->policyvers >= MOD_POLICYDB_VERSION_AVRULE_FTRANS &&
-	    avrule->specified & AVRULE_TRANSITION) {
-		len = avrule->object_name ? strlen(avrule->object_name) : 0;
-		*buf = cpu_to_le32(len);
-		items = put_entry(buf, sizeof(uint32_t), 1, fp);
-		if (items != 1)
-			return POLICYDB_ERROR;
-		if (avrule->object_name) {
-			items = put_entry(avrule->object_name, sizeof(char),
-					  len, fp);
-			if (items != len)
-				return POLICYDB_ERROR;
-		}
-	}
-
 	if (avrule->specified & AVRULE_XPERMS) {
 		size_t nel = ARRAY_SIZE(avrule->xperms->perms);
 		uint32_t buf32[nel];
@@ -2138,8 +2122,7 @@ static int avrule_write_list(policydb_t *p, avrule_t * avrules,
 	avrule = avrules;
 	len = 0;
 	while (avrule) {
-		if (p->policyvers >= MOD_POLICYDB_VERSION_AVRULE_FTRANS ||
-		    !(avrule->specified & AVRULE_TRANSITION &&
+		if (!(avrule->specified & AVRULE_TRANSITION &&
 		      avrule->object_name))
 			len++;
 		avrule = avrule->next;
@@ -2374,7 +2357,6 @@ static int avrule_decl_write(avrule_decl_t * decl, int num_scope_syms,
 	}
 
 	if (p->policyvers >= MOD_POLICYDB_VERSION_FILENAME_TRANS &&
-	    p->policyvers < MOD_POLICYDB_VERSION_AVRULE_FTRANS &&
 	    filename_trans_rule_write(p, decl->avrules, fp))
 		return POLICYDB_ERROR;
 
Signature · 1 line
2.41.0
#5 lore raw

PATCH 5/8 Revert "libsepol: implement new kernel binary format for avtab"

In reply to James Carter

This reverts commit 7b77edd91946d8a415cddc596765d8c2e8bd6f63.

---
 libsepol/include/sepol/policydb/policydb.h |  3 +-
 libsepol/src/avtab.c                       | 88 ++--------------------
 libsepol/src/policydb.c                    |  8 --
 libsepol/src/write.c                       | 86 ++++-----------------
 4 files changed, 21 insertions(+), 164 deletions(-)
libsepol/include/sepol/policydb/policydb.h +1 -2
index 528c1cad..d30f26af 100644
@@ -722,11 +722,10 @@ extern int policydb_set_target_platform(policydb_t *p, int platform);
 #define POLICYDB_VERSION_INFINIBAND		31 /* Linux-specific */
 #define POLICYDB_VERSION_GLBLUB		32
 #define POLICYDB_VERSION_COMP_FTRANS	33 /* compressed filename transitions */
-#define POLICYDB_VERSION_AVTAB_FTRANS	34 /* filename transitions moved to avtab */
 
 /* Range of policy versions we understand*/
 #define POLICYDB_VERSION_MIN	POLICYDB_VERSION_BASE
-#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_AVTAB_FTRANS
+#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_COMP_FTRANS
 
 /* Module versions and specific changes*/
 #define MOD_POLICYDB_VERSION_BASE		4
libsepol/src/avtab.c +5 -83

101 lines not on this page · raw message

libsepol/src/policydb.c +0 -8
index b15d4163..4913ee21 100644
@@ -208,13 +208,6 @@ static const struct policydb_compat_info policydb_compat[] = {
 	 .ocon_num = OCON_IBENDPORT + 1,
 	 .target_platform = SEPOL_TARGET_SELINUX,
 	},
-	{
-	 .type = POLICY_KERN,
-	 .version = POLICYDB_VERSION_AVTAB_FTRANS,
-	 .sym_num = SYM_NUM,
-	 .ocon_num = OCON_IBENDPORT + 1,
-	 .target_platform = SEPOL_TARGET_SELINUX,
-	},
 	{
 	 .type = POLICY_BASE,
 	 .version = MOD_POLICYDB_VERSION_BASE,
@@ -4106,7 +4099,6 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
 		if (role_allow_read(&p->role_allow, fp))
 			goto bad;
 		if (r_policyvers >= POLICYDB_VERSION_FILENAME_TRANS &&
-		    r_policyvers < POLICYDB_VERSION_AVTAB_FTRANS &&
 		    avtab_filename_trans_read(fp, r_policyvers, &p->te_avtab))
 			goto bad;
 	} else {
libsepol/src/write.c +15 -71

116 lines not on this page · raw message

Signature · 1 line
2.41.0
#6 lore raw

PATCH 6/8 Revert "checkpolicy,libsepol: move filename transition rules to avrule"

In reply to James Carter

This reverts commit 565d87489bc00cab2e624aae1a40872d2a2232ba.

---
 checkpolicy/checkpolicy.c                  |   9 +
 checkpolicy/module_compiler.c              |  12 ++
 checkpolicy/module_compiler.h              |   1 +
 checkpolicy/policy_define.c                | 215 ++++++++++++++++++---
 checkpolicy/policy_define.h                |   3 +-
 checkpolicy/policy_parse.y                 |   8 +-
 checkpolicy/test/dismod.c                  |  25 ++-
 libsepol/cil/src/cil_binary.c              |   2 -
 libsepol/include/sepol/policydb/policydb.h |  16 +-
 libsepol/src/avrule_block.c                |   1 +
 libsepol/src/expand.c                      | 132 +++++++++----
 libsepol/src/link.c                        |  56 +++++-
 libsepol/src/module_to_cil.c               |  71 ++++++-
 libsepol/src/policydb.c                    |  70 +++++--
 libsepol/src/policydb_validate.c           |  27 +++
 libsepol/src/write.c                       |  86 ++++-----
 16 files changed, 580 insertions(+), 154 deletions(-)
checkpolicy/checkpolicy.c +9 -0
index 623ba8b2..83000bcb 100644
@@ -615,6 +615,15 @@ int main(int argc, char **argv)
 		parse_policy.mls = mlspol;
 		parse_policy.handle_unknown = handle_unknown;
 
+		/*
+		 * Init and alloc te_avtab for filename transition duplicate
+		 * checking
+		 */
+		if (avtab_init(&parse_policy.te_avtab))
+			exit(1);
+		if (avtab_alloc(&parse_policy.te_avtab, 1 << 11))
+			exit(1);
+
 		policydbp = &parse_policy;
 
 		if (read_source_policy(policydbp, file, "checkpolicy") < 0)
checkpolicy/module_compiler.c +12 -0
index 5fe1729a..3188af89 100644
@@ -1278,6 +1278,18 @@ void append_role_allow(role_allow_rule_t * role_allow_rules)
 	decl->role_allow_rules = role_allow_rules;
 }
 
+/* this doesn't actually append, but really prepends it */
+void append_filename_trans(filename_trans_rule_t * filename_trans_rules)
+{
+	avrule_decl_t *decl = stack_top->decl;
+
+	/* filename transitions are not allowed within conditionals */
+	assert(stack_top->type == 1);
+
+	filename_trans_rules->next = decl->filename_trans_rules;
+	decl->filename_trans_rules = filename_trans_rules;
+}
+
 /* this doesn't actually append, but really prepends it */
 void append_range_trans(range_trans_rule_t * range_tr_rules)
 {
checkpolicy/module_compiler.h +1 -0
index 6f8bb9b9..29b824b4 100644
@@ -83,6 +83,7 @@ void append_avrule(avrule_t * avrule);
 void append_role_trans(role_trans_rule_t * role_tr_rules);
 void append_role_allow(role_allow_rule_t * role_allow_rules);
 void append_range_trans(range_trans_rule_t * range_tr_rules);
+void append_filename_trans(filename_trans_rule_t * filename_trans_rules);
 
 /* Create a new optional block and add it to the global policy.
  * During the second pass resolve the block's requirements.  Return 0
checkpolicy/policy_define.c +192 -23

260 lines not on this page · raw message

checkpolicy/policy_define.h +2 -1
index 5d0f70e4..50a7ba78 100644
@@ -28,7 +28,7 @@ int define_default_role(int which);
 int define_default_type(int which);
 int define_default_range(int which);
 int define_common_perms(void);
-int define_compute_type(int which, int has_filename);
+int define_compute_type(int which);
 int define_conditional(cond_expr_t *expr, avrule_t *t_list, avrule_t *f_list );
 int define_constraint(constraint_expr_t *expr);
 int define_dominance(void);
@@ -57,6 +57,7 @@ int define_role_trans(int class_specified);
 int define_role_types(void);
 int define_role_attr(void);
 int define_roleattribute(void);
+int define_filename_trans(void);
 int define_sens(void);
 int define_te_avtab(int which);
 int define_te_avtab_extended_perms(int which);
checkpolicy/policy_parse.y +4 -4
index 2a14fc1e..da32a776 100644
@@ -451,13 +451,13 @@ cond_dontaudit_def	: DONTAUDIT names names ':' names names ';'
 		        ;
 			;
 transition_def		: TYPE_TRANSITION  names names ':' names identifier filename ';'
-			{if (define_compute_type(AVRULE_TRANSITION, 1)) return -1; }
+			{if (define_filename_trans()) return -1; }
 			| TYPE_TRANSITION names names ':' names identifier ';'
-                        {if (define_compute_type(AVRULE_TRANSITION, 0)) return -1;}
+                        {if (define_compute_type(AVRULE_TRANSITION)) return -1;}
                         | TYPE_MEMBER names names ':' names identifier ';'
-                        {if (define_compute_type(AVRULE_MEMBER, 0)) return -1;}
+                        {if (define_compute_type(AVRULE_MEMBER)) return -1;}
                         | TYPE_CHANGE names names ':' names identifier ';'
-                        {if (define_compute_type(AVRULE_CHANGE, 0)) return -1;}
+                        {if (define_compute_type(AVRULE_CHANGE)) return -1;}
     			;
 range_trans_def		: RANGE_TRANSITION names names mls_range_def ';'
 			{ if (define_range_trans(0)) return -1; }
checkpolicy/test/dismod.c +23 -2
index 8bab207c..fa7117f5 100644
@@ -50,6 +50,7 @@
 #define DISPLAY_AVBLOCK_ROLE_ALLOW	4
 #define DISPLAY_AVBLOCK_REQUIRES	5
 #define DISPLAY_AVBLOCK_DECLARES	6
+#define DISPLAY_AVBLOCK_FILENAME_TRANS	7
 
 static policydb_t policydb;
 
@@ -86,6 +87,7 @@ static struct command {
 	{CMD,       'c', "Display policy capabilities"},
 	{CMD|NOOPT, 'l', "Link in a module"},
 	{CMD,       'u', "Display the unknown handling setting"},
+	{CMD,       'F', "Display filename_trans rules"},
 	{CMD,       'v', "display the version of policy and/or module"},
 	{HEADER, 0, ""},
 	{CMD|NOOPT, 'f',  "set output file"},
@@ -343,8 +345,6 @@ static int display_avrule(avrule_t * avrule, policydb_t * policy,
 				   policy, fp);
 	} else if (avrule->specified & AVRULE_TYPE) {
 		display_id(policy, fp, SYM_TYPES, avrule->perms->data - 1, "");
-		if (avrule->object_name)
-			fprintf(fp, " \"%s\"", avrule->object_name);
 	} else if (avrule->specified & AVRULE_XPERMS) {
 		avtab_extended_perms_t xperms;
 		int i;
@@ -562,6 +562,18 @@ static void display_role_allow(role_allow_rule_t * ra, policydb_t * p, FILE * fp
 	}
 }
 
+static void display_filename_trans(filename_trans_rule_t * tr, policydb_t * p, FILE * fp)
+{
+	fprintf(fp, "filename transition");
+	for (; tr; tr = tr->next) {
+		display_type_set(&tr->stypes, 0, p, fp);
+		display_type_set(&tr->ttypes, 0, p, fp);
+		display_id(p, fp, SYM_CLASSES, tr->tclass - 1, ":");
+		display_id(p, fp, SYM_TYPES, tr->otype - 1, "");
+		fprintf(fp, " %s\n", tr->name);
+	}
+}
+
 static int role_display_callback(hashtab_key_t key __attribute__((unused)),
 			  hashtab_datum_t datum, void *data)
 {
@@ -726,6 +738,10 @@ static int display_avdecl(avrule_decl_t * decl, int field,
 			}
 			break;
 		}
+	case DISPLAY_AVBLOCK_FILENAME_TRANS:
+		display_filename_trans(decl->filename_trans_rules, policy,
+				       out_fp);
+		break;
 	default:{
 			assert(0);
 		}
@@ -1059,6 +1075,11 @@ int main(int argc, char **argv)
 			if (out_fp != stdout)
 				printf("\nOutput to file: %s\n", OutfileName);
 			break;
+		case 'F':
+			fprintf(out_fp, "filename_trans rules:\n");
+			display_avblock(DISPLAY_AVBLOCK_FILENAME_TRANS,
+					&policydb, out_fp);
+			break;
 		case 'l':
 			link_module(&policydb, out_fp, ops? 0: 1);
 			break;
libsepol/cil/src/cil_binary.c +0 -2
index 996bad70..7150d405 100644
@@ -4650,7 +4650,6 @@ static avrule_t *__cil_init_sepol_avrule(uint32_t kind, struct cil_tree_node *no
 	__cil_init_sepol_type_set(&avrule->stypes);
 	__cil_init_sepol_type_set(&avrule->ttypes);
 	avrule->perms = NULL;
-	avrule->object_name = NULL;
 	avrule->line = node->line;
 
 	avrule->source_filename = NULL;
@@ -4677,7 +4676,6 @@ static void __cil_destroy_sepol_avrules(avrule_t *curr)
 		ebitmap_destroy(&curr->stypes.negset);
 		ebitmap_destroy(&curr->ttypes.types);
 		ebitmap_destroy(&curr->ttypes.negset);
-		free(curr->object_name);
 		__cil_destroy_sepol_class_perms(curr->perms);
 		free(curr);
 		curr = next;
libsepol/include/sepol/policydb/policydb.h +15 -1
index d30f26af..8bb11d18 100644
@@ -278,7 +278,6 @@ typedef struct avrule {
 	type_set_t stypes;
 	type_set_t ttypes;
 	class_perm_node_t *perms;
-	char *object_name;	/* optional object name */
 	av_extended_perms_t *xperms;
 	unsigned long line;	/* line number from policy.conf where
 				 * this rule originated  */
@@ -302,6 +301,16 @@ typedef struct role_allow_rule {
 	struct role_allow_rule *next;
 } role_allow_rule_t;
 
+typedef struct filename_trans_rule {
+	uint32_t flags; /* may have RULE_SELF set */
+	type_set_t stypes;
+	type_set_t ttypes;
+	uint32_t tclass;
+	char *name;
+	uint32_t otype;	/* new type */
+	struct filename_trans_rule *next;
+} filename_trans_rule_t;
+
 typedef struct range_trans_rule {
 	type_set_t stypes;
 	type_set_t ttypes;
@@ -442,6 +451,9 @@ typedef struct avrule_decl {
 	scope_index_t required;	/* symbols needed to activate this block */
 	scope_index_t declared;	/* symbols declared within this block */
 
+	/* type transition rules with a 'name' component */
+	filename_trans_rule_t *filename_trans_rules;
+
 	/* for additive statements (type attribute, roles, and users) */
 	symtab_t symtab[SYM_NUM];
 
@@ -644,6 +656,8 @@ extern void avrule_destroy(avrule_t * x);
 extern void avrule_list_destroy(avrule_t * x);
 extern void role_trans_rule_init(role_trans_rule_t * x);
 extern void role_trans_rule_list_destroy(role_trans_rule_t * x);
+extern void filename_trans_rule_init(filename_trans_rule_t * x);
+extern void filename_trans_rule_list_destroy(filename_trans_rule_t * x);
 
 extern void role_datum_init(role_datum_t * x);
 extern void role_datum_destroy(role_datum_t * x);
libsepol/src/avrule_block.c +1 -0
index fce4e772..dcfce8b8 100644
@@ -99,6 +99,7 @@ void avrule_decl_destroy(avrule_decl_t * x)
 	cond_list_destroy(x->cond_list);
 	avrule_list_destroy(x->avrules);
 	role_trans_rule_list_destroy(x->role_tr_rules);
+	filename_trans_rule_list_destroy(x->filename_trans_rules);
 	role_allow_rule_list_destroy(x->role_allow_rules);
 	range_trans_rule_list_destroy(x->range_tr_rules);
 	scope_index_destroy(&x->required);
libsepol/src/expand.c +98 -34

174 lines not on this page · raw message

libsepol/src/link.c +50 -6

74 lines not on this page · raw message

libsepol/src/module_to_cil.c +62 -9

107 lines not on this page · raw message

libsepol/src/policydb.c +50 -20

126 lines not on this page · raw message

libsepol/src/policydb_validate.c +27 -0
index 0b8e8eee..89306185 100644
@@ -1313,6 +1313,31 @@ bad:
 	return -1;
 }
 
+
+static int validate_filename_trans_rules(sepol_handle_t *handle, const filename_trans_rule_t *filename_trans, const policydb_t *p, validate_t flavors[])
+{
+	for (; filename_trans; filename_trans = filename_trans->next) {
+		if (validate_type_set(&filename_trans->stypes, &flavors[SYM_TYPES]))
+			goto bad;
+		if (validate_type_set(&filename_trans->ttypes, &flavors[SYM_TYPES]))
+			goto bad;
+		if (validate_value(filename_trans->tclass,&flavors[SYM_CLASSES] ))
+			goto bad;
+		if (validate_simpletype(filename_trans->otype, p, flavors))
+			goto bad;
+
+		/* currently only the RULE_SELF flag can be set */
+		if ((filename_trans->flags & ~RULE_SELF) != 0)
+			goto bad;
+	}
+
+	return 0;
+
+bad:
+	ERR(handle, "Invalid filename trans rule list");
+	return -1;
+}
+
 static int validate_symtabs(sepol_handle_t *handle, const symtab_t symtabs[], validate_t flavors[])
 {
 	unsigned int i;
@@ -1347,6 +1372,8 @@ static int validate_avrule_blocks(sepol_handle_t *handle, const avrule_block_t *
 				goto bad;
 			if (validate_scope_index(handle, &decl->declared, flavors))
 				goto bad;
+			if (validate_filename_trans_rules(handle, decl->filename_trans_rules, p, flavors))
+				goto bad;
 			if (validate_symtabs(handle, decl->symtab, flavors))
 				goto bad;
 		}
libsepol/src/write.c +34 -52

127 lines not on this page · raw message

Signature · 1 line
2.41.0
#7 lore raw

PATCH 7/8 Revert "checkpolicy,libsepol: move filename transitions to avtab"

In reply to James Carter

This reverts commit e169fe26530ef2c6b3dd126788cc81676359a3b3.

---
 checkpolicy/checkmodule.c                  |   9 -
 checkpolicy/checkpolicy.c                  |   9 -
 checkpolicy/policy_define.c                |  21 +-
 checkpolicy/test/dispol.c                  |  83 ++--
 libsepol/cil/src/cil_binary.c              |  27 +-
 libsepol/include/sepol/policydb/avtab.h    |   9 -
 libsepol/include/sepol/policydb/hashtab.h  |   8 -
 libsepol/include/sepol/policydb/policydb.h |  22 +
 libsepol/src/avtab.c                       | 199 ---------
 libsepol/src/conditional.c                 |   6 +-
 libsepol/src/expand.c                      |  27 +-
 libsepol/src/kernel_to_cil.c               | 159 +++++--
 libsepol/src/kernel_to_common.h            |   9 -
 libsepol/src/kernel_to_conf.c              | 155 +++++--
 libsepol/src/optimize.c                    |   8 +-
 libsepol/src/policydb.c                    | 343 ++++++++++++++-
 libsepol/src/policydb_validate.c           |  69 +--
 libsepol/src/write.c                       | 463 ++++++---------------
 18 files changed, 822 insertions(+), 804 deletions(-)
checkpolicy/checkmodule.c +0 -9
index d81d8c97..14e6c891 100644
@@ -280,15 +280,6 @@ int main(int argc, char **argv)
 		modpolicydb.mls = mlspol;
 		modpolicydb.handle_unknown = handle_unknown;
 
-		/*
-		 * Init and alloc te_avtab for filename transition duplicate
-		 * checking
-		 */
-		if (avtab_init(&modpolicydb.te_avtab))
-			exit(1);
-		if (avtab_alloc(&modpolicydb.te_avtab, 1 << 11))
-			exit(1);
-
 		if (read_source_policy(&modpolicydb, file, argv[0]) == -1) {
 			exit(1);
 		}
checkpolicy/checkpolicy.c +0 -9
index 83000bcb..623ba8b2 100644
@@ -615,15 +615,6 @@ int main(int argc, char **argv)
 		parse_policy.mls = mlspol;
 		parse_policy.handle_unknown = handle_unknown;
 
-		/*
-		 * Init and alloc te_avtab for filename transition duplicate
-		 * checking
-		 */
-		if (avtab_init(&parse_policy.te_avtab))
-			exit(1);
-		if (avtab_alloc(&parse_policy.te_avtab, 1 << 11))
-			exit(1);
-
 		policydbp = &parse_policy;
 
 		if (read_source_policy(policydbp, file, "checkpolicy") < 0)
checkpolicy/policy_define.c +6 -15
index dc2ee8f3..cef8f3c4 100644
@@ -3352,7 +3352,6 @@ int define_filename_trans(void)
 	ebitmap_node_t *snode, *tnode, *cnode;
 	filename_trans_rule_t *ftr;
 	type_datum_t *typdatum;
-	avtab_key_t avt_key;
 	uint32_t otype;
 	unsigned int c, s, t;
 	int add, self, rc;
@@ -3444,13 +3443,9 @@ int define_filename_trans(void)
 	ebitmap_for_each_positive_bit(&e_tclasses, cnode, c) {
 		ebitmap_for_each_positive_bit(&e_stypes, snode, s) {
 			ebitmap_for_each_positive_bit(&e_ttypes, tnode, t) {
-				avt_key.specified = AVTAB_TRANSITION;
-				avt_key.source_type = s + 1;
-				avt_key.target_type = t + 1;
-				avt_key.target_class = c + 1;
-				rc = avtab_insert_filename_trans(
-					&policydbp->te_avtab, &avt_key, otype,
-					name, NULL
+				rc = policydb_filetrans_insert(
+					policydbp, s+1, t+1, c+1, name,
+					NULL, otype, NULL
 				);
 				if (rc != SEPOL_OK) {
 					if (rc == SEPOL_EEXIST) {
@@ -3466,13 +3461,9 @@ int define_filename_trans(void)
 				}
 			}
 			if (self) {
-				avt_key.specified = AVTAB_TRANSITION;
-				avt_key.source_type = s + 1;
-				avt_key.target_type = t + 1;
-				avt_key.target_class = c + 1;
-				rc = avtab_insert_filename_trans(
-					&policydbp->te_avtab, &avt_key, otype,
-					name, NULL
+				rc = policydb_filetrans_insert(
+					policydbp, s+1, s+1, c+1, name,
+					NULL, otype, NULL
 				);
 				if (rc != SEPOL_OK) {
 					if (rc == SEPOL_EEXIST) {
checkpolicy/test/dispol.c +50 -33

113 lines not on this page · raw message

libsepol/cil/src/cil_binary.c +7 -20
index 7150d405..3f264594 100644
@@ -1005,12 +1005,7 @@ static int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src,
 	}
 	
 	existing = avtab_search_node(&pdb->te_avtab, &avtab_key);
-	/*
-	 * There might be empty transition node containing filename transitions
-	 * only. That is okay, we can merge them later.
-	 */
-	if (existing && !(existing->key.specified & AVTAB_TRANSITION &&
-	    !existing->datum.trans->otype)) {
+	if (existing) {
 		/* Don't add duplicate type rule and warn if they conflict.
 		 * A warning should have been previously given if there is a
 		 * non-duplicate rule using the same key.
@@ -1034,13 +1029,7 @@ static int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src,
 	}
 
 	if (!cond_node) {
-		/* If we have node from empty filename transition, use it */
-		if (existing && existing->key.specified & AVTAB_TRANSITION &&
-		    !existing->datum.trans->otype)
-			existing->datum.trans->otype = avtab_datum.trans->otype;
-		else
-			rc = avtab_insert(&pdb->te_avtab, &avtab_key,
-					  &avtab_datum);
+		rc = avtab_insert(&pdb->te_avtab, &avtab_key, &avtab_datum);
 	} else {
 		existing = avtab_search_node(&pdb->te_cond_avtab, &avtab_key);
 		if (existing) {
@@ -1200,18 +1189,16 @@ static int __cil_typetransition_to_avtab_helper(policydb_t *pdb,
 	class_datum_t *sepol_obj = NULL;
 	uint32_t otype;
 	struct cil_list_item *c;
-	avtab_key_t avt_key;
 
 	cil_list_for_each(c, class_list) {
 		rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj);
 		if (rc != SEPOL_OK) return rc;
 
-		avt_key.specified = AVTAB_TRANSITION;
-		avt_key.source_type = sepol_src->s.value;
-		avt_key.target_type = sepol_tgt->s.value;
-		avt_key.target_class = sepol_obj->s.value;
-		rc = avtab_insert_filename_trans(&pdb->te_avtab, &avt_key,
-			sepol_result->s.value, name, &otype);
+		rc = policydb_filetrans_insert(
+			pdb, sepol_src->s.value, sepol_tgt->s.value,
+			sepol_obj->s.value, name, NULL,
+			sepol_result->s.value, &otype
+		);
 		if (rc != SEPOL_OK) {
 			if (rc == SEPOL_EEXIST) {
 				if (sepol_result->s.value!= otype) {
libsepol/include/sepol/policydb/avtab.h +0 -9
index 5dc720cc..ca009c16 100644
@@ -42,7 +42,6 @@
 
 #include <sys/types.h>
 #include <stdint.h>
-#include <sepol/policydb/symtab.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -73,7 +72,6 @@ typedef struct avtab_key {
 
 typedef struct avtab_trans {
 	uint32_t otype;		/* resulting type of the new object */
-	symtab_t name_trans;	/* filename transitions */
 } avtab_trans_t;
 
 typedef struct avtab_extended_perms {
@@ -117,8 +115,6 @@ extern int avtab_insert(avtab_t * h, avtab_key_t * k, avtab_datum_t * d);
 
 extern avtab_datum_t *avtab_search(avtab_t * h, avtab_key_t * k);
 
-extern void avtab_trans_destroy(avtab_trans_t *trans);
-
 extern void avtab_destroy(avtab_t * h);
 
 extern int avtab_map(const avtab_t * h,
@@ -152,11 +148,6 @@ extern avtab_ptr_t avtab_search_node_next(avtab_ptr_t node, int specified);
 /* avtab_alloc uses one bucket per 2-4 elements, so adjust to get maximum buckets */
 #define MAX_AVTAB_SIZE (MAX_AVTAB_HASH_BUCKETS << 1)
 
-extern int avtab_insert_filename_trans(avtab_t *a, avtab_key_t *key,
-				       uint32_t otype, const char *name,
-				       uint32_t *present_otype);
-extern int avtab_filename_trans_read(void *fp, uint32_t vers, avtab_t *a);
-
 #ifdef __cplusplus
 }
 #endif
libsepol/include/sepol/policydb/hashtab.h +0 -8
index 354ebb43..dca8c983 100644
@@ -110,14 +110,6 @@ extern int hashtab_map(hashtab_t h,
 
 extern void hashtab_hash_eval(hashtab_t h, char *tag);
 
-/* Returns number of elements in the hashtab h or 0 is h is NULL */
-static inline uint32_t hashtab_nel(hashtab_t h)
-{
-	if (!h)
-		return 0;
-	return h->nel;
-}
-
 #ifdef __cplusplus
 }
 #endif
libsepol/include/sepol/policydb/policydb.h +22 -0
index 8bb11d18..b014b7a8 100644
@@ -161,6 +161,19 @@ typedef struct role_allow {
 	struct role_allow *next;
 } role_allow_t;
 
+/* filename_trans rules */
+typedef struct filename_trans_key {
+	uint32_t ttype;
+	uint32_t tclass;
+	char *name;
+} filename_trans_key_t;
+
+typedef struct filename_trans_datum {
+	ebitmap_t stypes;
+	uint32_t otype;
+	struct filename_trans_datum *next;
+} filename_trans_datum_t;
+
 /* Type attributes */
 typedef struct type_datum {
 	symtab_datum_t s;
@@ -579,6 +592,10 @@ typedef struct policydb {
 	/* range transitions table (range_trans_key -> mls_range) */
 	hashtab_t range_tr;
 
+	/* file transitions with the last path component */
+	hashtab_t filename_trans;
+	uint32_t filename_trans_count;
+
 	ebitmap_t *type_attr_map;
 
 	ebitmap_t *attr_type_map;	/* not saved in the binary policy */
@@ -637,6 +654,11 @@ extern int policydb_load_isids(policydb_t * p, sidtab_t * s);
 
 extern int policydb_sort_ocontexts(policydb_t *p);
 
+extern int policydb_filetrans_insert(policydb_t *p, uint32_t stype,
+				     uint32_t ttype, uint32_t tclass,
+				     const char *name, char **name_alloc,
+				     uint32_t otype, uint32_t *present_otype);
+
 /* Deprecated */
 extern int policydb_context_isvalid(const policydb_t * p,
 				    const context_struct_t * c);
libsepol/src/avtab.c +0 -199

214 lines not on this page · raw message

libsepol/src/conditional.c +1 -5
index 7900e928..24380ea0 100644
@@ -624,7 +624,6 @@ static int cond_insertf(avtab_t * a
 	struct policydb *p = data->p;
 	cond_av_list_t *other = data->other, *list, *cur;
 	avtab_ptr_t node_ptr;
-	avtab_datum_t *existing;
 	uint8_t found;
 
 	/*
@@ -633,10 +632,7 @@ static int cond_insertf(avtab_t * a
 	 * cond_te_avtab.
 	 */
 	if (k->specified & AVTAB_TYPE) {
-		existing = avtab_search(&p->te_avtab, k);
-		/* empty transition rule is not a conflict */
-		if (existing && !(k->specified & AVTAB_TRANSITION
-		    && !existing->trans->otype)) {
+		if (avtab_search(&p->te_avtab, k)) {
 			WARN(NULL, "security: type rule already exists outside of a conditional.");
 			return -1;
 		}
libsepol/src/expand.c +5 -22
index 878b0f21..6793a27d 100644
@@ -1413,17 +1413,14 @@ static int expand_filename_trans_helper(expand_state_t *state,
 {
 	uint32_t mapped_otype, present_otype;
 	int rc;
-	avtab_key_t avt_key;
 
 	mapped_otype = state->typemap[rule->otype - 1];
 
-	avt_key.specified = AVTAB_TRANSITION;
-	avt_key.source_type = s + 1;
-	avt_key.target_type = t + 1;
-	avt_key.target_class = rule->tclass;
-
-	rc = avtab_insert_filename_trans(&state->out->te_avtab, &avt_key,
-		mapped_otype, rule->name, &present_otype);
+	rc = policydb_filetrans_insert(
+		state->out, s + 1, t + 1,
+		rule->tclass, rule->name,
+		NULL, mapped_otype, &present_otype
+	);
 	if (rc == SEPOL_EEXIST) {
 		/* duplicate rule, ignore */
 		if (present_otype == mapped_otype)
@@ -1737,16 +1734,6 @@ static int expand_terule_helper(sepol_handle_t * handle,
 		 * either in the global scope or in another
 		 * conditional AV tab */
 		node = avtab_search_node(&p->te_avtab, &avkey);
-
-		/*
-		 * if node does not already contain transition, it is not a
-		 * conflict and transition otype will be set to node found by
-		 * find_avtab_node()
-		 */
-		if (specified & AVRULE_TRANSITION && node &&
-		    !node->datum.trans->otype)
-			node = NULL;
-
 		if (node) {
 			conflict = 1;
 		} else {
@@ -1754,10 +1741,6 @@ static int expand_terule_helper(sepol_handle_t * handle,
 			if (node && node->parse_context != other) {
 				conflict = 2;
 			}
-			/*
-			 * conditional avtab does not contain filename
-			 * transitions, no need to check for otype == 0
-			 */
 		}
 
 		if (conflict) {
libsepol/src/kernel_to_cil.c +116 -43

229 lines not on this page · raw message

libsepol/src/kernel_to_common.h +0 -9
index b8ea237d..9e567eb8 100644
@@ -83,15 +83,6 @@ struct strs {
 	size_t size;
 };
 
-typedef struct {
-	policydb_t *pdb;
-	struct strs *strs;
-	const char *flavor;
-	const char *src;
-	const char *tgt;
-	const char *class;
-} name_trans_to_strs_args_t;
-
 void sepol_indent(FILE *out, int indent);
 __attribute__ ((format(printf, 2, 3)))
 void sepol_printf(FILE *out, const char *fmt, ...);
libsepol/src/kernel_to_conf.c +112 -43

223 lines not on this page · raw message

libsepol/src/optimize.c +2 -6
index 7948d983..2d4a2d7a 100644
@@ -308,10 +308,8 @@ static void optimize_avtab(policydb_t *p, const struct type_vec *type_map)
 				*cur = tmp->next;
 				if (tmp->key.specified & AVTAB_XPERMS)
 					free(tmp->datum.xperms);
-				if (tmp->key.specified & AVTAB_TRANSITION) {
-					avtab_trans_destroy(tmp->datum.trans);
+				if (tmp->key.specified & AVTAB_TRANSITION)
 					free(tmp->datum.trans);
-				}
 				free(tmp);
 
 				tab->nel--;
@@ -431,10 +429,8 @@ static void optimize_cond_avtab(policydb_t *p, const struct type_vec *type_map)
 				*cur = tmp->next;
 				if (tmp->key.specified & AVTAB_XPERMS)
 					free(tmp->datum.xperms);
-				if (tmp->key.specified & AVTAB_TRANSITION) {
-					avtab_trans_destroy(tmp->datum.trans);
+				if (tmp->key.specified & AVTAB_TRANSITION)
 					free(tmp->datum.trans);
-				}
 				free(tmp);
 
 				tab->nel--;
libsepol/src/policydb.c +342 -1

385 lines not on this page · raw message

libsepol/src/policydb_validate.c +41 -28

94 lines not on this page · raw message

libsepol/src/write.c +118 -345

500 lines not on this page · raw message

Signature · 1 line
2.41.0
#8 lore raw

PATCH 8/8 Revert "checkpolicy,libsepol: move transition to separate structure in avtab"

In reply to James Carter

This reverts commit de708edf527be7e5142e5a9ae09879d58d65f50b.

---
 checkpolicy/test/dispol.c               |  2 +-
 libsepol/cil/src/cil_binary.c           | 26 +++++---------------
 libsepol/include/sepol/policydb/avtab.h |  7 +-----
 libsepol/src/avtab.c                    | 32 +------------------------
 libsepol/src/expand.c                   |  8 ++-----
 libsepol/src/kernel_to_cil.c            |  3 +--
 libsepol/src/kernel_to_conf.c           |  3 +--
 libsepol/src/optimize.c                 |  4 ----
 libsepol/src/policydb_validate.c        |  4 +---
 libsepol/src/services.c                 |  5 +---
 libsepol/src/write.c                    | 17 +++----------
 11 files changed, 18 insertions(+), 93 deletions(-)
checkpolicy/test/dispol.c +1 -1
index e45528b9..b567ce77 100644
@@ -180,7 +180,7 @@ static int render_av_rule(avtab_key_t * key, avtab_datum_t * datum, uint32_t wha
 		if (key->specified & AVTAB_TRANSITION) {
 			fprintf(fp, "type_transition ");
 			render_key(key, p, fp);
-			render_type(datum->trans->otype, p, fp);
+			render_type(datum->data, p, fp);
 			fprintf(fp, ";\n");
 		}
 		if (key->specified & AVTAB_MEMBER) {
libsepol/cil/src/cil_binary.c +6 -20
index 3f264594..c4ee2380 100644
@@ -975,34 +975,28 @@ static int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src,
 	int rc = SEPOL_OK;
 	avtab_key_t avtab_key;
 	avtab_datum_t avtab_datum;
-	avtab_trans_t trans;
 	avtab_ptr_t existing;	
 
 	avtab_key.source_type = src;
 	avtab_key.target_type = tgt;
 	avtab_key.target_class = obj;
 
-	memset(&avtab_datum, 0, sizeof(avtab_datum_t));
-	memset(&trans, 0, sizeof(avtab_trans_t));
-
 	switch (kind) {
 	case CIL_TYPE_TRANSITION:
 		avtab_key.specified = AVTAB_TRANSITION;
-		trans.otype = res;
-		avtab_datum.trans = &trans;
 		break;
 	case CIL_TYPE_CHANGE:
 		avtab_key.specified = AVTAB_CHANGE;
-		avtab_datum.data = res;
 		break;
 	case CIL_TYPE_MEMBER:
 		avtab_key.specified = AVTAB_MEMBER;
-		avtab_datum.data = res;
 		break;
 	default:
 		rc = SEPOL_ERR;
 		goto exit;
 	}
+
+	avtab_datum.data = res;
 	
 	existing = avtab_search_node(&pdb->te_avtab, &avtab_key);
 	if (existing) {
@@ -1010,17 +1004,13 @@ static int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src,
 		 * A warning should have been previously given if there is a
 		 * non-duplicate rule using the same key.
 		 */
-		uint32_t existing_otype =
-			existing->key.specified & AVTAB_TRANSITION
-			? existing->datum.trans->otype
-			: existing->datum.data;
-		if (existing_otype != res) {
+		if (existing->datum.data != res) {
 			cil_log(CIL_ERR, "Conflicting type rules (scontext=%s tcontext=%s tclass=%s result=%s), existing=%s\n",
 				pdb->p_type_val_to_name[src - 1],
 				pdb->p_type_val_to_name[tgt - 1],
 				pdb->p_class_val_to_name[obj - 1],
 				pdb->p_type_val_to_name[res - 1],
-				pdb->p_type_val_to_name[existing_otype - 1]);
+				pdb->p_type_val_to_name[existing->datum.data - 1]);
 			cil_log(CIL_ERR, "Expanded from type rule (scontext=%s tcontext=%s tclass=%s result=%s)\n",
 				cil_rule->src_str, cil_rule->tgt_str, cil_rule->obj_str, cil_rule->result_str);
 			rc = SEPOL_ERR;
@@ -1047,17 +1037,13 @@ static int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src,
 
 			search_datum = cil_cond_av_list_search(&avtab_key, other_list);
 			if (search_datum == NULL) {
-				uint32_t existing_otype =
-					existing->key.specified & AVTAB_TRANSITION
-					? existing->datum.trans->otype
-					: existing->datum.data;
-				if (existing_otype != res) {
+				if (existing->datum.data != res) {
 					cil_log(CIL_ERR, "Conflicting type rules (scontext=%s tcontext=%s tclass=%s result=%s), existing=%s\n",
 						pdb->p_type_val_to_name[src - 1],
 						pdb->p_type_val_to_name[tgt - 1],
 						pdb->p_class_val_to_name[obj - 1],
 						pdb->p_type_val_to_name[res - 1],
-						pdb->p_type_val_to_name[existing_otype - 1]);
+						pdb->p_type_val_to_name[existing->datum.data - 1]);
 					cil_log(CIL_ERR, "Expanded from type rule (scontext=%s tcontext=%s tclass=%s result=%s)\n",
 						cil_rule->src_str, cil_rule->tgt_str, cil_rule->obj_str, cil_rule->result_str);
 					rc = SEPOL_ERR;
libsepol/include/sepol/policydb/avtab.h +1 -6
index ca009c16..e4c48576 100644
@@ -70,10 +70,6 @@ typedef struct avtab_key {
 	uint16_t specified;	/* what fields are specified */
 } avtab_key_t;
 
-typedef struct avtab_trans {
-	uint32_t otype;		/* resulting type of the new object */
-} avtab_trans_t;
-
 typedef struct avtab_extended_perms {
 
 #define AVTAB_XPERMS_IOCTLFUNCTION	0x01
@@ -85,8 +81,7 @@ typedef struct avtab_extended_perms {
 } avtab_extended_perms_t;
 
 typedef struct avtab_datum {
-	uint32_t data;		/* access vector, member or change value */
-	avtab_trans_t *trans;	/* transition value */
+	uint32_t data;		/* access vector or type */
 	avtab_extended_perms_t *xperms;
 } avtab_datum_t;
 
libsepol/src/avtab.c +1 -31
index 4c292e8b..82fec783 100644
@@ -94,7 +94,6 @@ avtab_insert_node(avtab_t * h, int hvalue, avtab_ptr_t prev, avtab_key_t * key,
 		  avtab_datum_t * datum)
 {
 	avtab_ptr_t newnode;
-	avtab_trans_t *trans;
 	avtab_extended_perms_t *xperms;
 
 	newnode = (avtab_ptr_t) malloc(sizeof(struct avtab_node));
@@ -118,16 +117,6 @@ avtab_insert_node(avtab_t * h, int hvalue, avtab_ptr_t prev, avtab_key_t * key,
 		 * So copy data so it is set in the avtab
 		 */
 		newnode->datum.data = datum->data;
-	} else if (key->specified & AVTAB_TRANSITION) {
-		trans = calloc(1, sizeof(*trans));
-		if (trans == NULL) {
-			free(newnode);
-			return NULL;
-		}
-		if (datum->trans) /* else caller populates transition */
-			*trans = *(datum->trans);
-
-		newnode->datum.trans = trans;
 	} else {
 		newnode->datum = *datum;
 	}
@@ -328,8 +317,6 @@ void avtab_destroy(avtab_t * h)
 		while (cur != NULL) {
 			if (cur->key.specified & AVTAB_XPERMS) {
 				free(cur->datum.xperms);
-			} else if (cur->key.specified & AVTAB_TRANSITION) {
-				free(cur->datum.trans);
 			}
 			temp = cur;
 			cur = cur->next;
@@ -453,7 +440,6 @@ int avtab_read_item(struct policy_file *fp, uint32_t vers, avtab_t * a,
 	uint32_t buf32[8], items, items2, val;
 	avtab_key_t key;
 	avtab_datum_t datum;
-	avtab_trans_t trans;
 	avtab_extended_perms_t xperms;
 	unsigned set;
 	unsigned int i;
@@ -461,7 +447,6 @@ int avtab_read_item(struct policy_file *fp, uint32_t vers, avtab_t * a,
 
 	memset(&key, 0, sizeof(avtab_key_t));
 	memset(&datum, 0, sizeof(avtab_datum_t));
-	memset(&trans, 0, sizeof(avtab_trans_t));
 	memset(&xperms, 0, sizeof(avtab_extended_perms_t));
 
 	if (vers < POLICYDB_VERSION_AVTAB) {
@@ -524,14 +509,7 @@ int avtab_read_item(struct policy_file *fp, uint32_t vers, avtab_t * a,
 					return -1;
 				}
 				key.specified = spec_order[i] | enabled;
-				if (key.specified & AVTAB_TRANSITION) {
-					trans.otype =
-						le32_to_cpu(buf32[items++]);
-					datum.trans = &trans;
-				} else {
-					datum.data =
-						le32_to_cpu(buf32[items++]);
-				}
+				datum.data = le32_to_cpu(buf32[items++]);
 				rc = insertf(a, &key, &datum, p);
 				if (rc)
 					return rc;
@@ -593,14 +571,6 @@ int avtab_read_item(struct policy_file *fp, uint32_t vers, avtab_t * a,
 		for (i = 0; i < ARRAY_SIZE(xperms.perms); i++)
 			xperms.perms[i] = le32_to_cpu(buf32[i]);
 		datum.xperms = &xperms;
-	} else if (key.specified & AVTAB_TRANSITION) {
-		rc = next_entry(buf32, fp, sizeof(uint32_t));
-		if (rc < 0) {
-			ERR(fp->handle, "truncated entry");
-			return -1;
-		}
-		trans.otype = le32_to_cpu(*buf32);
-		datum.trans = &trans;
 	} else {
 		rc = next_entry(buf32, fp, sizeof(uint32_t));
 		if (rc < 0) {
libsepol/src/expand.c +2 -6
index 6793a27d..8795229a 100644
@@ -1746,7 +1746,7 @@ static int expand_terule_helper(sepol_handle_t * handle,
 		if (conflict) {
 			avdatump = &node->datum;
 			if (specified & AVRULE_TRANSITION) {
-				oldtype = avdatump->trans->otype;
+				oldtype = avdatump->data;
 			} else if (specified & AVRULE_MEMBER) {
 				oldtype = avdatump->data;
 			} else if (specified & AVRULE_CHANGE) {
@@ -1789,11 +1789,7 @@ static int expand_terule_helper(sepol_handle_t * handle,
 		}
 
 		avdatump = &node->datum;
-		if (specified & AVRULE_TRANSITION) {
-			avdatump->trans->otype = remapped_data;
-		} else {
-			avdatump->data = remapped_data;
-		}
+		avdatump->data = remapped_data;
 
 		cur = cur->next;
 	}
libsepol/src/kernel_to_cil.c +1 -2
index 316679cc..8fcc385d 100644
@@ -1702,8 +1702,7 @@ static char *xperms_to_str(avtab_extended_perms_t *xperms)
 
 static char *avtab_node_to_str(struct policydb *pdb, avtab_key_t *key, avtab_datum_t *datum)
 {
-	uint32_t data = key->specified & AVTAB_TRANSITION
-		? datum->trans->otype : datum->data;
+	uint32_t data = datum->data;
 	type_datum_t *type;
 	const char *flavor, *tgt;
 	char *src, *class, *perms, *new;
libsepol/src/kernel_to_conf.c +1 -2
index aa161b08..b0ae16d9 100644
@@ -1680,8 +1680,7 @@ exit:
 
 static char *avtab_node_to_str(struct policydb *pdb, avtab_key_t *key, avtab_datum_t *datum)
 {
-	uint32_t data = key->specified & AVTAB_TRANSITION
-		? datum->trans->otype : datum->data;
+	uint32_t data = datum->data;
 	type_datum_t *type;
 	const char *flavor, *src, *tgt, *class, *perms, *new;
 	char *rule = NULL;
libsepol/src/optimize.c +0 -4
index 2d4a2d7a..a38025ec 100644
@@ -308,8 +308,6 @@ static void optimize_avtab(policydb_t *p, const struct type_vec *type_map)
 				*cur = tmp->next;
 				if (tmp->key.specified & AVTAB_XPERMS)
 					free(tmp->datum.xperms);
-				if (tmp->key.specified & AVTAB_TRANSITION)
-					free(tmp->datum.trans);
 				free(tmp);
 
 				tab->nel--;
@@ -429,8 +427,6 @@ static void optimize_cond_avtab(policydb_t *p, const struct type_vec *type_map)
 				*cur = tmp->next;
 				if (tmp->key.specified & AVTAB_XPERMS)
 					free(tmp->datum.xperms);
-				if (tmp->key.specified & AVTAB_TRANSITION)
-					free(tmp->datum.trans);
 				free(tmp);
 
 				tab->nel--;
libsepol/src/policydb_validate.c +1 -3
index f402b506..3540f34a 100644
@@ -836,9 +836,7 @@ static int validate_avtab_key_and_datum(avtab_key_t *k, avtab_datum_t *d, void *
 	if (validate_avtab_key(k, 0, margs->policy, margs->flavors))
 		return -1;
 
-	uint32_t otype = k->specified & AVTAB_TRANSITION
-		? d->trans->otype : d->data;
-	if ((k->specified & AVTAB_TYPE) && validate_simpletype(otype, margs->policy, margs->flavors))
+	if ((k->specified & AVTAB_TYPE) && validate_simpletype(d->data, margs->policy, margs->flavors))
 		return -1;
 
 	if ((k->specified & AVTAB_XPERMS) && validate_xperms(d->xperms))
libsepol/src/services.c +1 -4
index 6bddc287..07ae051b 100644
@@ -1423,10 +1423,7 @@ static int sepol_compute_sid(sepol_security_id_t ssid,
 
 	if (avdatum) {
 		/* Use the type from the type transition/member/change rule. */
-		if (specified & AVTAB_TRANSITION)
-			newcontext.type = avdatum->trans->otype;
-		else
-			newcontext.type = avdatum->data;
+		newcontext.type = avdatum->data;
 	}
 
 	/* Check for class-specific changes. */
libsepol/src/write.c +3 -14
index 0d3d5f14..024fe628 100644
@@ -190,20 +190,14 @@ static int avtab_write_item(policydb_t * p,
 						ERR(fp->handle, "missing node");
 						return POLICYDB_ERROR;
 					}
-					uint32_t data =
-						node->key.specified & AVTAB_TRANSITION
-						? node->datum.trans->otype
-						: node->datum.data;
-					buf32[items++] = cpu_to_le32(data);
+					buf32[items++] =
+					    cpu_to_le32(node->datum.data);
 					set--;
 					node->merged = 1;
 				}
 			}
 		} else {
-			uint32_t data = cur->key.specified & AVTAB_TRANSITION
-				? cur->datum.trans->otype
-				: cur->datum.data;
-			buf32[items++] = cpu_to_le32(data);
+			buf32[items++] = cpu_to_le32(cur->datum.data);
 			cur->merged = 1;
 			set--;
 		}
@@ -262,11 +256,6 @@ static int avtab_write_item(policydb_t * p,
 		items = put_entry(buf32, sizeof(uint32_t),8,fp);
 		if (items != 8)
 			return POLICYDB_ERROR;
-	} else if (cur->key.specified & AVTAB_TRANSITION) {
-		buf32[0] = cpu_to_le32(cur->datum.trans->otype);
-		items = put_entry(buf32, sizeof(uint32_t), 1, fp);
-		if (items != 1)
-			return POLICYDB_ERROR;
 	} else {
 		buf32[0] = cpu_to_le32(cur->datum.data);
 		items = put_entry(buf32, sizeof(uint32_t), 1, fp);
Signature · 1 line
2.41.0
maintainer
#9 lore raw
In reply to James Carter
Quoted 6 lines · James Carter

Since the kernel patches have not been accepted yet, it seems better to revert these patches while they can still be cleanly reverted just in case the kernel patches are not accepted.

If the kernel patches get accepted, then I will re-apply these patches.

Thanks James, I think this is the smart move.

Signature · 1 line
paul-moore.com
Acked-by on the v1 series
#10 lore raw
In reply to James Carter
Quoted 8 lines · James Carter

Since the kernel patches have not been accepted yet, it seems better to revert these patches while they can still be cleanly reverted just in case the kernel patches are not accepted.

If the kernel patches get accepted, then I will re-apply these patches.

I should have waited for the kernel patches to be accepted before committing these in the first place.

Quoted 53 lines

James Carter (8):
Revert "libsepol/cil: add support for prefix/suffix filename
transtions to CIL"
Revert "checkpolicy,libsepol: add prefix/suffix support to module
policy"
Revert "checkpolicy,libsepol: add prefix/suffix support to kernel
policy"
Revert "libsepol: implement new module binary format of avrule" Revert "libsepol: implement new kernel binary format for avtab" Revert "checkpolicy,libsepol: move filename transition rules to
avrule"
Revert "checkpolicy,libsepol: move filename transitions to avtab" Revert "checkpolicy,libsepol: move transition to separate structure in
avtab"

 checkpolicy/checkmodule.c                  |   9 -
 checkpolicy/module_compiler.c              |  12 +
 checkpolicy/module_compiler.h              |   1 +
 checkpolicy/policy_define.c                | 211 +++++-
 checkpolicy/policy_define.h                |   3 +-
 checkpolicy/policy_parse.y                 |  13 +-
 checkpolicy/policy_scan.l                  |   4 -
 checkpolicy/test/dismod.c                  |  39 +-
 checkpolicy/test/dispol.c                  | 106 ++-
 libsepol/cil/src/cil.c                     |   6 -
 libsepol/cil/src/cil_binary.c              |  63 +-
 libsepol/cil/src/cil_build_ast.c           |  26 +-
 libsepol/cil/src/cil_copy_ast.c            |   1 -
 libsepol/cil/src/cil_internal.h            |   4 -
 libsepol/cil/src/cil_policy.c              |  17 +-
 libsepol/cil/src/cil_resolve_ast.c         |  10 -
 libsepol/cil/src/cil_write_ast.c           |   2 -
 libsepol/include/sepol/policydb/avtab.h    |  19 +-
 libsepol/include/sepol/policydb/hashtab.h  |   8 -
 libsepol/include/sepol/policydb/policydb.h |  50 +-
 libsepol/src/avrule_block.c                |   1 +
 libsepol/src/avtab.c                       | 338 +---------
 libsepol/src/conditional.c                 |   6 +-
 libsepol/src/expand.c                      | 153 +++--
 libsepol/src/kernel_to_cil.c               | 182 +++--
 libsepol/src/kernel_to_common.h            |  10 -
 libsepol/src/kernel_to_conf.c              | 178 +++--
 libsepol/src/link.c                        |  57 +-
 libsepol/src/module_to_cil.c               |  86 ++-
 libsepol/src/optimize.c                    |   8 -
 libsepol/src/policydb.c                    | 479 +++++++++++---
 libsepol/src/policydb_validate.c           | 101 ++-
 libsepol/src/services.c                    |   5 +-
 libsepol/src/write.c                       | 735 +++++----------------
 34 files changed, 1390 insertions(+), 1553 deletions(-)
Signature · 1 line
2.41.0
#11 lore raw
Quoted 7 lines · Petr Lautrbach
Quoted 4 lines · James Carter

Since the kernel patches have not been accepted yet, it seems better to revert these patches while they can still be cleanly reverted just in case the kernel patches are not accepted.

Quoted 7 lines
Quoted 4 lines

If the kernel patches get accepted, then I will re-apply these patches.

I should have waited for the kernel patches to be accepted before committing these in the first place.

This series has been merged. I am eagerly awaiting the new and improved version. Jim

Quoted 55 lines
Quoted 54 lines

James Carter (8):
Revert "libsepol/cil: add support for prefix/suffix filename
transtions to CIL"
Revert "checkpolicy,libsepol: add prefix/suffix support to module
policy"
Revert "checkpolicy,libsepol: add prefix/suffix support to kernel
policy"
Revert "libsepol: implement new module binary format of avrule" Revert "libsepol: implement new kernel binary format for avtab" Revert "checkpolicy,libsepol: move filename transition rules to
avrule"
Revert "checkpolicy,libsepol: move filename transitions to avtab" Revert "checkpolicy,libsepol: move transition to separate structure in
avtab"

 checkpolicy/checkmodule.c                  |   9 -
 checkpolicy/module_compiler.c              |  12 +
 checkpolicy/module_compiler.h              |   1 +
 checkpolicy/policy_define.c                | 211 +++++-
 checkpolicy/policy_define.h                |   3 +-
 checkpolicy/policy_parse.y                 |  13 +-
 checkpolicy/policy_scan.l                  |   4 -
 checkpolicy/test/dismod.c                  |  39 +-
 checkpolicy/test/dispol.c                  | 106 ++-
 libsepol/cil/src/cil.c                     |   6 -
 libsepol/cil/src/cil_binary.c              |  63 +-
 libsepol/cil/src/cil_build_ast.c           |  26 +-
 libsepol/cil/src/cil_copy_ast.c            |   1 -
 libsepol/cil/src/cil_internal.h            |   4 -
 libsepol/cil/src/cil_policy.c              |  17 +-
 libsepol/cil/src/cil_resolve_ast.c         |  10 -
 libsepol/cil/src/cil_write_ast.c           |   2 -
 libsepol/include/sepol/policydb/avtab.h    |  19 +-
 libsepol/include/sepol/policydb/hashtab.h  |   8 -
 libsepol/include/sepol/policydb/policydb.h |  50 +-
 libsepol/src/avrule_block.c                |   1 +
 libsepol/src/avtab.c                       | 338 +---------
 libsepol/src/conditional.c                 |   6 +-
 libsepol/src/expand.c                      | 153 +++--
 libsepol/src/kernel_to_cil.c               | 182 +++--
 libsepol/src/kernel_to_common.h            |  10 -
 libsepol/src/kernel_to_conf.c              | 178 +++--
 libsepol/src/link.c                        |  57 +-
 libsepol/src/module_to_cil.c               |  86 ++-
 libsepol/src/optimize.c                    |   8 -
 libsepol/src/policydb.c                    | 479 +++++++++++---
 libsepol/src/policydb_validate.c           | 101 ++-
 libsepol/src/services.c                    |   5 +-
 libsepol/src/write.c                       | 735 +++++----------------
 34 files changed, 1390 insertions(+), 1553 deletions(-)

--
2.41.0