Skip to content

Commit deb1779

Browse files
committed
selinux: check for simple types
Validate that the target of AVTAB_TYPE rules and file transitions are simple types and not attributes. Signed-off-by: Christian Göttsche <[email protected]>
1 parent 747b808 commit deb1779

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

security/selinux/ss/avtab.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ int avtab_read_item(struct avtab *a, struct policy_file *fp, struct policydb *po
426426
}
427427
key.specified = spec_order[i] | enabled;
428428
datum.u.data = le32_to_cpu(buf32[items++]);
429+
430+
if ((key.specified & AVTAB_TYPE) &&
431+
!policydb_simpletype_isvalid(pol, datum.u.data)) {
432+
pr_err("SELinux: avtab: invalid type\n");
433+
return -EINVAL;
434+
}
435+
429436
rc = insertf(a, &key, &datum, p);
430437
if (rc)
431438
return rc;
@@ -517,7 +524,7 @@ int avtab_read_item(struct avtab *a, struct policy_file *fp, struct policydb *po
517524
datum.u.data = le32_to_cpu(*buf32);
518525
}
519526
if ((key.specified & AVTAB_TYPE) &&
520-
!policydb_type_isvalid(pol, datum.u.data)) {
527+
!policydb_simpletype_isvalid(pol, datum.u.data)) {
521528
pr_err("SELinux: avtab: invalid type\n");
522529
return -EINVAL;
523530
}

security/selinux/ss/policydb.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ static int role_validate(void *key, void *datum, void *datap)
686686
}
687687

688688
ebitmap_for_each_positive_bit(&role->types, node, i) {
689-
if (!policydb_type_isvalid(p, i + 1))
689+
if (!policydb_simpletype_isvalid(p, i + 1))
690690
goto bad;
691691
}
692692

@@ -1047,6 +1047,23 @@ bool policydb_type_isvalid(const struct policydb *p, u32 type)
10471047
return true;
10481048
}
10491049

1050+
bool policydb_simpletype_isvalid(const struct policydb *p, u32 type)
1051+
{
1052+
const struct type_datum *datum;
1053+
1054+
if (!type || type > p->p_types.nprim)
1055+
return false;
1056+
1057+
datum = p->type_val_to_struct[type - 1];
1058+
if (!datum)
1059+
return false;
1060+
1061+
if (datum->attribute)
1062+
return false;
1063+
1064+
return true;
1065+
}
1066+
10501067
bool policydb_boolean_isvalid(const struct policydb *p, u32 boolean)
10511068
{
10521069
if (!boolean || boolean > p->p_bools.nprim)
@@ -2235,6 +2252,8 @@ static int filename_trans_read_helper_compat(struct policydb *p, struct policy_f
22352252
key.name = name;
22362253

22372254
otype = le32_to_cpu(buf[3]);
2255+
if (!policydb_simpletype_isvalid(p, otype))
2256+
goto out;
22382257

22392258
last = NULL;
22402259
datum = policydb_filenametr_search(p, &key);
@@ -2357,7 +2376,7 @@ static int filename_trans_read_helper(struct policydb *p, struct policy_file *fp
23572376
datum->otype = le32_to_cpu(buf[0]);
23582377

23592378
rc = -EINVAL;
2360-
if (!policydb_type_isvalid(p, datum->otype))
2379+
if (!policydb_simpletype_isvalid(p, datum->otype))
23612380
goto out;
23622381

23632382
dst = &datum->next;

security/selinux/ss/policydb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ extern int policydb_load_isids(struct policydb *p, struct sidtab *s);
323323
extern bool policydb_context_isvalid(const struct policydb *p, const struct context *c);
324324
extern bool policydb_class_isvalid(const struct policydb *p, u16 class);
325325
extern bool policydb_type_isvalid(const struct policydb *p, u32 type);
326+
extern bool policydb_simpletype_isvalid(const struct policydb *p, u32 type);
326327
extern bool policydb_role_isvalid(const struct policydb *p, u32 role);
327328
extern bool policydb_user_isvalid(const struct policydb *p, u32 user);
328329
extern bool policydb_boolean_isvalid(const struct policydb *p, u32 boolean);

0 commit comments

Comments
 (0)