remove te rule conflict checking from parser
PATCH 1/1 remove te rule conflict checking from parser
This patch removes the te rule conflict checking from the parser. Duplicate te rules in different scopes (eg., conditional and unconditional) are now fatal and the parser doesn't have enough information to know if the te rules have the same conditional expression if they are in different optional blocks. The expander correctly checks for te rule duplicates and conflicts; unfortunately this means the errors can't be caught until link/expand time (the base gets linked and expanded during compilation for validation) and can't be caught at all in modules until they are linked in.
checkpolicy/policy_parse.y +3 -96
@@ -923,22 +923,6 @@ static int insert_id(char *id, int push) return 0; } -/* Add a rule onto an avtab hash table only if it does not already - * exist. (Note that the avtab is discarded afterwards; it will be - * regenerated during expansion.) Return 1 if rule was added (or - * otherwise handled successfully), 0 if it conflicted with something, - * or -1 on error. */ -static int insert_check_type_rule(avrule_t *rule, avtab_t *avtab, cond_av_list_t **list, cond_av_list_t **other) -{ - int ret; - - ret = expand_rule(NULL, policydbp, rule, avtab, list, other, 0); - if (ret < 0) { - yyerror("Failed on expanding rule"); - } - return ret; -} - /* If the identifier has a dot within it and that its first character is not a dot then return 1, else return 0. */ static int id_has_dot(char *id)
@@ -2082,7 +2066,6 @@ static int define_compute_type(int which { char *id; avrule_t *avrule; - int retval; if (pass == 1) { while ((id = queue_remove(id_queue)))
@@ -2099,28 +2082,8 @@ static int define_compute_type(int which if (define_compute_type_helper(which, &avrule)) return -1; - retval = insert_check_type_rule(avrule, &policydbp->te_avtab, NULL, NULL); - switch (retval) { - case 1: { - /* append this avrule to the end of the current rules list */ - append_avrule(avrule); - return 0; - } - case 0: { - /* rule conflicted, so don't actually add this rule */ - avrule_destroy(avrule); - free(avrule); - return 0; - } - case -1: { - avrule_destroy(avrule); - free(avrule); - return -1; - } - default: { - assert(0); /* should never get here */ - } - } + append_avrule(avrule); + return 0; } static avrule_t *define_cond_compute_type(int which)
@@ -3263,9 +3226,8 @@ static uintptr_t static int define_conditional(cond_expr_t *expr, avrule_t *t, avrule_t *f ) { cond_expr_t *e; - int depth, retval; + int depth; cond_node_t cn, *cn_old; - avrule_t *tmp, *last_tmp; /* expression cannot be NULL */ if ( !expr) {
@@ -3344,61 +3306,6 @@ static int define_conditional(cond_expr_ return -1; } - /* verify te rules -- both true and false branches of conditional */ - tmp = cn.avtrue_list; - last_tmp = NULL; - while (tmp) { - if (!tmp->specified & AVRULE_TRANSITION) - continue; - retval = insert_check_type_rule(tmp, - &policydbp->te_cond_avtab, - &cn_old->true_list, &cn_old->false_list); - switch (retval) { - case 1: { - last_tmp = tmp; - tmp = tmp->next; - break; - } - case 0: { - /* rule conflicted or dupe, so bail */ - return -1; - } - case -1: { - return -1; - } - default: { - assert(0); /* should never get here */ - } - } - } - - tmp = cn.avfalse_list; - last_tmp = NULL; - while (tmp) { - if (!tmp->specified & AVRULE_TRANSITION) - continue; - retval = insert_check_type_rule(tmp, - &policydbp->te_cond_avtab, - &cn_old->false_list, &cn_old->true_list); - switch (retval) { - case 1: { - last_tmp = tmp; - tmp = tmp->next; - break; - } - case 0: { - /* rule conflicted or dupe, so bail */ - return -1; - } - case -1: { - return -1; - } - default: { - assert(0); /* should never get here */ - } - } - } - append_cond_list(&cn); /* note that there is no check here for duplicate rules, nor
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 9 lines · Joshua Brindle
This patch removes the te rule conflict checking from the parser. Duplicate te rules in different scopes (eg., conditional and unconditional) are now fatal and the parser doesn't have enough information to know if the te rules have the same conditional expression if they are in different optional blocks. The expander correctly checks for te rule duplicates and conflicts; unfortunately this means the errors can't be caught until link/expand time (the base gets linked and expanded during compilation for validation) and can't be caught at all in modules until they are linked in.
Manually adding a duplicate TE rule to my policy.conf and rebuilding with this patch applied to checkpolicy:
$ grep 'type_transition initrc_t acct_exec_t' policy.conf
type_transition initrc_t acct_exec_t:process acct_t;
type_transition initrc_t acct_exec_t:process acct_t;
$ make
Compiling refpolicy policy.20
/usr/bin/checkpolicy -M policy.conf -o policy.20
/usr/bin/checkpolicy: loading policy configuration from policy.conf
/usr/bin/checkpolicy: policy configuration loaded
/usr/bin/checkpolicy: writing binary representation (version 20) to policy.20Appears to have silently dropped the duplicate from the output.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 24 lines · Stephen Smalley
Quoted 9 lines · Joshua Brindle
This patch removes the te rule conflict checking from the parser. Duplicate te rules in different scopes (eg., conditional and unconditional) are now fatal and the parser doesn't have enough information to know if the te rules have the same conditional expression if they are in different optional blocks. The expander correctly checks for te rule duplicates and conflicts; unfortunately this means the errors can't be caught until link/expand time (the base gets linked and expanded during compilation for validation) and can't be caught at all in modules until they are linked in.
Manually adding a duplicate TE rule to my policy.conf and rebuilding with this patch applied to checkpolicy:
$ grep 'type_transition initrc_t acct_exec_t' policy.conf type_transition initrc_t acct_exec_t:process acct_t; type_transition initrc_t acct_exec_t:process acct_t; $ make Compiling refpolicy policy.20 /usr/bin/checkpolicy -M policy.conf -o policy.20 /usr/bin/checkpolicy: loading policy configuration from policy.conf /usr/bin/checkpolicy: policy configuration loaded /usr/bin/checkpolicy: writing binary representation (version 20) to policy.20
Quoted 1 line
Appears to have silently dropped the duplicate from the output.
Actually, I suppose that isn't new to this patch.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.