Skip to content

Commit 237389e

Browse files
WOnder93pcmoore
authored andcommitted
selinux: specialize symtab insert and search functions
This encapsulates symtab a little better and will help with further refactoring later. Signed-off-by: Ondrej Mosnacek <[email protected]> Acked-by: Stephen Smalley <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 2c3d8df commit 237389e

File tree

7 files changed

+69
-56
lines changed

7 files changed

+69
-56
lines changed

security/selinux/ss/conditional.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static int bool_isvalid(struct cond_bool_datum *b)
200200
return 1;
201201
}
202202

203-
int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)
203+
int cond_read_bool(struct policydb *p, struct symtab *s, void *fp)
204204
{
205205
char *key = NULL;
206206
struct cond_bool_datum *booldatum;
@@ -235,7 +235,7 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)
235235
if (rc)
236236
goto err;
237237
key[len] = '\0';
238-
rc = hashtab_insert(h, key, booldatum);
238+
rc = symtab_insert(s, key, booldatum);
239239
if (rc)
240240
goto err;
241241

security/selinux/ss/conditional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int cond_destroy_bool(void *key, void *datum, void *p);
6969

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

72-
int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp);
72+
int cond_read_bool(struct policydb *p, struct symtab *s, void *fp);
7373
int cond_read_list(struct policydb *p, void *fp);
7474
int cond_write_bool(void *key, void *datum, void *ptr);
7575
int cond_write_list(struct policydb *p, void *fp);

security/selinux/ss/mls.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ int mls_level_isvalid(struct policydb *p, struct mls_level *l)
165165

166166
if (!l->sens || l->sens > p->p_levels.nprim)
167167
return 0;
168-
levdatum = hashtab_search(&p->p_levels.table,
169-
sym_name(p, SYM_LEVELS, l->sens - 1));
168+
levdatum = symtab_search(&p->p_levels,
169+
sym_name(p, SYM_LEVELS, l->sens - 1));
170170
if (!levdatum)
171171
return 0;
172172

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

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

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

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

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

@@ -458,9 +458,10 @@ int mls_convert_context(struct policydb *oldp,
458458
return 0;
459459

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

465466
if (!levdatum)
466467
return -EINVAL;
@@ -470,8 +471,8 @@ int mls_convert_context(struct policydb *oldp,
470471
node, i) {
471472
int rc;
472473

473-
catdatum = hashtab_search(&newp->p_cats.table,
474-
sym_name(oldp, SYM_CATS, i));
474+
catdatum = symtab_search(&newp->p_cats,
475+
sym_name(oldp, SYM_CATS, i));
475476
if (!catdatum)
476477
return -EINVAL;
477478
rc = ebitmap_set_bit(&newc->range.level[l].cat,

security/selinux/ss/policydb.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static int roles_init(struct policydb *p)
400400
if (!key)
401401
goto out;
402402

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

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

1068-
static int perm_read(struct policydb *p, struct hashtab *h, void *fp)
1068+
static int perm_read(struct policydb *p, struct symtab *s, void *fp)
10691069
{
10701070
char *key = NULL;
10711071
struct perm_datum *perdatum;
@@ -1088,7 +1088,7 @@ static int perm_read(struct policydb *p, struct hashtab *h, void *fp)
10881088
if (rc)
10891089
goto bad;
10901090

1091-
rc = hashtab_insert(h, key, perdatum);
1091+
rc = symtab_insert(s, key, perdatum);
10921092
if (rc)
10931093
goto bad;
10941094

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

1101-
static int common_read(struct policydb *p, struct hashtab *h, void *fp)
1101+
static int common_read(struct policydb *p, struct symtab *s, void *fp)
11021102
{
11031103
char *key = NULL;
11041104
struct common_datum *comdatum;
@@ -1128,12 +1128,12 @@ static int common_read(struct policydb *p, struct hashtab *h, void *fp)
11281128
goto bad;
11291129

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

1136-
rc = hashtab_insert(h, key, comdatum);
1136+
rc = symtab_insert(s, key, comdatum);
11371137
if (rc)
11381138
goto bad;
11391139
return 0;
@@ -1262,7 +1262,7 @@ static int read_cons_helper(struct policydb *p,
12621262
return 0;
12631263
}
12641264

1265-
static int class_read(struct policydb *p, struct hashtab *h, void *fp)
1265+
static int class_read(struct policydb *p, struct symtab *s, void *fp)
12661266
{
12671267
char *key = NULL;
12681268
struct class_datum *cladatum;
@@ -1300,16 +1300,16 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
13001300
goto bad;
13011301

13021302
rc = -EINVAL;
1303-
cladatum->comdatum = hashtab_search(&p->p_commons.table,
1304-
cladatum->comkey);
1303+
cladatum->comdatum = symtab_search(&p->p_commons,
1304+
cladatum->comkey);
13051305
if (!cladatum->comdatum) {
13061306
pr_err("SELinux: unknown common %s\n",
13071307
cladatum->comkey);
13081308
goto bad;
13091309
}
13101310
}
13111311
for (i = 0; i < nel; i++) {
1312-
rc = perm_read(p, &cladatum->permissions.table, fp);
1312+
rc = perm_read(p, &cladatum->permissions, fp);
13131313
if (rc)
13141314
goto bad;
13151315
}
@@ -1347,7 +1347,7 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp)
13471347
cladatum->default_type = le32_to_cpu(buf[0]);
13481348
}
13491349

1350-
rc = hashtab_insert(h, key, cladatum);
1350+
rc = symtab_insert(s, key, cladatum);
13511351
if (rc)
13521352
goto bad;
13531353

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

1360-
static int role_read(struct policydb *p, struct hashtab *h, void *fp)
1360+
static int role_read(struct policydb *p, struct symtab *s, void *fp)
13611361
{
13621362
char *key = NULL;
13631363
struct role_datum *role;
@@ -1404,7 +1404,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
14041404
goto bad;
14051405
}
14061406

1407-
rc = hashtab_insert(h, key, role);
1407+
rc = symtab_insert(s, key, role);
14081408
if (rc)
14091409
goto bad;
14101410
return 0;
@@ -1413,7 +1413,7 @@ static int role_read(struct policydb *p, struct hashtab *h, void *fp)
14131413
return rc;
14141414
}
14151415

1416-
static int type_read(struct policydb *p, struct hashtab *h, void *fp)
1416+
static int type_read(struct policydb *p, struct symtab *s, void *fp)
14171417
{
14181418
char *key = NULL;
14191419
struct type_datum *typdatum;
@@ -1451,7 +1451,7 @@ static int type_read(struct policydb *p, struct hashtab *h, void *fp)
14511451
if (rc)
14521452
goto bad;
14531453

1454-
rc = hashtab_insert(h, key, typdatum);
1454+
rc = symtab_insert(s, key, typdatum);
14551455
if (rc)
14561456
goto bad;
14571457
return 0;
@@ -1487,7 +1487,7 @@ static int mls_read_level(struct mls_level *lp, void *fp)
14871487
return 0;
14881488
}
14891489

1490-
static int user_read(struct policydb *p, struct hashtab *h, void *fp)
1490+
static int user_read(struct policydb *p, struct symtab *s, void *fp)
14911491
{
14921492
char *key = NULL;
14931493
struct user_datum *usrdatum;
@@ -1528,7 +1528,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
15281528
goto bad;
15291529
}
15301530

1531-
rc = hashtab_insert(h, key, usrdatum);
1531+
rc = symtab_insert(s, key, usrdatum);
15321532
if (rc)
15331533
goto bad;
15341534
return 0;
@@ -1537,7 +1537,7 @@ static int user_read(struct policydb *p, struct hashtab *h, void *fp)
15371537
return rc;
15381538
}
15391539

1540-
static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
1540+
static int sens_read(struct policydb *p, struct symtab *s, void *fp)
15411541
{
15421542
char *key = NULL;
15431543
struct level_datum *levdatum;
@@ -1569,7 +1569,7 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
15691569
if (rc)
15701570
goto bad;
15711571

1572-
rc = hashtab_insert(h, key, levdatum);
1572+
rc = symtab_insert(s, key, levdatum);
15731573
if (rc)
15741574
goto bad;
15751575
return 0;
@@ -1578,7 +1578,7 @@ static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
15781578
return rc;
15791579
}
15801580

1581-
static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
1581+
static int cat_read(struct policydb *p, struct symtab *s, void *fp)
15821582
{
15831583
char *key = NULL;
15841584
struct cat_datum *catdatum;
@@ -1602,7 +1602,7 @@ static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
16021602
if (rc)
16031603
goto bad;
16041604

1605-
rc = hashtab_insert(h, key, catdatum);
1605+
rc = symtab_insert(s, key, catdatum);
16061606
if (rc)
16071607
goto bad;
16081608
return 0;
@@ -1611,7 +1611,7 @@ static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
16111611
return rc;
16121612
}
16131613

1614-
static int (*read_f[SYM_NUM]) (struct policydb *p, struct hashtab *h, void *fp) =
1614+
static int (*read_f[SYM_NUM]) (struct policydb *p, struct symtab *s, void *fp) =
16151615
{
16161616
common_read,
16171617
class_read,
@@ -1751,7 +1751,7 @@ u16 string_to_security_class(struct policydb *p, const char *name)
17511751
{
17521752
struct class_datum *cladatum;
17531753

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

@@ -1770,9 +1770,9 @@ u32 string_to_av_perm(struct policydb *p, u16 tclass, const char *name)
17701770
cladatum = p->class_val_to_struct[tclass-1];
17711771
comdatum = cladatum->comdatum;
17721772
if (comdatum)
1773-
perdatum = hashtab_search(&comdatum->permissions.table, name);
1773+
perdatum = symtab_search(&comdatum->permissions, name);
17741774
if (!perdatum)
1775-
perdatum = hashtab_search(&cladatum->permissions.table, name);
1775+
perdatum = symtab_search(&cladatum->permissions, name);
17761776
if (!perdatum)
17771777
return 0;
17781778

@@ -2509,7 +2509,7 @@ int policydb_read(struct policydb *p, void *fp)
25092509
}
25102510

25112511
for (j = 0; j < nel; j++) {
2512-
rc = read_f[i](p, &p->symtab[i].table, fp);
2512+
rc = read_f[i](p, &p->symtab[i], fp);
25132513
if (rc)
25142514
goto bad;
25152515
}

0 commit comments

Comments
 (0)