Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 201917
b: refs/heads/master
c: 6371dcd
h: refs/heads/master
i:
  201915: 9787bf3
v: v3
  • Loading branch information
Eric Paris authored and James Morris committed Aug 2, 2010
1 parent 465dbce commit ddd648d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 016d825fe02cd20fd8803ca37a1e6d428fe878f6
refs/heads/master: 6371dcd36f649d9d07823f31400618155a20dde1
41 changes: 31 additions & 10 deletions trunk/security/selinux/ss/policydb.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/audit.h>
#include <linux/flex_array.h>
#include "security.h"

#include "policydb.h"
Expand Down Expand Up @@ -739,11 +740,17 @@ void policydb_destroy(struct policydb *p)
hashtab_map(p->range_tr, range_tr_destroy, NULL);
hashtab_destroy(p->range_tr);

if (p->type_attr_map) {
for (i = 0; i < p->p_types.nprim; i++)
ebitmap_destroy(&p->type_attr_map[i]);
if (p->type_attr_map_array) {
for (i = 0; i < p->p_types.nprim; i++) {
struct ebitmap *e;

e = flex_array_get(p->type_attr_map_array, i);
if (!e)
continue;
ebitmap_destroy(e);
}
flex_array_free(p->type_attr_map_array);
}
kfree(p->type_attr_map);
ebitmap_destroy(&p->policycaps);
ebitmap_destroy(&p->permissive_map);

Expand Down Expand Up @@ -2257,19 +2264,33 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto bad;

p->type_attr_map = kmalloc(p->p_types.nprim * sizeof(struct ebitmap), GFP_KERNEL);
if (!p->type_attr_map)
rc = -ENOMEM;
p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap),
p->p_types.nprim,
GFP_KERNEL | __GFP_ZERO);
if (!p->type_attr_map_array)
goto bad;

/* preallocate so we don't have to worry about the put ever failing */
rc = flex_array_prealloc(p->type_attr_map_array, 0, p->p_types.nprim - 1,
GFP_KERNEL | __GFP_ZERO);
if (rc)
goto bad;

for (i = 0; i < p->p_types.nprim; i++) {
ebitmap_init(&p->type_attr_map[i]);
struct ebitmap *e = flex_array_get(p->type_attr_map_array, i);

BUG_ON(!e);
ebitmap_init(e);
if (p->policyvers >= POLICYDB_VERSION_AVTAB) {
if (ebitmap_read(&p->type_attr_map[i], fp))
rc = ebitmap_read(e, fp);
if (rc)
goto bad;
}
/* add the type itself as the degenerate case */
if (ebitmap_set_bit(&p->type_attr_map[i], i, 1))
goto bad;
rc = ebitmap_set_bit(e, i, 1);
if (rc)
goto bad;
}

rc = policydb_bounds_sanity_check(p);
Expand Down
4 changes: 3 additions & 1 deletion trunk/security/selinux/ss/policydb.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#ifndef _SS_POLICYDB_H_
#define _SS_POLICYDB_H_

#include <linux/flex_array.h>

#include "symtab.h"
#include "avtab.h"
#include "sidtab.h"
Expand Down Expand Up @@ -246,7 +248,7 @@ struct policydb {
struct hashtab *range_tr;

/* type -> attribute reverse mapping */
struct ebitmap *type_attr_map;
struct flex_array *type_attr_map_array;

struct ebitmap policycaps;

Expand Down
7 changes: 5 additions & 2 deletions trunk/security/selinux/ss/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <linux/audit.h>
#include <linux/mutex.h>
#include <linux/selinux.h>
#include <linux/flex_array.h>
#include <net/netlabel.h>

#include "flask.h"
Expand Down Expand Up @@ -626,8 +627,10 @@ static void context_struct_compute_av(struct context *scontext,
*/
avkey.target_class = tclass;
avkey.specified = AVTAB_AV;
sattr = &policydb.type_attr_map[scontext->type - 1];
tattr = &policydb.type_attr_map[tcontext->type - 1];
sattr = flex_array_get(policydb.type_attr_map_array, scontext->type - 1);
BUG_ON(!sattr);
tattr = flex_array_get(policydb.type_attr_map_array, tcontext->type - 1);
BUG_ON(!tattr);
ebitmap_for_each_positive_bit(sattr, snode, i) {
ebitmap_for_each_positive_bit(tattr, tnode, j) {
avkey.source_type = i + 1;
Expand Down

0 comments on commit ddd648d

Please sign in to comment.