mirror of
https://github.com/topjohnwu/selinux.git
synced 2025-03-02 16:37:55 +00:00
libsepol: Treat types like an attribute in the attr_type_map.
Types are treated as attributes that contain only themselves. This is how types are already treated in the type_attr_map. Treating types this way makes finding rules that apply to a given type much easier. This simplifies the implementation of neverallow checking in assertion.c and bounds checking in hierarchy.c. Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
This commit is contained in:
parent
49f7ebb04c
commit
88d09b6979
@ -2311,25 +2311,33 @@ static int type_attr_map(hashtab_key_t key
|
|||||||
policydb_t *p = state->out;
|
policydb_t *p = state->out;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
ebitmap_node_t *tnode;
|
ebitmap_node_t *tnode;
|
||||||
|
int value;
|
||||||
|
|
||||||
type = (type_datum_t *) datum;
|
type = (type_datum_t *) datum;
|
||||||
|
value = type->s.value;
|
||||||
|
|
||||||
if (type->flavor == TYPE_ATTRIB) {
|
if (type->flavor == TYPE_ATTRIB) {
|
||||||
if (ebitmap_cpy(&p->attr_type_map[type->s.value - 1],
|
if (ebitmap_cpy(&p->attr_type_map[value - 1], &type->types)) {
|
||||||
&type->types)) {
|
goto oom;
|
||||||
ERR(state->handle, "Out of memory!");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
ebitmap_for_each_bit(&type->types, tnode, i) {
|
ebitmap_for_each_bit(&type->types, tnode, i) {
|
||||||
if (!ebitmap_node_get_bit(tnode, i))
|
if (!ebitmap_node_get_bit(tnode, i))
|
||||||
continue;
|
continue;
|
||||||
if (ebitmap_set_bit(&p->type_attr_map[i],
|
if (ebitmap_set_bit(&p->type_attr_map[i], value - 1, 1)) {
|
||||||
type->s.value - 1, 1)) {
|
goto oom;
|
||||||
ERR(state->handle, "Out of memory!");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (ebitmap_set_bit(&p->attr_type_map[value - 1], value - 1, 1)) {
|
||||||
|
goto oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
oom:
|
||||||
|
ERR(state->handle, "Out of memory!");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* converts typeset using typemap and expands into ebitmap_t types using the attributes in the passed in policy.
|
/* converts typeset using typemap and expands into ebitmap_t types using the attributes in the passed in policy.
|
||||||
|
@ -3936,6 +3936,10 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
|
|||||||
/* add the type itself as the degenerate case */
|
/* add the type itself as the degenerate case */
|
||||||
if (ebitmap_set_bit(&p->type_attr_map[i], i, 1))
|
if (ebitmap_set_bit(&p->type_attr_map[i], i, 1))
|
||||||
goto bad;
|
goto bad;
|
||||||
|
if (p->type_val_to_struct[i]->flavor != TYPE_ATTRIB) {
|
||||||
|
if (ebitmap_set_bit(&p->attr_type_map[i], i, 1))
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user