Skip to contentSkip to conversation

libsepol: Produce more meaningful error messages for conflicting type rules

PATCH In review Guido Trentalancia 2 participants 3 messages Aug 27, 2016 – Sep 6, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Produce more meaningful error messages for conflicting type rules

Produce more meaningful error messages when conflicting type rules are found by libsepol.

Fixes Debian bug #832331 (https://bugs.debian.org/832331).

---
 cil/src/cil_binary.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
cil/src/cil_binary.c +4 -4
@@ -973,7 +973,7 @@ avtab_datum_t *cil_cond_av_list_search(a
 	return NULL;
 }
 
-int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src, uint32_t tgt, uint32_t obj, uint32_t res, cond_node_t *cond_node, enum cil_flavor cond_flavor)
+int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src, uint32_t tgt, uint32_t obj, uint32_t res, struct cil_type_rule *cil_rule, cond_node_t *cond_node, enum cil_flavor cond_flavor)
 {
 	int rc = SEPOL_OK;
 	avtab_key_t avtab_key;
@@ -1008,7 +1008,7 @@ int __cil_insert_type_rule(policydb_t *p
 		 * non-duplicate rule using the same key.
 		 */
 		if (existing->datum.data != res) {
-			cil_log(CIL_ERR, "Conflicting type rules\n");
+			cil_log(CIL_ERR, "Conflicting type rules (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;
 		}
 		goto exit;
@@ -1034,7 +1034,7 @@ int __cil_insert_type_rule(policydb_t *p
 			search_datum = cil_cond_av_list_search(&avtab_key, other_list);
 			if (search_datum == NULL) {
 				if (existing->datum.data != res) {
-					cil_log(CIL_ERR, "Conflicting type rules\n");
+					cil_log(CIL_ERR, "Conflicting type rules (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;
 					goto exit;
 				}
@@ -1093,7 +1093,7 @@ int __cil_type_rule_to_avtab(policydb_t
 				rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj);
 				if (rc != SEPOL_OK) goto exit;
 
-				rc = __cil_insert_type_rule(pdb, kind, sepol_src->s.value, sepol_tgt->s.value, sepol_obj->s.value, sepol_result->s.value, cond_node, cond_flavor);
+				rc = __cil_insert_type_rule(pdb, kind, sepol_src->s.value, sepol_tgt->s.value, sepol_obj->s.value, sepol_result->s.value, cil_rule, cond_node, cond_flavor);
 				if (rc != SEPOL_OK) goto exit;
 			}
 		}
#1 lore raw

Hello.

I received no feedback on this.

I still believe it is a very useful patch, because at the moment it is very hard to track down the error from the error message.

Guido

Quoted 67 lines · Guido Trentalancia

Produce more meaningful error messages when conflicting type rules are found by libsepol.

Fixes Debian bug #832331 (https://bugs.debian.org/832331).

---
 cil/src/cil_binary.c |    8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)

--- libsepol-2.5/cil/src/cil_binary.c 2016-02-23
17:31:41.000000000 +0100
+++ libsepol-2.5-conflicting_type_rules/cil/src/cil_binary.c 2
016-08-27 14:31:44.307988662 +0200

cil/src/cil_binary.c +0 -0
@@ -973,7 +973,7 @@ avtab_datum_t *cil_cond_av_list_search(a
  	return NULL;
  }


-int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src, uint32_t tgt, uint32_t obj, uint32_t res, cond_node_t *cond_node, enum cil_flavor cond_flavor)
+int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src, uint32_t tgt, uint32_t obj, uint32_t res, struct cil_type_rule *cil_rule, cond_node_t *cond_node, enum cil_flavor cond_flavor) {
  int rc = SEPOL_OK;
  avtab_key_t avtab_key;

(quoted diff) +1 -1
@@ -1008,7 +1008,7 @@ int __cil_insert_type_rule(policydb_t *p
  		 * non-duplicate rule using the same key.
  		 */
  		if (existing->datum.data != res) {
-			cil_log(CIL_ERR, "Conflicting type
 rules\n");
+			cil_log(CIL_ERR, "Conflicting type rules
 (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;
  }
  goto exit;

(quoted diff) +0 -0
@@ -1034,7 +1034,7 @@ int __cil_insert_type_rule(policydb_t *p

  search_datum = cil_cond_av_list_search(&avtab_key, other_list);
  if (search_datum == NULL) {
  if (existing->datum.data != res) {

(quoted diff) +0 -1
-					cil_log(CIL_ERR,

"Conflicting type rules\n");

(quoted diff) +1 -0
+					cil_log(CIL_ERR,

"Conflicting type rules (scontext=%s tcontext=%s tclass=%s result=%s)\n", cil_rule->src_str, cil_rule->tgt_str, cil_rule-

Quoted 1 line

obj_str, cil_rule->result_str);

  rc = SEPOL_ERR; goto exit; }

(quoted diff) +0 -0
@@ -1093,7 +1093,7 @@ int __cil_type_rule_to_avtab(policydb_t

  rc = __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj); if (rc != SEPOL_OK) goto exit;

(quoted diff) +0 -1
-				rc = __cil_insert_type_rule(pdb,

kind, sepol_src->s.value, sepol_tgt->s.value, sepol_obj->s.value, sepol_result->s.value, cond_node, cond_flavor);

(quoted diff) +1 -0
+				rc = __cil_insert_type_rule(pdb,

kind, sepol_src->s.value, sepol_tgt->s.value, sepol_obj->s.value, sepol_result->s.value, cil_rule, cond_node, cond_flavor); if (rc != SEPOL_OK) goto exit; }
  }

#2 lore raw
Quoted 16 lines · Guido Trentalancia

Hello.

I received no feedback on this.

I still believe it is a very useful patch, because at the moment it is very hard to track down the error from the error message.

Guido

Quoted 6 lines · Guido Trentalancia

Produce more meaningful error messages when conflicting type rules are found by libsepol.

Fixes Debian bug #832331 (https://bugs.debian.org/832331).

Sorry for the delay, but applied now.

Thanks,
Jim

Quoted 68 lines
Quoted 58 lines
---
 cil/src/cil_binary.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- libsepol-2.5/cil/src/cil_binary.c 2016-02-23
17:31:41.000000000 +0100
+++ libsepol-2.5-conflicting_type_rules/cil/src/cil_binary.c 2
016-08-27 14:31:44.307988662 +0200

cil/src/cil_binary.c +0 -1
@@ -973,7 +973,7 @@ avtab_datum_t *cil_cond_av_list_search(a
 	return NULL;
 }
 
-int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t

src, uint32_t tgt, uint32_t obj, uint32_t res, cond_node_t *cond_node, enum cil_flavor cond_flavor)
+int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src, uint32_t tgt, uint32_t obj, uint32_t res, struct cil_type_rule *cil_rule, cond_node_t *cond_node, enum cil_flavor cond_flavor)
{

cil/src/cil_binary.c +1 -1
 	int rc = SEPOL_OK;
 	avtab_key_t avtab_key;
@@ -1008,7 +1008,7 @@ int __cil_insert_type_rule(policydb_t *p
 		 * non-duplicate rule using the same key.
 		 */
 		if (existing->datum.data != res) {
-			cil_log(CIL_ERR, "Conflicting type
 rules\n");
+			cil_log(CIL_ERR, "Conflicting type rules
 (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);
cil/src/cil_binary.c +1 -1
 			rc = SEPOL_ERR;
 		}
 		goto exit;
@@ -1034,7 +1034,7 @@ int __cil_insert_type_rule(policydb_t *p
 			search_datum =
 cil_cond_av_list_search(&avtab_key, other_list);
 			if (search_datum == NULL) {
 				if (existing->datum.data != res) {
-					cil_log(CIL_ERR,
 "Conflicting type rules\n");
+					cil_log(CIL_ERR,

"Conflicting type rules (scontext=%s tcontext=%s tclass=%s result=%s)\n", cil_rule->src_str, cil_rule->tgt_str, cil_rule-

Quoted 1 line

obj_str, cil_rule->result_str);

cil/src/cil_binary.c +1 -1
 					rc = SEPOL_ERR;
 					goto exit;
 				}
@@ -1093,7 +1093,7 @@ int __cil_type_rule_to_avtab(policydb_t
 				rc =
 __cil_get_sepol_class_datum(pdb, DATUM(c->data), &sepol_obj);
 				if (rc != SEPOL_OK) goto exit;
 
-				rc = __cil_insert_type_rule(pdb,
 kind, sepol_src->s.value, sepol_tgt->s.value, sepol_obj->s.value,
 sepol_result->s.value, cond_node, cond_flavor);
+				rc = __cil_insert_type_rule(pdb,

kind, sepol_src->s.value, sepol_tgt->s.value, sepol_obj->s.value, sepol_result->s.value, cil_rule, cond_node, cond_flavor);

cil/src/cil_binary.c int __cil_type_rule_to_avtab(policydb_t · line 1099

Quoted 3 lines
cil/src/cil_binary.c +0 -0
 				if (rc != SEPOL_OK) goto exit;
 			}
 		}

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

Signature · 2 lines
James Carter <[email protected]>
National Security Agency