Skip to content

Commit

Permalink
selinux: specialize symtab insert and search functions
Browse files Browse the repository at this point in the history
This encapsulates symtab a little better and will help with further
refactoring later.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Ondrej Mosnacek authored and Paul Moore committed Jul 9, 2020
1 parent 2c3d8df commit 237389e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 56 deletions.
4 changes: 2 additions & 2 deletions security/selinux/ss/conditional.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static int bool_isvalid(struct cond_bool_datum *b)
return 1;
}

int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)
int cond_read_bool(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct cond_bool_datum *booldatum;
Expand Down Expand Up @@ -235,7 +235,7 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)
if (rc)
goto err;
key[len] = '\0';
rc = hashtab_insert(h, key, booldatum);
rc = symtab_insert(s, key, booldatum);
if (rc)
goto err;

Expand Down
2 changes: 1 addition & 1 deletion security/selinux/ss/conditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int cond_destroy_bool(void *key, void *datum, void *p);

int cond_index_bool(void *key, void *datum, void *datap);

int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp);
int cond_read_bool(struct policydb *p, struct symtab *s, void *fp);
int cond_read_list(struct policydb *p, void *fp);
int cond_write_bool(void *key, void *datum, void *ptr);
int cond_write_list(struct policydb *p, void *fp);
Expand Down
21 changes: 11 additions & 10 deletions security/selinux/ss/mls.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ int mls_level_isvalid(struct policydb *p, struct mls_level *l)

if (!l->sens || l->sens > p->p_levels.nprim)
return 0;
levdatum = hashtab_search(&p->p_levels.table,
sym_name(p, SYM_LEVELS, l->sens - 1));
levdatum = symtab_search(&p->p_levels,
sym_name(p, SYM_LEVELS, l->sens - 1));
if (!levdatum)
return 0;

Expand Down Expand Up @@ -293,7 +293,7 @@ int mls_context_to_sid(struct policydb *pol,
*(next_cat++) = '\0';

/* Parse sensitivity. */
levdatum = hashtab_search(&pol->p_levels.table, sensitivity);
levdatum = symtab_search(&pol->p_levels, sensitivity);
if (!levdatum)
return -EINVAL;
context->range.level[l].sens = levdatum->level->sens;
Expand All @@ -312,7 +312,7 @@ int mls_context_to_sid(struct policydb *pol,
*rngptr++ = '\0';
}

catdatum = hashtab_search(&pol->p_cats.table, cur_cat);
catdatum = symtab_search(&pol->p_cats, cur_cat);
if (!catdatum)
return -EINVAL;

Expand All @@ -325,7 +325,7 @@ int mls_context_to_sid(struct policydb *pol,
if (rngptr == NULL)
continue;

rngdatum = hashtab_search(&pol->p_cats.table, rngptr);
rngdatum = symtab_search(&pol->p_cats, rngptr);
if (!rngdatum)
return -EINVAL;

Expand Down Expand Up @@ -458,9 +458,10 @@ int mls_convert_context(struct policydb *oldp,
return 0;

for (l = 0; l < 2; l++) {
levdatum = hashtab_search(&newp->p_levels.table,
sym_name(oldp, SYM_LEVELS,
oldc->range.level[l].sens - 1));
char *name = sym_name(oldp, SYM_LEVELS,
oldc->range.level[l].sens - 1);

levdatum = symtab_search(&newp->p_levels, name);

if (!levdatum)
return -EINVAL;
Expand All @@ -470,8 +471,8 @@ int mls_convert_context(struct policydb *oldp,
node, i) {
int rc;

catdatum = hashtab_search(&newp->p_cats.table,
sym_name(oldp, SYM_CATS, i));
catdatum = symtab_search(&newp->p_cats,
sym_name(oldp, SYM_CATS, i));
if (!catdatum)
return -EINVAL;
rc = ebitmap_set_bit(&newc->range.level[l].cat,
Expand Down
52 changes: 26 additions & 26 deletions security/selinux/ss/policydb.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ static int roles_init(struct policydb *p)
if (!key)
goto out;

rc = hashtab_insert(&p->p_roles.table, key, role);
rc = symtab_insert(&p->p_roles, key, role);
if (rc)
goto out;

Expand Down Expand Up @@ -1065,7 +1065,7 @@ static int str_read(char **strp, gfp_t flags, void *fp, u32 len)
return 0;
}

static int perm_read(struct policydb *p, struct hashtab *h, void *fp)
static int perm_read(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct perm_datum *perdatum;
Expand All @@ -1088,7 +1088,7 @@ static int perm_read(struct policydb *p, struct hashtab *h, void *fp)
if (rc)
goto bad;

rc = hashtab_insert(h, key, perdatum);
rc = symtab_insert(s, key, perdatum);
if (rc)
goto bad;

Expand All @@ -1098,7 +1098,7 @@ static int perm_read(struct policydb *p, struct hashtab *h, void *fp)
return rc;
}

static int common_read(struct policydb *p, struct hashtab *h, void *fp)
static int common_read(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct common_datum *comdatum;
Expand Down Expand Up @@ -1128,12 +1128,12 @@ static int common_read(struct policydb *p, struct hashtab *h, void *fp)
goto bad;

for (i = 0; i < nel; i++) {
rc = perm_read(p, &comdatum->permissions.table, fp);
rc = perm_read(p, &comdatum->permissions, fp);
if (rc)
goto bad;
}

rc = hashtab_insert(h, key, comdatum);
rc = symtab_insert(s, key, comdatum);
if (rc)
goto bad;
return 0;
Expand Down Expand Up @@ -1262,7 +1262,7 @@ static int read_cons_helper(struct policydb *p,
return 0;
}

static int class_read(struct policydb *p, struct hashtab *h, void *fp)
static int class_read(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct class_datum *cladatum;
Expand Down Expand Up @@ -1300,16 +1300,16 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
goto bad;

rc = -EINVAL;
cladatum->comdatum = hashtab_search(&p->p_commons.table,
cladatum->comkey);
cladatum->comdatum = symtab_search(&p->p_commons,
cladatum->comkey);
if (!cladatum->comdatum) {
pr_err("SELinux: unknown common %s\n",
cladatum->comkey);
goto bad;
}
}
for (i = 0; i < nel; i++) {
rc = perm_read(p, &cladatum->permissions.table, fp);
rc = perm_read(p, &cladatum->permissions, fp);
if (rc)
goto bad;
}
Expand Down Expand Up @@ -1347,7 +1347,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
cladatum->default_type = le32_to_cpu(buf[0]);
}

rc = hashtab_insert(h, key, cladatum);
rc = symtab_insert(s, key, cladatum);
if (rc)
goto bad;

Expand All @@ -1357,7 +1357,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
return rc;
}

static int role_read(struct policydb *p, struct hashtab *h, void *fp)
static int role_read(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct role_datum *role;
Expand Down Expand Up @@ -1404,7 +1404,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
goto bad;
}

rc = hashtab_insert(h, key, role);
rc = symtab_insert(s, key, role);
if (rc)
goto bad;
return 0;
Expand All @@ -1413,7 +1413,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
return rc;
}

static int type_read(struct policydb *p, struct hashtab *h, void *fp)
static int type_read(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct type_datum *typdatum;
Expand Down Expand Up @@ -1451,7 +1451,7 @@ static int type_read(struct policydb *p, struct hashtab *h, void *fp)
if (rc)
goto bad;

rc = hashtab_insert(h, key, typdatum);
rc = symtab_insert(s, key, typdatum);
if (rc)
goto bad;
return 0;
Expand Down Expand Up @@ -1487,7 +1487,7 @@ static int mls_read_level(struct mls_level *lp, void *fp)
return 0;
}

static int user_read(struct policydb *p, struct hashtab *h, void *fp)
static int user_read(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct user_datum *usrdatum;
Expand Down Expand Up @@ -1528,7 +1528,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
goto bad;
}

rc = hashtab_insert(h, key, usrdatum);
rc = symtab_insert(s, key, usrdatum);
if (rc)
goto bad;
return 0;
Expand All @@ -1537,7 +1537,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
return rc;
}

static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
static int sens_read(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct level_datum *levdatum;
Expand Down Expand Up @@ -1569,7 +1569,7 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
if (rc)
goto bad;

rc = hashtab_insert(h, key, levdatum);
rc = symtab_insert(s, key, levdatum);
if (rc)
goto bad;
return 0;
Expand All @@ -1578,7 +1578,7 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
return rc;
}

static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
static int cat_read(struct policydb *p, struct symtab *s, void *fp)
{
char *key = NULL;
struct cat_datum *catdatum;
Expand All @@ -1602,7 +1602,7 @@ static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
if (rc)
goto bad;

rc = hashtab_insert(h, key, catdatum);
rc = symtab_insert(s, key, catdatum);
if (rc)
goto bad;
return 0;
Expand All @@ -1611,7 +1611,7 @@ static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
return rc;
}

static int (*read_f[SYM_NUM]) (struct policydb *p, struct hashtab *h, void *fp) =
static int (*read_f[SYM_NUM]) (struct policydb *p, struct symtab *s, void *fp) =
{
common_read,
class_read,
Expand Down Expand Up @@ -1751,7 +1751,7 @@ u16 string_to_security_class(struct policydb *p, const char *name)
{
struct class_datum *cladatum;

cladatum = hashtab_search(&p->p_classes.table, name);
cladatum = symtab_search(&p->p_classes, name);
if (!cladatum)
return 0;

Expand All @@ -1770,9 +1770,9 @@ u32 string_to_av_perm(struct policydb *p, u16 tclass, const char *name)
cladatum = p->class_val_to_struct[tclass-1];
comdatum = cladatum->comdatum;
if (comdatum)
perdatum = hashtab_search(&comdatum->permissions.table, name);
perdatum = symtab_search(&comdatum->permissions, name);
if (!perdatum)
perdatum = hashtab_search(&cladatum->permissions.table, name);
perdatum = symtab_search(&cladatum->permissions, name);
if (!perdatum)
return 0;

Expand Down Expand Up @@ -2509,7 +2509,7 @@ int policydb_read(struct policydb *p, void *fp)
}

for (j = 0; j < nel; j++) {
rc = read_f[i](p, &p->symtab[i].table, fp);
rc = read_f[i](p, &p->symtab[i], fp);
if (rc)
goto bad;
}
Expand Down
Loading

0 comments on commit 237389e

Please sign in to comment.