libsepol: module_to_cil: warn and drop non-trivial -self neverallows
Stephen Smalley
maintainerPATCH 1/1 libsepol: module_to_cil: warn and drop non-trivial -self neverallows
CIL has no target syntax for a neverallow whose target is an arbitrary type set with self subtracted. The (notself) syntax is the universe minus self and the (other) syntax is the source set minus self. module_to_cil emits (notself) for the trivial ~self case but fails any other notself rule with a target set.
That construct is legal in the source language and checkmodule emits it into POLICY_BASE/MOD binaries; the assertion checker handles it, and semodule_link/expand accept and preserve it. So a validated module carrying
neverallow SRC { TGT -self } : CLASS PERM;reads and validates but fails hll/pp, and now also aborts the fuzz harness that treats a validated module failing module_to_cil() as an invariant break.
There is no valid CIL translation and refusing the module in the validator would break the tools that do handle it. Downgrade to a warning and skip the rule instead of failing. The dropped rule is a neverallow assertion, not an enforcement rule, so the emitted CIL produces a policy that is no more permissive than the input; the assertion is simply not rechecked at CIL compile time.
Hoist the check to the top of the loop so that the lmx/lme line markers stay paired for the rules that are emitted.
--- libsepol/src/module_to_cil.c | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-)
libsepol/src/module_to_cil.c +25 -15
@@ -1257,6 +1257,31 @@ static int avrule_list_to_cil(int indent, struct policydb *pdb,struct type_set *ts;for (avrule = avrule_list; avrule !=NULL ; avrule = avrule->next) { +if ((avrule->flags &RULE_NOTSELF ) && + (!ebitmap_is_empty (&avrule->ttypes.types) || + !ebitmap_is_empty (&avrule->ttypes.negset))) { +/* +* CIL has no target syntax for "T minus self": +* (notself) is the universe minus self and (other) is +* the source set minus self. A neverallow with a +* non-trivial target set and -self therefore has no +* representation. Drop it rather than fail the whole +* conversion; the rule is an assertion, not an +* enforcement rule, so the resulting policy is no more +* permissive. +*/ +if (avrule->source_filename) { +WARN (NULL , +"%s:%lu: neverallow with a non-trivial -self target is not representable in CIL, dropped" , + avrule->source_filename, + avrule->source_line); + }else { +WARN (NULL , +"neverallow with a non-trivial -self target is not representable in CIL, dropped" ); + } +continue ; + } +if ((avrule->specified & pdb->line_marker_avrules) && avrule->source_filename) { cil_println(0, ";;* lmx %lu %s\n", avrule->source_line,
@@ -1270,21 +1295,6 @@ static int avrule_list_to_cil(int indent, struct policydb *pdb, }if (avrule->flags &RULE_NOTSELF ) { -if (!ebitmap_is_empty (&avrule->ttypes.types) || - !ebitmap_is_empty (&avrule->ttypes.negset)) { -if (avrule->source_filename) { -ERR (NULL , -"%s:%lu: Non-trivial neverallow rules with targets containing not or minus self not yet supported" , - avrule->source_filename, - avrule->source_line); - }else { -ERR (NULL , -"Non-trivial neverallow rules with targets containing not or minus self not yet supported" ); - } - rc =-1 ; - goto exit; - } - num_tnames =0 ; }else { ts = &avrule->ttypes;
Signature · 1 line
2.55.0
Stephen Smalley
maintainerQuoted 25 lines · Stephen Smalley
CIL has no target syntax for a neverallow whose target is an arbitrary type set with self subtracted. The (notself) syntax is the universe minus self and the (other) syntax is the source set minus self.
module_to_cilemits (notself) for the trivial ~self case but fails any other notself rule with a target set.That construct is legal in the source language and checkmodule emits it into POLICY_BASE/MOD binaries; the assertion checker handles it, and semodule_link/expand accept and preserve it. So a validated module carrying
neverallow SRC { TGT -self } : CLASS PERM;reads and validates but fails hll/pp, and now also aborts the fuzz harness that treats a validated module failing
module_to_cil()as an invariant break.There is no valid CIL translation and refusing the module in the validator would break the tools that do handle it. Downgrade to a warning and skip the rule instead of failing. The dropped rule is a neverallow assertion, not an enforcement rule, so the emitted CIL produces a policy that is no more permissive than the input; the assertion is simply not rechecked at CIL compile time.
Quoted 6 lines
Hoist the check to the top of the loop so that the lmx/lme line markers stay paired for the rules that are emitted.
Reported-by oss-fuzzSigned-off-by Stephen Smalley <[email protected]>
This patch has been merged.