From: James Carter <jwcart2@tycho.nsa.gov>
To: Stephen Smalley <sds@tycho.nsa.gov>, selinux@tycho.nsa.gov
Subject: Re: [PATCH 02/10] libsepol: Treat types like an attribute in the attr_type_map.
Date: Fri, 12 Jun 2015 08:14:49 -0400 [thread overview]
Message-ID: <557ACD39.9020108@tycho.nsa.gov> (raw)
In-Reply-To: <5579E99E.1060502@tycho.nsa.gov>
On 06/11/2015 04:03 PM, Stephen Smalley wrote:
> On 06/11/2015 02:26 PM, James Carter wrote:
>> 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.
>>
>> Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
>> ---
>> libsepol/src/expand.c | 26 +++++++++++++++++---------
>> libsepol/src/policydb.c | 4 ++++
>> 2 files changed, 21 insertions(+), 9 deletions(-)
>>
>> diff --git a/libsepol/src/expand.c b/libsepol/src/expand.c
>> index b999890..cbd39df 100644
>> --- a/libsepol/src/expand.c
>> +++ b/libsepol/src/expand.c
>> @@ -2317,25 +2317,33 @@ static int type_attr_map(hashtab_key_t key
>> policydb_t *p = state->out;
>> unsigned int i;
>> ebitmap_node_t *tnode;
>> + int value;
>>
>> type = (type_datum_t *) datum;
>> + value = type->s.value;
>> +
>> if (type->flavor == TYPE_ATTRIB) {
>> - if (ebitmap_cpy(&p->attr_type_map[type->s.value - 1],
>> - &type->types)) {
>> - ERR(state->handle, "Out of memory!");
>> - return -1;
>> - }
>> ebitmap_for_each_bit(&type->types, tnode, i) {
>> if (!ebitmap_node_get_bit(tnode, i))
>> continue;
>> - if (ebitmap_set_bit(&p->type_attr_map[i],
>> - type->s.value - 1, 1)) {
>> - ERR(state->handle, "Out of memory!");
>> - return -1;
>> + if (ebitmap_set_bit(&p->type_attr_map[i], value - 1, 1)) {
>> + goto out;
>> }
>> + if (ebitmap_set_bit(&p->attr_type_map[value - 1], i, 1)) {
>> + goto out;
>
> Why populate attr_type_map here via individual ebitmap_set_bit() calls
> rather than just a single ebitmap_cpy() as above?
>
I was conflicted on what was the best way to do this. The ebitmap_cpy() does an
ebitmap_init() and I thought that it might be clearer to leave the
ebitmap_init() close to where the attr_type_map is malloc'd.
I could use ebitmap_union() here if you would prefer.
>> + }
>> + }
>> + } else {
>> + if (ebitmap_set_bit(&p->attr_type_map[value - 1], value - 1, 1)) {
>> + goto out;
>> }
>> }
>> +
>> return 0;
>> +
>> +out:
>> + 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.
>> diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c
>> index 8c3c7ac..be0c701 100644
>> --- a/libsepol/src/policydb.c
>> +++ b/libsepol/src/policydb.c
>> @@ -3936,6 +3936,10 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
>> /* add the type itself as the degenerate case */
>> if (ebitmap_set_bit(&p->type_attr_map[i], i, 1))
>> 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;
>> + }
>> }
>> }
>>
>>
--
James Carter <jwcart2@tycho.nsa.gov>
National Security Agency
next prev parent reply other threads:[~2015-06-12 12:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-11 18:26 [PATCH 00/10] Improve libsepol and CIL neverallow and bounds checking James Carter
2015-06-11 18:26 ` [PATCH 01/10] libsepol: Add new ebitmap function named ebitmap_match_any() James Carter
2015-06-11 18:26 ` [PATCH 02/10] libsepol: Treat types like an attribute in the attr_type_map James Carter
2015-06-11 20:03 ` Stephen Smalley
2015-06-12 12:14 ` James Carter [this message]
2015-06-12 12:22 ` Stephen Smalley
2015-06-12 13:02 ` James Carter
2015-06-11 18:26 ` [PATCH 03/10] libsepol: Refactored neverallow checking James Carter
2015-06-11 20:07 ` Stephen Smalley
2015-06-12 12:55 ` Christopher J. PeBenito
2015-06-12 12:59 ` James Carter
2015-06-12 13:05 ` James Carter
2015-06-11 18:26 ` [PATCH 04/10] libsepol: Refactored bounds (hierarchy) checking code James Carter
2015-06-11 18:26 ` [PATCH 05/10] libsepol/cil: Add function to search the CIL AST for an AV rule James Carter
2015-06-12 18:27 ` Steve Lawrence
2015-06-15 13:59 ` James Carter
2015-06-11 18:26 ` [PATCH 06/10] libsepol/cil: Refactored CIL neverallow checking and reporting James Carter
2015-06-11 18:26 ` [PATCH 07/10] libsepol/cil: Track number of classes and number of types and attributes James Carter
2015-06-11 18:26 ` [PATCH 08/10] libsepol/cil: Add CIL bounds checking and reporting James Carter
2015-06-11 18:26 ` [PATCH 09/10] secilc: Add a CIL policy file to test neverallow checking James Carter
2015-06-11 18:26 ` [PATCH 10/10] secilc: Add a CIL policy file to test bounds checking James Carter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=557ACD39.9020108@tycho.nsa.gov \
--to=jwcart2@tycho.nsa.gov \
--cc=sds@tycho.nsa.gov \
--cc=selinux@tycho.nsa.gov \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.