Lines Matching +full:sens +full:-
1 // SPDX-License-Identifier: GPL-2.0-only
11 * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
16 * Copyright (C) 2003-2004 Tresys Technology, LLC
18 * Updated: Hewlett-Packard <paul@paul-moore.com>
20 * Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
41 /* clang-format off */
52 /* clang-format off */
65 .sym_num = SYM_NUM - 3,
66 .ocon_num = OCON_NUM - 3,
70 .sym_num = SYM_NUM - 2,
71 .ocon_num = OCON_NUM - 3,
75 .sym_num = SYM_NUM - 2,
76 .ocon_num = OCON_NUM - 2,
80 .sym_num = SYM_NUM - 2,
81 .ocon_num = OCON_NUM - 2,
86 .ocon_num = OCON_NUM - 2,
91 .ocon_num = OCON_NUM - 2,
96 .ocon_num = OCON_NUM - 2,
101 .ocon_num = OCON_NUM - 2,
106 .ocon_num = OCON_NUM - 2,
111 .ocon_num = OCON_NUM - 2,
116 .ocon_num = OCON_NUM - 2,
121 .ocon_num = OCON_NUM - 2,
126 .ocon_num = OCON_NUM - 2,
131 .ocon_num = OCON_NUM - 2,
136 .ocon_num = OCON_NUM - 2,
141 .ocon_num = OCON_NUM - 2,
193 hashtab_map(&comdatum->permissions.table, perm_destroy, NULL); in common_destroy()
194 hashtab_destroy(&comdatum->permissions.table); in common_destroy()
203 ebitmap_destroy(&expr->names); in constraint_expr_destroy()
204 if (expr->type_names) { in constraint_expr_destroy()
205 ebitmap_destroy(&expr->type_names->types); in constraint_expr_destroy()
206 ebitmap_destroy(&expr->type_names->negset); in constraint_expr_destroy()
207 kfree(expr->type_names); in constraint_expr_destroy()
222 hashtab_map(&cladatum->permissions.table, perm_destroy, NULL); in cls_destroy()
223 hashtab_destroy(&cladatum->permissions.table); in cls_destroy()
224 constraint = cladatum->constraints; in cls_destroy()
226 e = constraint->expr; in cls_destroy()
229 e = e->next; in cls_destroy()
233 constraint = constraint->next; in cls_destroy()
237 constraint = cladatum->validatetrans; in cls_destroy()
239 e = constraint->expr; in cls_destroy()
242 e = e->next; in cls_destroy()
246 constraint = constraint->next; in cls_destroy()
249 kfree(cladatum->comkey); in cls_destroy()
262 ebitmap_destroy(&role->dominates); in role_destroy()
263 ebitmap_destroy(&role->types); in role_destroy()
283 ebitmap_destroy(&usrdatum->roles); in user_destroy()
284 ebitmap_destroy(&usrdatum->range.level[0].cat); in user_destroy()
285 ebitmap_destroy(&usrdatum->range.level[1].cat); in user_destroy()
286 ebitmap_destroy(&usrdatum->dfltlevel.cat); in user_destroy()
299 if (levdatum->level) in sens_destroy()
300 ebitmap_destroy(&levdatum->level->cat); in sens_destroy()
301 kfree(levdatum->level); in sens_destroy()
314 /* clang-format off */
325 /* clang-format on */
332 kfree(ft->name); in filenametr_destroy()
335 ebitmap_destroy(&d->stypes); in filenametr_destroy()
336 next = d->next; in filenametr_destroy()
349 ebitmap_destroy(&rt->level[0].cat); in range_tr_destroy()
350 ebitmap_destroy(&rt->level[1].cat); in range_tr_destroy()
368 context_destroy(&c->context[0]); in ocontext_destroy()
369 context_destroy(&c->context[1]); in ocontext_destroy()
372 kfree(c->u.name); in ocontext_destroy()
387 return -ENOMEM; in roles_init()
389 rc = -EINVAL; in roles_init()
390 role->value = ++p->p_roles.nprim; in roles_init()
391 if (role->value != OBJECT_R_VAL) in roles_init()
394 rc = -ENOMEM; in roles_init()
399 rc = symtab_insert(&p->p_roles, key, role); in roles_init()
413 unsigned long salt = ft->ttype ^ ft->tclass; in filenametr_hash()
415 return full_name_hash((void *)salt, ft->name, strlen(ft->name)); in filenametr_hash()
424 v = ft1->ttype - ft2->ttype; in filenametr_cmp()
428 v = ft1->tclass - ft2->tclass; in filenametr_cmp()
432 return strcmp(ft1->name, ft2->name); in filenametr_cmp()
443 return hashtab_search(&p->filename_trans, key, filenametr_key_params); in policydb_filenametr_search()
450 return key->source_type + (key->target_type << 3) + in rangetr_hash()
451 (key->target_class << 5); in rangetr_hash()
459 v = key1->source_type - key2->source_type; in rangetr_cmp()
463 v = key1->target_type - key2->target_type; in rangetr_cmp()
467 v = key1->target_class - key2->target_class; in rangetr_cmp()
480 return hashtab_search(&p->range_tr, key, rangetr_key_params); in policydb_rangetr_search()
487 return jhash_3words(key->role, key->type, in role_trans_hash()
488 (u32)key->tclass << 16 | key->tclass, 0); in role_trans_hash()
496 v = key1->role - key2->role; in role_trans_cmp()
500 v = key1->type - key2->type; in role_trans_cmp()
504 return key1->tclass - key2->tclass; in role_trans_cmp()
515 return hashtab_search(&p->role_tr, key, roletr_key_params); in policydb_roletr_search()
525 avtab_init(&p->te_avtab); in policydb_init()
528 ebitmap_init(&p->filename_trans_ttypes); in policydb_init()
529 ebitmap_init(&p->policycaps); in policydb_init()
530 ebitmap_init(&p->permissive_map); in policydb_init()
550 if (!comdatum->value || comdatum->value > p->p_commons.nprim) in common_index()
551 return -EINVAL; in common_index()
553 p->sym_val_to_name[SYM_COMMONS][comdatum->value - 1] = key; in common_index()
565 if (!cladatum->value || cladatum->value > p->p_classes.nprim) in class_index()
566 return -EINVAL; in class_index()
568 p->sym_val_to_name[SYM_CLASSES][cladatum->value - 1] = key; in class_index()
569 p->class_val_to_struct[cladatum->value - 1] = cladatum; in class_index()
580 if (!role->value || role->value > p->p_roles.nprim || in role_index()
581 role->bounds > p->p_roles.nprim) in role_index()
582 return -EINVAL; in role_index()
584 p->sym_val_to_name[SYM_ROLES][role->value - 1] = key; in role_index()
585 p->role_val_to_struct[role->value - 1] = role; in role_index()
597 if (typdatum->primary) { in type_index()
598 if (!typdatum->value || typdatum->value > p->p_types.nprim || in type_index()
599 typdatum->bounds > p->p_types.nprim) in type_index()
600 return -EINVAL; in type_index()
601 p->sym_val_to_name[SYM_TYPES][typdatum->value - 1] = key; in type_index()
602 p->type_val_to_struct[typdatum->value - 1] = typdatum; in type_index()
615 if (!usrdatum->value || usrdatum->value > p->p_users.nprim || in user_index()
616 usrdatum->bounds > p->p_users.nprim) in user_index()
617 return -EINVAL; in user_index()
619 p->sym_val_to_name[SYM_USERS][usrdatum->value - 1] = key; in user_index()
620 p->user_val_to_struct[usrdatum->value - 1] = usrdatum; in user_index()
632 if (!levdatum->isalias) { in sens_index()
633 if (!levdatum->level->sens || in sens_index()
634 levdatum->level->sens > p->p_levels.nprim) in sens_index()
635 return -EINVAL; in sens_index()
637 p->sym_val_to_name[SYM_LEVELS][levdatum->level->sens - 1] = key; in sens_index()
651 if (!catdatum->isalias) { in cat_index()
652 if (!catdatum->value || catdatum->value > p->p_cats.nprim) in cat_index()
653 return -EINVAL; in cat_index()
655 p->sym_val_to_name[SYM_CATS][catdatum->value - 1] = key; in cat_index()
661 /* clang-format off */
672 /* clang-format on */
683 hash_name, hash_details ? "@" : "", hash_details ?: "", h->nel, in hash_eval()
684 info.slots_used, h->size, info.max_chain_len, in hash_eval()
716 if (p->mls_enabled) in policydb_index()
718 "SELinux: %d users, %d roles, %d types, %d bools, %d sens, %d cats\n", in policydb_index()
719 p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, in policydb_index()
720 p->p_bools.nprim, p->p_levels.nprim, p->p_cats.nprim); in policydb_index()
723 p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, in policydb_index()
724 p->p_bools.nprim); in policydb_index()
726 pr_debug("SELinux: %d classes, %d rules\n", p->p_classes.nprim, in policydb_index()
727 p->te_avtab.nel); in policydb_index()
729 avtab_hash_eval(&p->te_avtab, "rules"); in policydb_index()
730 symtab_hash_eval(p->symtab); in policydb_index()
732 p->class_val_to_struct = kcalloc(p->p_classes.nprim, in policydb_index()
733 sizeof(*p->class_val_to_struct), in policydb_index()
735 if (!p->class_val_to_struct) in policydb_index()
736 return -ENOMEM; in policydb_index()
738 p->role_val_to_struct = kcalloc( in policydb_index()
739 p->p_roles.nprim, sizeof(*p->role_val_to_struct), GFP_KERNEL); in policydb_index()
740 if (!p->role_val_to_struct) in policydb_index()
741 return -ENOMEM; in policydb_index()
743 p->user_val_to_struct = kcalloc( in policydb_index()
744 p->p_users.nprim, sizeof(*p->user_val_to_struct), GFP_KERNEL); in policydb_index()
745 if (!p->user_val_to_struct) in policydb_index()
746 return -ENOMEM; in policydb_index()
748 p->type_val_to_struct = kvcalloc( in policydb_index()
749 p->p_types.nprim, sizeof(*p->type_val_to_struct), GFP_KERNEL); in policydb_index()
750 if (!p->type_val_to_struct) in policydb_index()
751 return -ENOMEM; in policydb_index()
758 p->sym_val_to_name[i] = kvcalloc(p->symtab[i].nprim, in policydb_index()
760 if (!p->sym_val_to_name[i]) in policydb_index()
761 return -ENOMEM; in policydb_index()
763 rc = hashtab_map(&p->symtab[i].table, index_f[i], p); in policydb_index()
784 hashtab_map(&p->symtab[i].table, destroy_f[i], NULL); in policydb_destroy()
785 hashtab_destroy(&p->symtab[i].table); in policydb_destroy()
789 kvfree(p->sym_val_to_name[i]); in policydb_destroy()
791 kfree(p->class_val_to_struct); in policydb_destroy()
792 kfree(p->role_val_to_struct); in policydb_destroy()
793 kfree(p->user_val_to_struct); in policydb_destroy()
794 kvfree(p->type_val_to_struct); in policydb_destroy()
796 avtab_destroy(&p->te_avtab); in policydb_destroy()
800 c = p->ocontexts[i]; in policydb_destroy()
803 c = c->next; in policydb_destroy()
806 p->ocontexts[i] = NULL; in policydb_destroy()
809 g = p->genfs; in policydb_destroy()
812 kfree(g->fstype); in policydb_destroy()
813 c = g->head; in policydb_destroy()
816 c = c->next; in policydb_destroy()
820 g = g->next; in policydb_destroy()
823 p->genfs = NULL; in policydb_destroy()
827 hashtab_map(&p->role_tr, role_tr_destroy, NULL); in policydb_destroy()
828 hashtab_destroy(&p->role_tr); in policydb_destroy()
830 for (ra = p->role_allow; ra; ra = ra->next) { in policydb_destroy()
837 hashtab_map(&p->filename_trans, filenametr_destroy, NULL); in policydb_destroy()
838 hashtab_destroy(&p->filename_trans); in policydb_destroy()
840 hashtab_map(&p->range_tr, range_tr_destroy, NULL); in policydb_destroy()
841 hashtab_destroy(&p->range_tr); in policydb_destroy()
843 if (p->type_attr_map_array) { in policydb_destroy()
844 for (i = 0; i < p->p_types.nprim; i++) in policydb_destroy()
845 ebitmap_destroy(&p->type_attr_map_array[i]); in policydb_destroy()
846 kvfree(p->type_attr_map_array); in policydb_destroy()
849 ebitmap_destroy(&p->filename_trans_ttypes); in policydb_destroy()
850 ebitmap_destroy(&p->policycaps); in policydb_destroy()
851 ebitmap_destroy(&p->permissive_map); in policydb_destroy()
870 isid_init = ebitmap_get_bit(&p->policycaps, in policydb_load_isids()
873 head = p->ocontexts[OCON_ISID]; in policydb_load_isids()
874 for (c = head; c; c = c->next) { in policydb_load_isids()
875 u32 sid = c->sid[0]; in policydb_load_isids()
881 return -EINVAL; in policydb_load_isids()
895 rc = sidtab_set_initial(s, sid, &c->context[0]); in policydb_load_isids()
913 &c->context[0]); in policydb_load_isids()
927 if (!class || class > p->p_classes.nprim) in policydb_class_isvalid()
934 if (!role || role > p->p_roles.nprim) in policydb_role_isvalid()
941 if (!type || type > p->p_types.nprim) in policydb_type_isvalid()
955 if (!c->role || c->role > p->p_roles.nprim) in policydb_context_isvalid()
958 if (!c->user || c->user > p->p_users.nprim) in policydb_context_isvalid()
961 if (!c->type || c->type > p->p_types.nprim) in policydb_context_isvalid()
964 if (c->role != OBJECT_R_VAL) { in policydb_context_isvalid()
968 role = p->role_val_to_struct[c->role - 1]; in policydb_context_isvalid()
969 if (!role || !ebitmap_get_bit(&role->types, c->type - 1)) in policydb_context_isvalid()
976 usrdatum = p->user_val_to_struct[c->user - 1]; in policydb_context_isvalid()
980 if (!ebitmap_get_bit(&usrdatum->roles, c->role - 1)) in policydb_context_isvalid()
1005 rc = -EINVAL; in mls_read_range_helper()
1018 r->level[0].sens = le32_to_cpu(buf[0]); in mls_read_range_helper()
1020 r->level[1].sens = le32_to_cpu(buf[1]); in mls_read_range_helper()
1022 r->level[1].sens = r->level[0].sens; in mls_read_range_helper()
1024 rc = ebitmap_read(&r->level[0].cat, fp); in mls_read_range_helper()
1030 rc = ebitmap_read(&r->level[1].cat, fp); in mls_read_range_helper()
1036 rc = ebitmap_cpy(&r->level[1].cat, &r->level[0].cat); in mls_read_range_helper()
1045 ebitmap_destroy(&r->level[0].cat); in mls_read_range_helper()
1065 c->user = le32_to_cpu(buf[0]); in context_read_and_validate()
1066 c->role = le32_to_cpu(buf[1]); in context_read_and_validate()
1067 c->type = le32_to_cpu(buf[2]); in context_read_and_validate()
1068 if (p->policyvers >= POLICYDB_VERSION_MLS) { in context_read_and_validate()
1069 rc = mls_read_range_helper(&c->range, fp); in context_read_and_validate()
1076 rc = -EINVAL; in context_read_and_validate()
1098 if ((len == 0) || (len == (u32)-1)) in str_read()
1099 return -EINVAL; in str_read()
1103 return -ENOMEM; in str_read()
1126 return -ENOMEM; in perm_read()
1133 perdatum->value = le32_to_cpu(buf[1]); in perm_read()
1159 return -ENOMEM; in common_read()
1166 comdatum->value = le32_to_cpu(buf[1]); in common_read()
1169 rc = symtab_init(&comdatum->permissions, nel); in common_read()
1172 comdatum->permissions.nprim = le32_to_cpu(buf[2]); in common_read()
1179 rc = perm_read(p, &comdatum->permissions, fp); in common_read()
1184 hash_eval(&comdatum->permissions.table, "common_permissions", key); in common_read()
1197 ebitmap_init(&t->types); in type_set_init()
1198 ebitmap_init(&t->negset); in type_set_init()
1206 if (ebitmap_read(&t->types, fp)) in type_set_read()
1207 return -EINVAL; in type_set_read()
1208 if (ebitmap_read(&t->negset, fp)) in type_set_read()
1209 return -EINVAL; in type_set_read()
1213 return -EINVAL; in type_set_read()
1214 t->flags = le32_to_cpu(buf[0]); in type_set_read()
1232 return -ENOMEM; in read_cons_helper()
1235 lc->next = c; in read_cons_helper()
1242 c->permissions = le32_to_cpu(buf[0]); in read_cons_helper()
1245 depth = -1; in read_cons_helper()
1249 return -ENOMEM; in read_cons_helper()
1252 le->next = e; in read_cons_helper()
1254 c->expr = e; in read_cons_helper()
1259 e->expr_type = le32_to_cpu(buf[0]); in read_cons_helper()
1260 e->attr = le32_to_cpu(buf[1]); in read_cons_helper()
1261 e->op = le32_to_cpu(buf[2]); in read_cons_helper()
1263 switch (e->expr_type) { in read_cons_helper()
1266 return -EINVAL; in read_cons_helper()
1271 return -EINVAL; in read_cons_helper()
1272 depth--; in read_cons_helper()
1275 if (depth == (CEXPR_MAXDEPTH - 1)) in read_cons_helper()
1276 return -EINVAL; in read_cons_helper()
1280 if (!allowxtarget && (e->attr & CEXPR_XTARGET)) in read_cons_helper()
1281 return -EINVAL; in read_cons_helper()
1282 if (depth == (CEXPR_MAXDEPTH - 1)) in read_cons_helper()
1283 return -EINVAL; in read_cons_helper()
1285 rc = ebitmap_read(&e->names, fp); in read_cons_helper()
1288 if (p->policyvers >= in read_cons_helper()
1290 e->type_names = in read_cons_helper()
1291 kzalloc(sizeof(*e->type_names), in read_cons_helper()
1293 if (!e->type_names) in read_cons_helper()
1294 return -ENOMEM; in read_cons_helper()
1295 type_set_init(e->type_names); in read_cons_helper()
1296 rc = type_set_read(e->type_names, fp); in read_cons_helper()
1302 return -EINVAL; in read_cons_helper()
1307 return -EINVAL; in read_cons_helper()
1324 return -ENOMEM; in class_read()
1332 cladatum->value = le32_to_cpu(buf[2]); in class_read()
1335 rc = symtab_init(&cladatum->permissions, nel); in class_read()
1338 cladatum->permissions.nprim = le32_to_cpu(buf[3]); in class_read()
1347 rc = str_read(&cladatum->comkey, GFP_KERNEL, fp, len2); in class_read()
1351 rc = -EINVAL; in class_read()
1352 cladatum->comdatum = in class_read()
1353 symtab_search(&p->p_commons, cladatum->comkey); in class_read()
1354 if (!cladatum->comdatum) { in class_read()
1356 cladatum->comkey); in class_read()
1361 rc = perm_read(p, &cladatum->permissions, fp); in class_read()
1366 hash_eval(&cladatum->permissions.table, "class_permissions", key); in class_read()
1368 rc = read_cons_helper(p, &cladatum->constraints, ncons, 0, fp); in class_read()
1372 if (p->policyvers >= POLICYDB_VERSION_VALIDATETRANS) { in class_read()
1378 rc = read_cons_helper(p, &cladatum->validatetrans, ncons, 1, in class_read()
1384 if (p->policyvers >= POLICYDB_VERSION_NEW_OBJECT_DEFAULTS) { in class_read()
1389 cladatum->default_user = le32_to_cpu(buf[0]); in class_read()
1390 cladatum->default_role = le32_to_cpu(buf[1]); in class_read()
1391 cladatum->default_range = le32_to_cpu(buf[2]); in class_read()
1394 if (p->policyvers >= POLICYDB_VERSION_DEFAULT_TYPE) { in class_read()
1398 cladatum->default_type = le32_to_cpu(buf[0]); in class_read()
1422 return -ENOMEM; in role_read()
1424 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) in role_read()
1432 role->value = le32_to_cpu(buf[1]); in role_read()
1433 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) in role_read()
1434 role->bounds = le32_to_cpu(buf[2]); in role_read()
1440 rc = ebitmap_read(&role->dominates, fp); in role_read()
1444 rc = ebitmap_read(&role->types, fp); in role_read()
1449 rc = -EINVAL; in role_read()
1450 if (role->value != OBJECT_R_VAL) { in role_read()
1452 OBJECT_R, role->value); in role_read()
1479 return -ENOMEM; in type_read()
1481 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) in type_read()
1489 typdatum->value = le32_to_cpu(buf[1]); in type_read()
1490 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) { in type_read()
1494 typdatum->primary = 1; in type_read()
1496 typdatum->attribute = 1; in type_read()
1498 typdatum->bounds = le32_to_cpu(buf[3]); in type_read()
1500 typdatum->primary = le32_to_cpu(buf[2]); in type_read()
1532 lp->sens = le32_to_cpu(buf[0]); in mls_read_level()
1534 rc = ebitmap_read(&lp->cat, fp); in mls_read_level()
1553 return -ENOMEM; in user_read()
1555 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) in user_read()
1563 usrdatum->value = le32_to_cpu(buf[1]); in user_read()
1564 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) in user_read()
1565 usrdatum->bounds = le32_to_cpu(buf[2]); in user_read()
1571 rc = ebitmap_read(&usrdatum->roles, fp); in user_read()
1575 if (p->policyvers >= POLICYDB_VERSION_MLS) { in user_read()
1576 rc = mls_read_range_helper(&usrdatum->range, fp); in user_read()
1579 rc = mls_read_level(&usrdatum->dfltlevel, fp); in user_read()
1603 return -ENOMEM; in sens_read()
1610 levdatum->isalias = le32_to_cpu(buf[1]); in sens_read()
1616 rc = -ENOMEM; in sens_read()
1617 levdatum->level = kmalloc(sizeof(*levdatum->level), GFP_KERNEL); in sens_read()
1618 if (!levdatum->level) in sens_read()
1621 rc = mls_read_level(levdatum->level, fp); in sens_read()
1644 return -ENOMEM; in cat_read()
1651 catdatum->value = le32_to_cpu(buf[1]); in cat_read()
1652 catdatum->isalias = le32_to_cpu(buf[2]); in cat_read()
1667 /* clang-format off */
1679 /* clang-format on */
1688 while (upper->bounds) { in user_bounds_sanity_check()
1696 return -EINVAL; in user_bounds_sanity_check()
1699 upper = p->user_val_to_struct[upper->bounds - 1]; in user_bounds_sanity_check()
1700 ebitmap_for_each_positive_bit(&user->roles, node, bit) in user_bounds_sanity_check()
1702 if (ebitmap_get_bit(&upper->roles, bit)) in user_bounds_sanity_check()
1707 sym_name(p, SYM_USERS, user->value - 1), in user_bounds_sanity_check()
1709 sym_name(p, SYM_USERS, upper->value - 1)); in user_bounds_sanity_check()
1711 return -EINVAL; in user_bounds_sanity_check()
1725 while (upper->bounds) { in role_bounds_sanity_check()
1733 return -EINVAL; in role_bounds_sanity_check()
1736 upper = p->role_val_to_struct[upper->bounds - 1]; in role_bounds_sanity_check()
1737 ebitmap_for_each_positive_bit(&role->types, node, bit) in role_bounds_sanity_check()
1739 if (ebitmap_get_bit(&upper->types, bit)) in role_bounds_sanity_check()
1744 sym_name(p, SYM_ROLES, role->value - 1), in role_bounds_sanity_check()
1746 sym_name(p, SYM_ROLES, upper->value - 1)); in role_bounds_sanity_check()
1748 return -EINVAL; in role_bounds_sanity_check()
1762 while (upper->bounds) { in type_bounds_sanity_check()
1767 return -EINVAL; in type_bounds_sanity_check()
1770 upper = p->type_val_to_struct[upper->bounds - 1]; in type_bounds_sanity_check()
1773 if (upper->attribute) { in type_bounds_sanity_check()
1777 sym_name(p, SYM_TYPES, upper->value - 1)); in type_bounds_sanity_check()
1778 return -EINVAL; in type_bounds_sanity_check()
1789 if (p->policyvers < POLICYDB_VERSION_BOUNDARY) in policydb_bounds_sanity_check()
1792 rc = hashtab_map(&p->p_users.table, user_bounds_sanity_check, p); in policydb_bounds_sanity_check()
1796 rc = hashtab_map(&p->p_roles.table, role_bounds_sanity_check, p); in policydb_bounds_sanity_check()
1800 rc = hashtab_map(&p->p_types.table, type_bounds_sanity_check, p); in policydb_bounds_sanity_check()
1811 cladatum = symtab_search(&p->p_classes, name); in string_to_security_class()
1815 return cladatum->value; in string_to_security_class()
1824 if (!tclass || tclass > p->p_classes.nprim) in string_to_av_perm()
1827 cladatum = p->class_val_to_struct[tclass - 1]; in string_to_av_perm()
1828 comdatum = cladatum->comdatum; in string_to_av_perm()
1830 perdatum = symtab_search(&comdatum->permissions, name); in string_to_av_perm()
1832 perdatum = symtab_search(&cladatum->permissions, name); in string_to_av_perm()
1836 return 1U << (perdatum->value - 1); in string_to_av_perm()
1847 if (p->policyvers < POLICYDB_VERSION_MLS) in range_read()
1856 rc = hashtab_init(&p->range_tr, nel); in range_read()
1861 rc = -ENOMEM; in range_read()
1870 rt->source_type = le32_to_cpu(buf[0]); in range_read()
1871 rt->target_type = le32_to_cpu(buf[1]); in range_read()
1872 if (p->policyvers >= POLICYDB_VERSION_RANGETRANS) { in range_read()
1876 rt->target_class = le32_to_cpu(buf[0]); in range_read()
1878 rt->target_class = p->process_class; in range_read()
1880 rc = -EINVAL; in range_read()
1881 if (!policydb_type_isvalid(p, rt->source_type) || in range_read()
1882 !policydb_type_isvalid(p, rt->target_type) || in range_read()
1883 !policydb_class_isvalid(p, rt->target_class)) in range_read()
1886 rc = -ENOMEM; in range_read()
1895 rc = -EINVAL; in range_read()
1901 rc = hashtab_insert(&p->range_tr, rt, r, rangetr_key_params); in range_read()
1908 hash_eval(&p->range_tr, "rangetr", NULL); in range_read()
1950 if (unlikely(ebitmap_get_bit(&datum->stypes, stype - 1))) { in filename_trans_read_helper_compat()
1956 if (likely(datum->otype == otype)) in filename_trans_read_helper_compat()
1959 datum = datum->next; in filename_trans_read_helper_compat()
1962 rc = -ENOMEM; in filename_trans_read_helper_compat()
1967 ebitmap_init(&datum->stypes); in filename_trans_read_helper_compat()
1968 datum->otype = otype; in filename_trans_read_helper_compat()
1969 datum->next = NULL; in filename_trans_read_helper_compat()
1972 last->next = datum; in filename_trans_read_helper_compat()
1974 rc = -ENOMEM; in filename_trans_read_helper_compat()
1979 rc = hashtab_insert(&p->filename_trans, ft, datum, in filename_trans_read_helper_compat()
1985 rc = ebitmap_set_bit(&p->filename_trans_ttypes, in filename_trans_read_helper_compat()
1992 return ebitmap_set_bit(&datum->stypes, stype - 1, 1); in filename_trans_read_helper_compat()
2031 rc = -ENOENT; in filename_trans_read_helper()
2037 rc = -ENOMEM; in filename_trans_read_helper()
2042 datum->next = NULL; in filename_trans_read_helper()
2046 rc = ebitmap_read(&datum->stypes, fp); in filename_trans_read_helper()
2054 datum->otype = le32_to_cpu(buf[0]); in filename_trans_read_helper()
2056 dst = &datum->next; in filename_trans_read_helper()
2059 rc = -ENOMEM; in filename_trans_read_helper()
2064 ft->ttype = ttype; in filename_trans_read_helper()
2065 ft->tclass = tclass; in filename_trans_read_helper()
2066 ft->name = name; in filename_trans_read_helper()
2068 rc = hashtab_insert(&p->filename_trans, ft, first, in filename_trans_read_helper()
2070 if (rc == -EEXIST) in filename_trans_read_helper()
2075 return ebitmap_set_bit(&p->filename_trans_ttypes, ttype, 1); in filename_trans_read_helper()
2082 first = first->next; in filename_trans_read_helper()
2084 ebitmap_destroy(&datum->stypes); in filename_trans_read_helper()
2096 if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS) in filename_trans_read()
2104 if (p->policyvers < POLICYDB_VERSION_COMP_FTRANS) { in filename_trans_read()
2105 p->compat_filename_trans_count = nel; in filename_trans_read()
2107 rc = hashtab_init(&p->filename_trans, (1 << 11)); in filename_trans_read()
2117 rc = hashtab_init(&p->filename_trans, nel); in filename_trans_read()
2127 hash_eval(&p->filename_trans, "filenametr", NULL); in filename_trans_read()
2152 rc = -ENOMEM; in genfs_read()
2157 rc = str_read(&newgenfs->fstype, GFP_KERNEL, fp, len); in genfs_read()
2161 for (genfs_p = NULL, genfs = p->genfs; genfs; in genfs_read()
2162 genfs_p = genfs, genfs = genfs->next) { in genfs_read()
2163 rc = -EINVAL; in genfs_read()
2164 if (strcmp(newgenfs->fstype, genfs->fstype) == 0) { in genfs_read()
2166 newgenfs->fstype); in genfs_read()
2169 if (strcmp(newgenfs->fstype, genfs->fstype) < 0) in genfs_read()
2172 newgenfs->next = genfs; in genfs_read()
2174 genfs_p->next = newgenfs; in genfs_read()
2176 p->genfs = newgenfs; in genfs_read()
2191 rc = -ENOMEM; in genfs_read()
2196 rc = str_read(&newc->u.name, GFP_KERNEL, fp, len); in genfs_read()
2204 newc->v.sclass = le32_to_cpu(buf[0]); in genfs_read()
2205 rc = context_read_and_validate(&newc->context[0], p, in genfs_read()
2210 for (l = NULL, c = genfs->head; c; l = c, c = c->next) { in genfs_read()
2211 rc = -EINVAL; in genfs_read()
2212 if (!strcmp(newc->u.name, c->u.name) && in genfs_read()
2213 (!c->v.sclass || !newc->v.sclass || in genfs_read()
2214 newc->v.sclass == c->v.sclass)) { in genfs_read()
2216 genfs->fstype, c->u.name); in genfs_read()
2219 len = strlen(newc->u.name); in genfs_read()
2220 len2 = strlen(c->u.name); in genfs_read()
2225 newc->next = c; in genfs_read()
2227 l->next = newc; in genfs_read()
2229 genfs->head = newc; in genfs_read()
2236 kfree(newgenfs->fstype); in genfs_read()
2255 for (i = 0; i < info->ocon_num; i++) { in ocontext_read()
2263 rc = -ENOMEM; in ocontext_read()
2268 l->next = c; in ocontext_read()
2270 p->ocontexts[i] = c; in ocontext_read()
2279 c->sid[0] = le32_to_cpu(buf[0]); in ocontext_read()
2280 rc = context_read_and_validate(&c->context[0], in ocontext_read()
2292 rc = str_read(&c->u.name, GFP_KERNEL, fp, len); in ocontext_read()
2298 c->u.name); in ocontext_read()
2300 rc = context_read_and_validate(&c->context[0], in ocontext_read()
2304 rc = context_read_and_validate(&c->context[1], in ocontext_read()
2313 c->u.port.protocol = le32_to_cpu(buf[0]); in ocontext_read()
2314 c->u.port.low_port = le32_to_cpu(buf[1]); in ocontext_read()
2315 c->u.port.high_port = le32_to_cpu(buf[2]); in ocontext_read()
2316 rc = context_read_and_validate(&c->context[0], in ocontext_read()
2325 c->u.node.addr = nodebuf[0]; /* network order */ in ocontext_read()
2326 c->u.node.mask = nodebuf[1]; /* network order */ in ocontext_read()
2327 rc = context_read_and_validate(&c->context[0], in ocontext_read()
2337 rc = -EINVAL; in ocontext_read()
2338 c->v.behavior = le32_to_cpu(buf[0]); in ocontext_read()
2340 if (c->v.behavior == SECURITY_FS_USE_MNTPOINT) in ocontext_read()
2342 if (c->v.behavior > SECURITY_FS_USE_MAX) in ocontext_read()
2346 rc = str_read(&c->u.name, GFP_KERNEL, fp, len); in ocontext_read()
2350 rc = context_read_and_validate(&c->context[0], in ocontext_read()
2362 c->u.node6.addr[k] = nodebuf[k]; in ocontext_read()
2364 c->u.node6.mask[k] = nodebuf[k + 4]; in ocontext_read()
2365 rc = context_read_and_validate(&c->context[0], in ocontext_read()
2379 c->u.ibpkey.subnet_prefix = in ocontext_read()
2390 rc = -EINVAL; in ocontext_read()
2394 c->u.ibpkey.low_pkey = pkey_lo; in ocontext_read()
2395 c->u.ibpkey.high_pkey = pkey_hi; in ocontext_read()
2397 rc = context_read_and_validate(&c->context[0], in ocontext_read()
2411 rc = str_read(&c->u.ibendport.dev_name, in ocontext_read()
2418 rc = -EINVAL; in ocontext_read()
2422 c->u.ibendport.port = port; in ocontext_read()
2424 rc = context_read_and_validate(&c->context[0], in ocontext_read()
2461 rc = -EINVAL; in policydb_read()
2469 rc = -EINVAL; in policydb_read()
2478 rc = -ENOMEM; in policydb_read()
2494 rc = -EINVAL; in policydb_read()
2512 rc = -EINVAL; in policydb_read()
2513 p->policyvers = le32_to_cpu(buf[0]); in policydb_read()
2514 if (p->policyvers < POLICYDB_VERSION_MIN || in policydb_read()
2515 p->policyvers > POLICYDB_VERSION_MAX) { in policydb_read()
2517 "my version range %d-%d\n", in policydb_read()
2524 p->mls_enabled = 1; in policydb_read()
2526 rc = -EINVAL; in policydb_read()
2527 if (p->policyvers < POLICYDB_VERSION_MLS) { in policydb_read()
2530 p->policyvers); in policydb_read()
2534 p->reject_unknown = !!(le32_to_cpu(buf[1]) & REJECT_UNKNOWN); in policydb_read()
2535 p->allow_unknown = !!(le32_to_cpu(buf[1]) & ALLOW_UNKNOWN); in policydb_read()
2537 if (p->policyvers >= POLICYDB_VERSION_POLCAP) { in policydb_read()
2538 rc = ebitmap_read(&p->policycaps, fp); in policydb_read()
2543 if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE) { in policydb_read()
2544 rc = ebitmap_read(&p->permissive_map, fp); in policydb_read()
2549 rc = -EINVAL; in policydb_read()
2550 info = policydb_lookup_compat(p->policyvers); in policydb_read()
2554 p->policyvers); in policydb_read()
2558 rc = -EINVAL; in policydb_read()
2559 if (le32_to_cpu(buf[2]) != info->sym_num || in policydb_read()
2560 le32_to_cpu(buf[3]) != info->ocon_num) { in policydb_read()
2563 le32_to_cpu(buf[2]), le32_to_cpu(buf[3]), info->sym_num, in policydb_read()
2564 info->ocon_num); in policydb_read()
2568 for (i = 0; i < info->sym_num; i++) { in policydb_read()
2575 rc = symtab_init(&p->symtab[i], nel); in policydb_read()
2586 rc = read_f[i](p, &p->symtab[i], fp); in policydb_read()
2591 p->symtab[i].nprim = nprim; in policydb_read()
2594 rc = -EINVAL; in policydb_read()
2595 p->process_class = string_to_security_class(p, "process"); in policydb_read()
2596 if (!p->process_class) { in policydb_read()
2601 rc = avtab_read(&p->te_avtab, fp, p); in policydb_read()
2605 if (p->policyvers >= POLICYDB_VERSION_BOOL) { in policydb_read()
2616 rc = hashtab_init(&p->role_tr, nel); in policydb_read()
2620 rc = -ENOMEM; in policydb_read()
2625 rc = -ENOMEM; in policydb_read()
2634 rtk->role = le32_to_cpu(buf[0]); in policydb_read()
2635 rtk->type = le32_to_cpu(buf[1]); in policydb_read()
2636 rtd->new_role = le32_to_cpu(buf[2]); in policydb_read()
2637 if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) { in policydb_read()
2641 rtk->tclass = le32_to_cpu(buf[0]); in policydb_read()
2643 rtk->tclass = p->process_class; in policydb_read()
2645 rc = -EINVAL; in policydb_read()
2646 if (!policydb_role_isvalid(p, rtk->role) || in policydb_read()
2647 !policydb_type_isvalid(p, rtk->type) || in policydb_read()
2648 !policydb_class_isvalid(p, rtk->tclass) || in policydb_read()
2649 !policydb_role_isvalid(p, rtd->new_role)) in policydb_read()
2652 rc = hashtab_insert(&p->role_tr, rtk, rtd, roletr_key_params); in policydb_read()
2660 hash_eval(&p->role_tr, "roletr", NULL); in policydb_read()
2668 rc = -ENOMEM; in policydb_read()
2673 lra->next = ra; in policydb_read()
2675 p->role_allow = ra; in policydb_read()
2680 rc = -EINVAL; in policydb_read()
2681 ra->role = le32_to_cpu(buf[0]); in policydb_read()
2682 ra->new_role = le32_to_cpu(buf[1]); in policydb_read()
2683 if (!policydb_role_isvalid(p, ra->role) || in policydb_read()
2684 !policydb_role_isvalid(p, ra->new_role)) in policydb_read()
2697 rc = -EINVAL; in policydb_read()
2698 perm = string_to_av_perm(p, p->process_class, "transition"); in policydb_read()
2703 p->process_trans_perms = perm; in policydb_read()
2704 perm = string_to_av_perm(p, p->process_class, "dyntransition"); in policydb_read()
2709 p->process_trans_perms |= perm; in policydb_read()
2723 rc = -ENOMEM; in policydb_read()
2724 p->type_attr_map_array = kvcalloc( in policydb_read()
2725 p->p_types.nprim, sizeof(*p->type_attr_map_array), GFP_KERNEL); in policydb_read()
2726 if (!p->type_attr_map_array) in policydb_read()
2730 for (i = 0; i < p->p_types.nprim; i++) in policydb_read()
2731 ebitmap_init(&p->type_attr_map_array[i]); in policydb_read()
2733 for (i = 0; i < p->p_types.nprim; i++) { in policydb_read()
2734 struct ebitmap *e = &p->type_attr_map_array[i]; in policydb_read()
2736 if (p->policyvers >= POLICYDB_VERSION_AVTAB) { in policydb_read()
2770 buf[0] = cpu_to_le32(l->sens); in mls_write_level()
2775 rc = ebitmap_write(&l->cat, fp); in mls_write_level()
2792 eq = mls_level_eq(&r->level[1], &r->level[0]); in mls_write_range_helper()
2798 buf[0] = cpu_to_le32(items - 1); in mls_write_range_helper()
2799 buf[1] = cpu_to_le32(r->level[0].sens); in mls_write_range_helper()
2801 buf[2] = cpu_to_le32(r->level[1].sens); in mls_write_range_helper()
2809 rc = ebitmap_write(&r->level[0].cat, fp); in mls_write_range_helper()
2813 rc = ebitmap_write(&r->level[1].cat, fp); in mls_write_range_helper()
2826 void *fp = pd->fp; in sens_write()
2833 buf[1] = cpu_to_le32(levdatum->isalias); in sens_write()
2842 rc = mls_write_level(levdatum->level, fp); in sens_write()
2854 void *fp = pd->fp; in cat_write()
2861 buf[1] = cpu_to_le32(catdatum->value); in cat_write()
2862 buf[2] = cpu_to_le32(catdatum->isalias); in cat_write()
2879 void *fp = pd->fp; in role_trans_write_one()
2880 struct policydb *p = pd->p; in role_trans_write_one()
2884 buf[0] = cpu_to_le32(rtk->role); in role_trans_write_one()
2885 buf[1] = cpu_to_le32(rtk->type); in role_trans_write_one()
2886 buf[2] = cpu_to_le32(rtd->new_role); in role_trans_write_one()
2890 if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) { in role_trans_write_one()
2891 buf[0] = cpu_to_le32(rtk->tclass); in role_trans_write_one()
2905 buf[0] = cpu_to_le32(p->role_tr.nel); in role_trans_write()
2910 return hashtab_map(&p->role_tr, role_trans_write_one, &pd); in role_trans_write()
2921 for (ra = r; ra; ra = ra->next) in role_allow_write()
2927 for (ra = r; ra; ra = ra->next) { in role_allow_write()
2928 buf[0] = cpu_to_le32(ra->role); in role_allow_write()
2929 buf[1] = cpu_to_le32(ra->new_role); in role_allow_write()
2946 buf[0] = cpu_to_le32(c->user); in context_write()
2947 buf[1] = cpu_to_le32(c->role); in context_write()
2948 buf[2] = cpu_to_le32(c->type); in context_write()
2954 rc = mls_write_range_helper(&c->range, fp); in context_write()
2977 buf[1] = cpu_to_le32(perdatum->value); in perm_write()
2994 void *fp = pd->fp; in common_write()
3001 buf[1] = cpu_to_le32(comdatum->value); in common_write()
3002 buf[2] = cpu_to_le32(comdatum->permissions.nprim); in common_write()
3003 buf[3] = cpu_to_le32(comdatum->permissions.table.nel); in common_write()
3012 rc = hashtab_map(&comdatum->permissions.table, perm_write, fp); in common_write()
3024 if (ebitmap_write(&t->types, fp)) in type_set_write()
3025 return -EINVAL; in type_set_write()
3026 if (ebitmap_write(&t->negset, fp)) in type_set_write()
3027 return -EINVAL; in type_set_write()
3029 buf[0] = cpu_to_le32(t->flags); in type_set_write()
3032 return -EINVAL; in type_set_write()
3046 for (c = node; c; c = c->next) { in write_cons_helper()
3048 for (e = c->expr; e; e = e->next) in write_cons_helper()
3050 buf[0] = cpu_to_le32(c->permissions); in write_cons_helper()
3055 for (e = c->expr; e; e = e->next) { in write_cons_helper()
3056 buf[0] = cpu_to_le32(e->expr_type); in write_cons_helper()
3057 buf[1] = cpu_to_le32(e->attr); in write_cons_helper()
3058 buf[2] = cpu_to_le32(e->op); in write_cons_helper()
3063 switch (e->expr_type) { in write_cons_helper()
3065 rc = ebitmap_write(&e->names, fp); in write_cons_helper()
3068 if (p->policyvers >= in write_cons_helper()
3070 rc = type_set_write(e->type_names, fp); in write_cons_helper()
3089 void *fp = pd->fp; in class_write()
3090 struct policydb *p = pd->p; in class_write()
3098 if (cladatum->comkey) in class_write()
3099 len2 = strlen(cladatum->comkey); in class_write()
3104 for (c = cladatum->constraints; c; c = c->next) in class_write()
3109 buf[2] = cpu_to_le32(cladatum->value); in class_write()
3110 buf[3] = cpu_to_le32(cladatum->permissions.nprim); in class_write()
3111 buf[4] = cpu_to_le32(cladatum->permissions.table.nel); in class_write()
3121 if (cladatum->comkey) { in class_write()
3122 rc = put_entry(cladatum->comkey, 1, len2, fp); in class_write()
3127 rc = hashtab_map(&cladatum->permissions.table, perm_write, fp); in class_write()
3131 rc = write_cons_helper(p, cladatum->constraints, fp); in class_write()
3137 for (c = cladatum->validatetrans; c; c = c->next) in class_write()
3145 rc = write_cons_helper(p, cladatum->validatetrans, fp); in class_write()
3149 if (p->policyvers >= POLICYDB_VERSION_NEW_OBJECT_DEFAULTS) { in class_write()
3150 buf[0] = cpu_to_le32(cladatum->default_user); in class_write()
3151 buf[1] = cpu_to_le32(cladatum->default_role); in class_write()
3152 buf[2] = cpu_to_le32(cladatum->default_range); in class_write()
3159 if (p->policyvers >= POLICYDB_VERSION_DEFAULT_TYPE) { in class_write()
3160 buf[0] = cpu_to_le32(cladatum->default_type); in class_write()
3174 void *fp = pd->fp; in role_write()
3175 struct policydb *p = pd->p; in role_write()
3183 buf[items++] = cpu_to_le32(role->value); in role_write()
3184 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) in role_write()
3185 buf[items++] = cpu_to_le32(role->bounds); in role_write()
3197 rc = ebitmap_write(&role->dominates, fp); in role_write()
3201 rc = ebitmap_write(&role->types, fp); in role_write()
3213 struct policydb *p = pd->p; in type_write()
3214 void *fp = pd->fp; in type_write()
3222 buf[items++] = cpu_to_le32(typdatum->value); in type_write()
3223 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) { in type_write()
3226 if (typdatum->primary) in type_write()
3229 if (typdatum->attribute) in type_write()
3233 buf[items++] = cpu_to_le32(typdatum->bounds); in type_write()
3235 buf[items++] = cpu_to_le32(typdatum->primary); in type_write()
3254 struct policydb *p = pd->p; in user_write()
3255 void *fp = pd->fp; in user_write()
3263 buf[items++] = cpu_to_le32(usrdatum->value); in user_write()
3264 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) in user_write()
3265 buf[items++] = cpu_to_le32(usrdatum->bounds); in user_write()
3275 rc = ebitmap_write(&usrdatum->roles, fp); in user_write()
3279 rc = mls_write_range_helper(&usrdatum->range, fp); in user_write()
3283 rc = mls_write_level(&usrdatum->dfltlevel, fp); in user_write()
3290 /* clang-format off */
3301 /* clang-format on */
3313 for (i = 0; i < info->ocon_num; i++) { in ocontext_write()
3315 for (c = p->ocontexts[i]; c; c = c->next) in ocontext_write()
3321 for (c = p->ocontexts[i]; c; c = c->next) { in ocontext_write()
3324 buf[0] = cpu_to_le32(c->sid[0]); in ocontext_write()
3328 rc = context_write(p, &c->context[0], fp); in ocontext_write()
3334 len = strlen(c->u.name); in ocontext_write()
3339 rc = put_entry(c->u.name, 1, len, fp); in ocontext_write()
3342 rc = context_write(p, &c->context[0], fp); in ocontext_write()
3345 rc = context_write(p, &c->context[1], fp); in ocontext_write()
3350 buf[0] = cpu_to_le32(c->u.port.protocol); in ocontext_write()
3351 buf[1] = cpu_to_le32(c->u.port.low_port); in ocontext_write()
3352 buf[2] = cpu_to_le32(c->u.port.high_port); in ocontext_write()
3356 rc = context_write(p, &c->context[0], fp); in ocontext_write()
3361 nodebuf[0] = c->u.node.addr; /* network order */ in ocontext_write()
3362 nodebuf[1] = c->u.node.mask; /* network order */ in ocontext_write()
3366 rc = context_write(p, &c->context[0], fp); in ocontext_write()
3371 buf[0] = cpu_to_le32(c->v.behavior); in ocontext_write()
3372 len = strlen(c->u.name); in ocontext_write()
3377 rc = put_entry(c->u.name, 1, len, fp); in ocontext_write()
3380 rc = context_write(p, &c->context[0], fp); in ocontext_write()
3387 c->u.node6.addr in ocontext_write()
3391 c->u.node6.mask in ocontext_write()
3396 rc = context_write(p, &c->context[0], fp); in ocontext_write()
3403 cpu_to_be64(c->u.ibpkey.subnet_prefix); in ocontext_write()
3409 buf[0] = cpu_to_le32(c->u.ibpkey.low_pkey); in ocontext_write()
3410 buf[1] = cpu_to_le32(c->u.ibpkey.high_pkey); in ocontext_write()
3415 rc = context_write(p, &c->context[0], fp); in ocontext_write()
3420 len = strlen(c->u.ibendport.dev_name); in ocontext_write()
3422 buf[1] = cpu_to_le32(c->u.ibendport.port); in ocontext_write()
3426 rc = put_entry(c->u.ibendport.dev_name, 1, len, in ocontext_write()
3430 rc = context_write(p, &c->context[0], fp); in ocontext_write()
3449 for (genfs = p->genfs; genfs; genfs = genfs->next) in genfs_write()
3455 for (genfs = p->genfs; genfs; genfs = genfs->next) { in genfs_write()
3456 len = strlen(genfs->fstype); in genfs_write()
3461 rc = put_entry(genfs->fstype, 1, len, fp); in genfs_write()
3465 for (c = genfs->head; c; c = c->next) in genfs_write()
3471 for (c = genfs->head; c; c = c->next) { in genfs_write()
3472 len = strlen(c->u.name); in genfs_write()
3477 rc = put_entry(c->u.name, 1, len, fp); in genfs_write()
3480 buf[0] = cpu_to_le32(c->v.sclass); in genfs_write()
3484 rc = context_write(p, &c->context[0], fp); in genfs_write()
3498 void *fp = pd->fp; in range_write_helper()
3499 struct policydb *p = pd->p; in range_write_helper()
3502 buf[0] = cpu_to_le32(rt->source_type); in range_write_helper()
3503 buf[1] = cpu_to_le32(rt->target_type); in range_write_helper()
3507 if (p->policyvers >= POLICYDB_VERSION_RANGETRANS) { in range_write_helper()
3508 buf[0] = cpu_to_le32(rt->target_class); in range_write_helper()
3529 buf[0] = cpu_to_le32(p->range_tr.nel); in range_write()
3535 rc = hashtab_map(&p->range_tr, range_write_helper, &pd); in range_write()
3550 u32 bit, len = strlen(ft->name); in filename_write_helper_compat()
3553 ebitmap_for_each_positive_bit(&datum->stypes, node, bit) in filename_write_helper_compat()
3560 rc = put_entry(ft->name, sizeof(char), len, fp); in filename_write_helper_compat()
3565 buf[1] = cpu_to_le32(ft->ttype); in filename_write_helper_compat()
3566 buf[2] = cpu_to_le32(ft->tclass); in filename_write_helper_compat()
3567 buf[3] = cpu_to_le32(datum->otype); in filename_write_helper_compat()
3574 datum = datum->next; in filename_write_helper_compat()
3587 u32 ndatum, len = strlen(ft->name); in filename_write_helper()
3594 rc = put_entry(ft->name, sizeof(char), len, fp); in filename_write_helper()
3602 datum = datum->next; in filename_write_helper()
3605 buf[0] = cpu_to_le32(ft->ttype); in filename_write_helper()
3606 buf[1] = cpu_to_le32(ft->tclass); in filename_write_helper()
3614 rc = ebitmap_write(&datum->stypes, fp); in filename_write_helper()
3618 buf[0] = cpu_to_le32(datum->otype); in filename_write_helper()
3623 datum = datum->next; in filename_write_helper()
3634 if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS) in filename_trans_write()
3637 if (p->policyvers < POLICYDB_VERSION_COMP_FTRANS) { in filename_trans_write()
3638 buf[0] = cpu_to_le32(p->compat_filename_trans_count); in filename_trans_write()
3643 rc = hashtab_map(&p->filename_trans, in filename_trans_write()
3646 buf[0] = cpu_to_le32(p->filename_trans.nel); in filename_trans_write()
3651 rc = hashtab_map(&p->filename_trans, filename_write_helper, fp); in filename_trans_write()
3676 if (p->policyvers < POLICYDB_VERSION_AVTAB) { in policydb_write()
3679 p->policyvers, POLICYDB_VERSION_AVTAB); in policydb_write()
3680 return -EINVAL; in policydb_write()
3684 if (p->mls_enabled) in policydb_write()
3687 if (p->reject_unknown) in policydb_write()
3689 if (p->allow_unknown) in policydb_write()
3704 info = policydb_lookup_compat(p->policyvers); in policydb_write()
3708 p->policyvers); in policydb_write()
3709 return -EINVAL; in policydb_write()
3712 buf[0] = cpu_to_le32(p->policyvers); in policydb_write()
3714 buf[2] = cpu_to_le32(info->sym_num); in policydb_write()
3715 buf[3] = cpu_to_le32(info->ocon_num); in policydb_write()
3721 if (p->policyvers >= POLICYDB_VERSION_POLCAP) { in policydb_write()
3722 rc = ebitmap_write(&p->policycaps, fp); in policydb_write()
3727 if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE) { in policydb_write()
3728 rc = ebitmap_write(&p->permissive_map, fp); in policydb_write()
3733 num_syms = info->sym_num; in policydb_write()
3740 buf[0] = cpu_to_le32(p->symtab[i].nprim); in policydb_write()
3741 buf[1] = cpu_to_le32(p->symtab[i].table.nel); in policydb_write()
3746 rc = hashtab_map(&p->symtab[i].table, write_f[i], &pd); in policydb_write()
3751 rc = avtab_write(p, &p->te_avtab, fp); in policydb_write()
3763 rc = role_allow_write(p->role_allow, fp); in policydb_write()
3783 for (i = 0; i < p->p_types.nprim; i++) { in policydb_write()
3784 struct ebitmap *e = &p->type_attr_map_array[i]; in policydb_write()