Skip to content

Commit 35e0bb8

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 66a4f97 commit 35e0bb8

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
@@ -423,6 +423,13 @@ int avtab_read_item(struct avtab *a, struct policy_file *fp, struct policydb *po
423423
}
424424
key.specified = spec_order[i] | enabled;
425425
datum.u.data = le32_to_cpu(buf32[items++]);
426+
427+
if ((key.specified & AVTAB_TYPE) &&
428+
!policydb_simpletype_isvalid(pol, datum.u.data)) {
429+
pr_err("SELinux: avtab: invalid type\n");
430+
return -EINVAL;
431+
}
432+
426433
rc = insertf(a, &key, &datum, p);
427434
if (rc)
428435
return rc;
@@ -519,7 +526,7 @@ int avtab_read_item(struct avtab *a, struct policy_file *fp, struct policydb *po
519526
datum.u.data = le32_to_cpu(*buf32);
520527
}
521528
if ((key.specified & AVTAB_TYPE) &&
522-
!policydb_type_isvalid(pol, datum.u.data)) {
529+
!policydb_simpletype_isvalid(pol, datum.u.data)) {
523530
pr_err("SELinux: avtab: invalid type\n");
524531
return -EINVAL;
525532
}

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)
@@ -2230,6 +2247,8 @@ static int filename_trans_read_helper_compat(struct policydb *p, struct policy_f
22302247
key.name = name;
22312248

22322249
otype = le32_to_cpu(buf[3]);
2250+
if (!policydb_simpletype_isvalid(p, otype))
2251+
goto out;
22332252

22342253
last = NULL;
22352254
datum = policydb_filenametr_search(p, &key);
@@ -2352,7 +2371,7 @@ static int filename_trans_read_helper(struct policydb *p, struct policy_file *fp
23522371
datum->otype = le32_to_cpu(buf[0]);
23532372

23542373
rc = -EINVAL;
2355-
if (!policydb_type_isvalid(p, datum->otype))
2374+
if (!policydb_simpletype_isvalid(p, datum->otype))
23562375
goto out;
23572376

23582377
dst = &datum->next;

security/selinux/ss/policydb.h

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

0 commit comments

Comments
 (0)