2 * Implementation of the policy database.
4 * Author : Stephen Smalley, <sds@tycho.nsa.gov>
8 * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
10 * Support for enhanced MLS infrastructure.
12 * Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com>
14 * Added conditional policy language extensions
16 * Updated: Hewlett-Packard <paul@paul-moore.com>
18 * Added support for the policy capability bitmap
20 * Update: Mellanox Techonologies
22 * Added Infiniband support
24 * Copyright (C) 2016 Mellanox Techonologies
25 * Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
26 * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
27 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, version 2.
33 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/slab.h>
36 #include <linux/string.h>
37 #include <linux/errno.h>
38 #include <linux/audit.h>
39 #include <linux/flex_array.h>
43 #include "conditional.h"
50 static const char *symtab_name[SYM_NUM] = {
62 static unsigned int symtab_sizes[SYM_NUM] = {
73 struct policydb_compat_info {
79 /* These need to be updated if SYM_NUM or OCON_NUM changes */
80 static struct policydb_compat_info policydb_compat[] = {
82 .version = POLICYDB_VERSION_BASE,
83 .sym_num = SYM_NUM - 3,
84 .ocon_num = OCON_NUM - 3,
87 .version = POLICYDB_VERSION_BOOL,
88 .sym_num = SYM_NUM - 2,
89 .ocon_num = OCON_NUM - 3,
92 .version = POLICYDB_VERSION_IPV6,
93 .sym_num = SYM_NUM - 2,
94 .ocon_num = OCON_NUM - 2,
97 .version = POLICYDB_VERSION_NLCLASS,
98 .sym_num = SYM_NUM - 2,
99 .ocon_num = OCON_NUM - 2,
102 .version = POLICYDB_VERSION_MLS,
104 .ocon_num = OCON_NUM - 2,
107 .version = POLICYDB_VERSION_AVTAB,
109 .ocon_num = OCON_NUM - 2,
112 .version = POLICYDB_VERSION_RANGETRANS,
114 .ocon_num = OCON_NUM - 2,
117 .version = POLICYDB_VERSION_POLCAP,
119 .ocon_num = OCON_NUM - 2,
122 .version = POLICYDB_VERSION_PERMISSIVE,
124 .ocon_num = OCON_NUM - 2,
127 .version = POLICYDB_VERSION_BOUNDARY,
129 .ocon_num = OCON_NUM - 2,
132 .version = POLICYDB_VERSION_FILENAME_TRANS,
134 .ocon_num = OCON_NUM - 2,
137 .version = POLICYDB_VERSION_ROLETRANS,
139 .ocon_num = OCON_NUM - 2,
142 .version = POLICYDB_VERSION_NEW_OBJECT_DEFAULTS,
144 .ocon_num = OCON_NUM - 2,
147 .version = POLICYDB_VERSION_DEFAULT_TYPE,
149 .ocon_num = OCON_NUM - 2,
152 .version = POLICYDB_VERSION_CONSTRAINT_NAMES,
154 .ocon_num = OCON_NUM - 2,
157 .version = POLICYDB_VERSION_XPERMS_IOCTL,
159 .ocon_num = OCON_NUM - 2,
162 .version = POLICYDB_VERSION_INFINIBAND,
164 .ocon_num = OCON_NUM,
168 static struct policydb_compat_info *policydb_lookup_compat(int version)
171 struct policydb_compat_info *info = NULL;
173 for (i = 0; i < ARRAY_SIZE(policydb_compat); i++) {
174 if (policydb_compat[i].version == version) {
175 info = &policydb_compat[i];
183 * Initialize the role table.
185 static int roles_init(struct policydb *p)
189 struct role_datum *role;
191 role = kzalloc(sizeof(*role), GFP_KERNEL);
196 role->value = ++p->p_roles.nprim;
197 if (role->value != OBJECT_R_VAL)
201 key = kstrdup(OBJECT_R, GFP_KERNEL);
205 rc = hashtab_insert(p->p_roles.table, key, role);
216 static u32 filenametr_hash(struct hashtab *h, const void *k)
218 const struct filename_trans *ft = k;
220 unsigned int byte_num;
223 hash = ft->stype ^ ft->ttype ^ ft->tclass;
226 while ((focus = ft->name[byte_num++]))
227 hash = partial_name_hash(focus, hash);
228 return hash & (h->size - 1);
231 static int filenametr_cmp(struct hashtab *h, const void *k1, const void *k2)
233 const struct filename_trans *ft1 = k1;
234 const struct filename_trans *ft2 = k2;
237 v = ft1->stype - ft2->stype;
241 v = ft1->ttype - ft2->ttype;
245 v = ft1->tclass - ft2->tclass;
249 return strcmp(ft1->name, ft2->name);
253 static u32 rangetr_hash(struct hashtab *h, const void *k)
255 const struct range_trans *key = k;
256 return (key->source_type + (key->target_type << 3) +
257 (key->target_class << 5)) & (h->size - 1);
260 static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)
262 const struct range_trans *key1 = k1, *key2 = k2;
265 v = key1->source_type - key2->source_type;
269 v = key1->target_type - key2->target_type;
273 v = key1->target_class - key2->target_class;
278 static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap);
281 * Initialize a policy database structure.
283 static int policydb_init(struct policydb *p)
287 memset(p, 0, sizeof(*p));
289 for (i = 0; i < SYM_NUM; i++) {
290 rc = symtab_init(&p->symtab[i], symtab_sizes[i]);
295 rc = avtab_init(&p->te_avtab);
303 rc = cond_policydb_init(p);
307 p->filename_trans = hashtab_create(filenametr_hash, filenametr_cmp, (1 << 10));
308 if (!p->filename_trans) {
313 p->range_tr = hashtab_create(rangetr_hash, rangetr_cmp, 256);
319 ebitmap_init(&p->filename_trans_ttypes);
320 ebitmap_init(&p->policycaps);
321 ebitmap_init(&p->permissive_map);
325 hashtab_destroy(p->filename_trans);
326 hashtab_destroy(p->range_tr);
327 for (i = 0; i < SYM_NUM; i++) {
328 hashtab_map(p->symtab[i].table, destroy_f[i], NULL);
329 hashtab_destroy(p->symtab[i].table);
335 * The following *_index functions are used to
336 * define the val_to_name and val_to_struct arrays
337 * in a policy database structure. The val_to_name
338 * arrays are used when converting security context
339 * structures into string representations. The
340 * val_to_struct arrays are used when the attributes
341 * of a class, role, or user are needed.
344 static int common_index(void *key, void *datum, void *datap)
347 struct common_datum *comdatum;
348 struct flex_array *fa;
352 if (!comdatum->value || comdatum->value > p->p_commons.nprim)
355 fa = p->sym_val_to_name[SYM_COMMONS];
356 if (flex_array_put_ptr(fa, comdatum->value - 1, key,
357 GFP_KERNEL | __GFP_ZERO))
362 static int class_index(void *key, void *datum, void *datap)
365 struct class_datum *cladatum;
366 struct flex_array *fa;
370 if (!cladatum->value || cladatum->value > p->p_classes.nprim)
372 fa = p->sym_val_to_name[SYM_CLASSES];
373 if (flex_array_put_ptr(fa, cladatum->value - 1, key,
374 GFP_KERNEL | __GFP_ZERO))
376 p->class_val_to_struct[cladatum->value - 1] = cladatum;
380 static int role_index(void *key, void *datum, void *datap)
383 struct role_datum *role;
384 struct flex_array *fa;
389 || role->value > p->p_roles.nprim
390 || role->bounds > p->p_roles.nprim)
393 fa = p->sym_val_to_name[SYM_ROLES];
394 if (flex_array_put_ptr(fa, role->value - 1, key,
395 GFP_KERNEL | __GFP_ZERO))
397 p->role_val_to_struct[role->value - 1] = role;
401 static int type_index(void *key, void *datum, void *datap)
404 struct type_datum *typdatum;
405 struct flex_array *fa;
410 if (typdatum->primary) {
412 || typdatum->value > p->p_types.nprim
413 || typdatum->bounds > p->p_types.nprim)
415 fa = p->sym_val_to_name[SYM_TYPES];
416 if (flex_array_put_ptr(fa, typdatum->value - 1, key,
417 GFP_KERNEL | __GFP_ZERO))
420 fa = p->type_val_to_struct_array;
421 if (flex_array_put_ptr(fa, typdatum->value - 1, typdatum,
422 GFP_KERNEL | __GFP_ZERO))
429 static int user_index(void *key, void *datum, void *datap)
432 struct user_datum *usrdatum;
433 struct flex_array *fa;
438 || usrdatum->value > p->p_users.nprim
439 || usrdatum->bounds > p->p_users.nprim)
442 fa = p->sym_val_to_name[SYM_USERS];
443 if (flex_array_put_ptr(fa, usrdatum->value - 1, key,
444 GFP_KERNEL | __GFP_ZERO))
446 p->user_val_to_struct[usrdatum->value - 1] = usrdatum;
450 static int sens_index(void *key, void *datum, void *datap)
453 struct level_datum *levdatum;
454 struct flex_array *fa;
459 if (!levdatum->isalias) {
460 if (!levdatum->level->sens ||
461 levdatum->level->sens > p->p_levels.nprim)
463 fa = p->sym_val_to_name[SYM_LEVELS];
464 if (flex_array_put_ptr(fa, levdatum->level->sens - 1, key,
465 GFP_KERNEL | __GFP_ZERO))
472 static int cat_index(void *key, void *datum, void *datap)
475 struct cat_datum *catdatum;
476 struct flex_array *fa;
481 if (!catdatum->isalias) {
482 if (!catdatum->value || catdatum->value > p->p_cats.nprim)
484 fa = p->sym_val_to_name[SYM_CATS];
485 if (flex_array_put_ptr(fa, catdatum->value - 1, key,
486 GFP_KERNEL | __GFP_ZERO))
493 static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) =
506 static void hash_eval(struct hashtab *h, const char *hash_name)
508 struct hashtab_info info;
510 hashtab_stat(h, &info);
511 pr_debug("SELinux: %s: %d entries and %d/%d buckets used, "
512 "longest chain length %d\n", hash_name, h->nel,
513 info.slots_used, h->size, info.max_chain_len);
516 static void symtab_hash_eval(struct symtab *s)
520 for (i = 0; i < SYM_NUM; i++)
521 hash_eval(s[i].table, symtab_name[i]);
525 static inline void hash_eval(struct hashtab *h, char *hash_name)
531 * Define the other val_to_name and val_to_struct arrays
532 * in a policy database structure.
534 * Caller must clean up on failure.
536 static int policydb_index(struct policydb *p)
541 pr_debug("SELinux: %d users, %d roles, %d types, %d bools, %d sens, %d cats\n",
542 p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim,
543 p->p_bools.nprim, p->p_levels.nprim, p->p_cats.nprim);
545 pr_debug("SELinux: %d users, %d roles, %d types, %d bools\n",
546 p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim,
549 pr_debug("SELinux: %d classes, %d rules\n",
550 p->p_classes.nprim, p->te_avtab.nel);
553 avtab_hash_eval(&p->te_avtab, "rules");
554 symtab_hash_eval(p->symtab);
557 p->class_val_to_struct = kcalloc(p->p_classes.nprim,
558 sizeof(*p->class_val_to_struct),
560 if (!p->class_val_to_struct)
563 p->role_val_to_struct = kcalloc(p->p_roles.nprim,
564 sizeof(*p->role_val_to_struct),
566 if (!p->role_val_to_struct)
569 p->user_val_to_struct = kcalloc(p->p_users.nprim,
570 sizeof(*p->user_val_to_struct),
572 if (!p->user_val_to_struct)
575 /* Yes, I want the sizeof the pointer, not the structure */
576 p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *),
578 GFP_KERNEL | __GFP_ZERO);
579 if (!p->type_val_to_struct_array)
582 rc = flex_array_prealloc(p->type_val_to_struct_array, 0,
583 p->p_types.nprim, GFP_KERNEL | __GFP_ZERO);
587 rc = cond_init_bool_indexes(p);
591 for (i = 0; i < SYM_NUM; i++) {
592 p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *),
594 GFP_KERNEL | __GFP_ZERO);
595 if (!p->sym_val_to_name[i])
598 rc = flex_array_prealloc(p->sym_val_to_name[i],
599 0, p->symtab[i].nprim,
600 GFP_KERNEL | __GFP_ZERO);
604 rc = hashtab_map(p->symtab[i].table, index_f[i], p);
614 * The following *_destroy functions are used to
615 * free any memory allocated for each kind of
616 * symbol data in the policy database.
619 static int perm_destroy(void *key, void *datum, void *p)
626 static int common_destroy(void *key, void *datum, void *p)
628 struct common_datum *comdatum;
633 hashtab_map(comdatum->permissions.table, perm_destroy, NULL);
634 hashtab_destroy(comdatum->permissions.table);
640 static void constraint_expr_destroy(struct constraint_expr *expr)
643 ebitmap_destroy(&expr->names);
644 if (expr->type_names) {
645 ebitmap_destroy(&expr->type_names->types);
646 ebitmap_destroy(&expr->type_names->negset);
647 kfree(expr->type_names);
653 static int cls_destroy(void *key, void *datum, void *p)
655 struct class_datum *cladatum;
656 struct constraint_node *constraint, *ctemp;
657 struct constraint_expr *e, *etmp;
662 hashtab_map(cladatum->permissions.table, perm_destroy, NULL);
663 hashtab_destroy(cladatum->permissions.table);
664 constraint = cladatum->constraints;
666 e = constraint->expr;
670 constraint_expr_destroy(etmp);
673 constraint = constraint->next;
677 constraint = cladatum->validatetrans;
679 e = constraint->expr;
683 constraint_expr_destroy(etmp);
686 constraint = constraint->next;
689 kfree(cladatum->comkey);
695 static int role_destroy(void *key, void *datum, void *p)
697 struct role_datum *role;
702 ebitmap_destroy(&role->dominates);
703 ebitmap_destroy(&role->types);
709 static int type_destroy(void *key, void *datum, void *p)
716 static int user_destroy(void *key, void *datum, void *p)
718 struct user_datum *usrdatum;
723 ebitmap_destroy(&usrdatum->roles);
724 ebitmap_destroy(&usrdatum->range.level[0].cat);
725 ebitmap_destroy(&usrdatum->range.level[1].cat);
726 ebitmap_destroy(&usrdatum->dfltlevel.cat);
732 static int sens_destroy(void *key, void *datum, void *p)
734 struct level_datum *levdatum;
740 ebitmap_destroy(&levdatum->level->cat);
741 kfree(levdatum->level);
747 static int cat_destroy(void *key, void *datum, void *p)
754 static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) =
766 static int filenametr_destroy(void *key, void *datum, void *p)
768 struct filename_trans *ft = key;
776 static int range_tr_destroy(void *key, void *datum, void *p)
778 struct mls_range *rt = datum;
780 ebitmap_destroy(&rt->level[0].cat);
781 ebitmap_destroy(&rt->level[1].cat);
787 static void ocontext_destroy(struct ocontext *c, int i)
792 context_destroy(&c->context[0]);
793 context_destroy(&c->context[1]);
794 if (i == OCON_ISID || i == OCON_FS ||
795 i == OCON_NETIF || i == OCON_FSUSE)
801 * Free any memory allocated by a policy database structure.
803 void policydb_destroy(struct policydb *p)
805 struct ocontext *c, *ctmp;
806 struct genfs *g, *gtmp;
808 struct role_allow *ra, *lra = NULL;
809 struct role_trans *tr, *ltr = NULL;
811 for (i = 0; i < SYM_NUM; i++) {
813 hashtab_map(p->symtab[i].table, destroy_f[i], NULL);
814 hashtab_destroy(p->symtab[i].table);
817 for (i = 0; i < SYM_NUM; i++) {
818 if (p->sym_val_to_name[i])
819 flex_array_free(p->sym_val_to_name[i]);
822 kfree(p->class_val_to_struct);
823 kfree(p->role_val_to_struct);
824 kfree(p->user_val_to_struct);
825 if (p->type_val_to_struct_array)
826 flex_array_free(p->type_val_to_struct_array);
828 avtab_destroy(&p->te_avtab);
830 for (i = 0; i < OCON_NUM; i++) {
836 ocontext_destroy(ctmp, i);
838 p->ocontexts[i] = NULL;
849 ocontext_destroy(ctmp, OCON_FSUSE);
857 cond_policydb_destroy(p);
859 for (tr = p->role_tr; tr; tr = tr->next) {
866 for (ra = p->role_allow; ra; ra = ra->next) {
873 hashtab_map(p->filename_trans, filenametr_destroy, NULL);
874 hashtab_destroy(p->filename_trans);
876 hashtab_map(p->range_tr, range_tr_destroy, NULL);
877 hashtab_destroy(p->range_tr);
879 if (p->type_attr_map_array) {
880 for (i = 0; i < p->p_types.nprim; i++) {
883 e = flex_array_get(p->type_attr_map_array, i);
888 flex_array_free(p->type_attr_map_array);
891 ebitmap_destroy(&p->filename_trans_ttypes);
892 ebitmap_destroy(&p->policycaps);
893 ebitmap_destroy(&p->permissive_map);
897 * Load the initial SIDs specified in a policy database
898 * structure into a SID table.
900 int policydb_load_isids(struct policydb *p, struct sidtab *s)
902 struct ocontext *head, *c;
907 pr_err("SELinux: out of memory on SID table init\n");
911 head = p->ocontexts[OCON_ISID];
912 for (c = head; c; c = c->next) {
914 if (!c->context[0].user) {
915 pr_err("SELinux: SID %s was never defined.\n",
920 rc = sidtab_insert(s, c->sid[0], &c->context[0]);
922 pr_err("SELinux: unable to load initial SID %s.\n",
932 int policydb_class_isvalid(struct policydb *p, unsigned int class)
934 if (!class || class > p->p_classes.nprim)
939 int policydb_role_isvalid(struct policydb *p, unsigned int role)
941 if (!role || role > p->p_roles.nprim)
946 int policydb_type_isvalid(struct policydb *p, unsigned int type)
948 if (!type || type > p->p_types.nprim)
954 * Return 1 if the fields in the security context
955 * structure `c' are valid. Return 0 otherwise.
957 int policydb_context_isvalid(struct policydb *p, struct context *c)
959 struct role_datum *role;
960 struct user_datum *usrdatum;
962 if (!c->role || c->role > p->p_roles.nprim)
965 if (!c->user || c->user > p->p_users.nprim)
968 if (!c->type || c->type > p->p_types.nprim)
971 if (c->role != OBJECT_R_VAL) {
973 * Role must be authorized for the type.
975 role = p->role_val_to_struct[c->role - 1];
976 if (!role || !ebitmap_get_bit(&role->types, c->type - 1))
977 /* role may not be associated with type */
981 * User must be authorized for the role.
983 usrdatum = p->user_val_to_struct[c->user - 1];
987 if (!ebitmap_get_bit(&usrdatum->roles, c->role - 1))
988 /* user may not be associated with role */
992 if (!mls_context_isvalid(p, c))
999 * Read a MLS range structure from a policydb binary
1000 * representation file.
1002 static int mls_read_range_helper(struct mls_range *r, void *fp)
1008 rc = next_entry(buf, fp, sizeof(u32));
1013 items = le32_to_cpu(buf[0]);
1014 if (items > ARRAY_SIZE(buf)) {
1015 pr_err("SELinux: mls: range overflow\n");
1019 rc = next_entry(buf, fp, sizeof(u32) * items);
1021 pr_err("SELinux: mls: truncated range\n");
1025 r->level[0].sens = le32_to_cpu(buf[0]);
1027 r->level[1].sens = le32_to_cpu(buf[1]);
1029 r->level[1].sens = r->level[0].sens;
1031 rc = ebitmap_read(&r->level[0].cat, fp);
1033 pr_err("SELinux: mls: error reading low categories\n");
1037 rc = ebitmap_read(&r->level[1].cat, fp);
1039 pr_err("SELinux: mls: error reading high categories\n");
1043 rc = ebitmap_cpy(&r->level[1].cat, &r->level[0].cat);
1045 pr_err("SELinux: mls: out of memory\n");
1052 ebitmap_destroy(&r->level[0].cat);
1058 * Read and validate a security context structure
1059 * from a policydb binary representation file.
1061 static int context_read_and_validate(struct context *c,
1068 rc = next_entry(buf, fp, sizeof buf);
1070 pr_err("SELinux: context truncated\n");
1073 c->user = le32_to_cpu(buf[0]);
1074 c->role = le32_to_cpu(buf[1]);
1075 c->type = le32_to_cpu(buf[2]);
1076 if (p->policyvers >= POLICYDB_VERSION_MLS) {
1077 rc = mls_read_range_helper(&c->range, fp);
1079 pr_err("SELinux: error reading MLS range of context\n");
1085 if (!policydb_context_isvalid(p, c)) {
1086 pr_err("SELinux: invalid security context\n");
1096 * The following *_read functions are used to
1097 * read the symbol data from a policy database
1098 * binary representation file.
1101 static int str_read(char **strp, gfp_t flags, void *fp, u32 len)
1106 if ((len == 0) || (len == (u32)-1))
1109 str = kmalloc(len + 1, flags | __GFP_NOWARN);
1113 /* it's expected the caller should free the str */
1116 rc = next_entry(str, fp, len);
1124 static int perm_read(struct policydb *p, struct hashtab *h, void *fp)
1127 struct perm_datum *perdatum;
1132 perdatum = kzalloc(sizeof(*perdatum), GFP_KERNEL);
1136 rc = next_entry(buf, fp, sizeof buf);
1140 len = le32_to_cpu(buf[0]);
1141 perdatum->value = le32_to_cpu(buf[1]);
1143 rc = str_read(&key, GFP_KERNEL, fp, len);
1147 rc = hashtab_insert(h, key, perdatum);
1153 perm_destroy(key, perdatum, NULL);
1157 static int common_read(struct policydb *p, struct hashtab *h, void *fp)
1160 struct common_datum *comdatum;
1165 comdatum = kzalloc(sizeof(*comdatum), GFP_KERNEL);
1169 rc = next_entry(buf, fp, sizeof buf);
1173 len = le32_to_cpu(buf[0]);
1174 comdatum->value = le32_to_cpu(buf[1]);
1176 rc = symtab_init(&comdatum->permissions, PERM_SYMTAB_SIZE);
1179 comdatum->permissions.nprim = le32_to_cpu(buf[2]);
1180 nel = le32_to_cpu(buf[3]);
1182 rc = str_read(&key, GFP_KERNEL, fp, len);
1186 for (i = 0; i < nel; i++) {
1187 rc = perm_read(p, comdatum->permissions.table, fp);
1192 rc = hashtab_insert(h, key, comdatum);
1197 common_destroy(key, comdatum, NULL);
1201 static void type_set_init(struct type_set *t)
1203 ebitmap_init(&t->types);
1204 ebitmap_init(&t->negset);
1207 static int type_set_read(struct type_set *t, void *fp)
1212 if (ebitmap_read(&t->types, fp))
1214 if (ebitmap_read(&t->negset, fp))
1217 rc = next_entry(buf, fp, sizeof(u32));
1220 t->flags = le32_to_cpu(buf[0]);
1226 static int read_cons_helper(struct policydb *p,
1227 struct constraint_node **nodep,
1228 int ncons, int allowxtarget, void *fp)
1230 struct constraint_node *c, *lc;
1231 struct constraint_expr *e, *le;
1234 int rc, i, j, depth;
1237 for (i = 0; i < ncons; i++) {
1238 c = kzalloc(sizeof(*c), GFP_KERNEL);
1247 rc = next_entry(buf, fp, (sizeof(u32) * 2));
1250 c->permissions = le32_to_cpu(buf[0]);
1251 nexpr = le32_to_cpu(buf[1]);
1254 for (j = 0; j < nexpr; j++) {
1255 e = kzalloc(sizeof(*e), GFP_KERNEL);
1264 rc = next_entry(buf, fp, (sizeof(u32) * 3));
1267 e->expr_type = le32_to_cpu(buf[0]);
1268 e->attr = le32_to_cpu(buf[1]);
1269 e->op = le32_to_cpu(buf[2]);
1271 switch (e->expr_type) {
1283 if (depth == (CEXPR_MAXDEPTH - 1))
1288 if (!allowxtarget && (e->attr & CEXPR_XTARGET))
1290 if (depth == (CEXPR_MAXDEPTH - 1))
1293 rc = ebitmap_read(&e->names, fp);
1296 if (p->policyvers >=
1297 POLICYDB_VERSION_CONSTRAINT_NAMES) {
1298 e->type_names = kzalloc(sizeof
1303 type_set_init(e->type_names);
1304 rc = type_set_read(e->type_names, fp);
1322 static int class_read(struct policydb *p, struct hashtab *h, void *fp)
1325 struct class_datum *cladatum;
1327 u32 len, len2, ncons, nel;
1330 cladatum = kzalloc(sizeof(*cladatum), GFP_KERNEL);
1334 rc = next_entry(buf, fp, sizeof(u32)*6);
1338 len = le32_to_cpu(buf[0]);
1339 len2 = le32_to_cpu(buf[1]);
1340 cladatum->value = le32_to_cpu(buf[2]);
1342 rc = symtab_init(&cladatum->permissions, PERM_SYMTAB_SIZE);
1345 cladatum->permissions.nprim = le32_to_cpu(buf[3]);
1346 nel = le32_to_cpu(buf[4]);
1348 ncons = le32_to_cpu(buf[5]);
1350 rc = str_read(&key, GFP_KERNEL, fp, len);
1355 rc = str_read(&cladatum->comkey, GFP_KERNEL, fp, len2);
1360 cladatum->comdatum = hashtab_search(p->p_commons.table, cladatum->comkey);
1361 if (!cladatum->comdatum) {
1362 pr_err("SELinux: unknown common %s\n",
1367 for (i = 0; i < nel; i++) {
1368 rc = perm_read(p, cladatum->permissions.table, fp);
1373 rc = read_cons_helper(p, &cladatum->constraints, ncons, 0, fp);
1377 if (p->policyvers >= POLICYDB_VERSION_VALIDATETRANS) {
1378 /* grab the validatetrans rules */
1379 rc = next_entry(buf, fp, sizeof(u32));
1382 ncons = le32_to_cpu(buf[0]);
1383 rc = read_cons_helper(p, &cladatum->validatetrans,
1389 if (p->policyvers >= POLICYDB_VERSION_NEW_OBJECT_DEFAULTS) {
1390 rc = next_entry(buf, fp, sizeof(u32) * 3);
1394 cladatum->default_user = le32_to_cpu(buf[0]);
1395 cladatum->default_role = le32_to_cpu(buf[1]);
1396 cladatum->default_range = le32_to_cpu(buf[2]);
1399 if (p->policyvers >= POLICYDB_VERSION_DEFAULT_TYPE) {
1400 rc = next_entry(buf, fp, sizeof(u32) * 1);
1403 cladatum->default_type = le32_to_cpu(buf[0]);
1406 rc = hashtab_insert(h, key, cladatum);
1412 cls_destroy(key, cladatum, NULL);
1416 static int role_read(struct policydb *p, struct hashtab *h, void *fp)
1419 struct role_datum *role;
1420 int rc, to_read = 2;
1424 role = kzalloc(sizeof(*role), GFP_KERNEL);
1428 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1431 rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
1435 len = le32_to_cpu(buf[0]);
1436 role->value = le32_to_cpu(buf[1]);
1437 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1438 role->bounds = le32_to_cpu(buf[2]);
1440 rc = str_read(&key, GFP_KERNEL, fp, len);
1444 rc = ebitmap_read(&role->dominates, fp);
1448 rc = ebitmap_read(&role->types, fp);
1452 if (strcmp(key, OBJECT_R) == 0) {
1454 if (role->value != OBJECT_R_VAL) {
1455 pr_err("SELinux: Role %s has wrong value %d\n",
1456 OBJECT_R, role->value);
1463 rc = hashtab_insert(h, key, role);
1468 role_destroy(key, role, NULL);
1472 static int type_read(struct policydb *p, struct hashtab *h, void *fp)
1475 struct type_datum *typdatum;
1476 int rc, to_read = 3;
1480 typdatum = kzalloc(sizeof(*typdatum), GFP_KERNEL);
1484 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1487 rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
1491 len = le32_to_cpu(buf[0]);
1492 typdatum->value = le32_to_cpu(buf[1]);
1493 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) {
1494 u32 prop = le32_to_cpu(buf[2]);
1496 if (prop & TYPEDATUM_PROPERTY_PRIMARY)
1497 typdatum->primary = 1;
1498 if (prop & TYPEDATUM_PROPERTY_ATTRIBUTE)
1499 typdatum->attribute = 1;
1501 typdatum->bounds = le32_to_cpu(buf[3]);
1503 typdatum->primary = le32_to_cpu(buf[2]);
1506 rc = str_read(&key, GFP_KERNEL, fp, len);
1510 rc = hashtab_insert(h, key, typdatum);
1515 type_destroy(key, typdatum, NULL);
1521 * Read a MLS level structure from a policydb binary
1522 * representation file.
1524 static int mls_read_level(struct mls_level *lp, void *fp)
1529 memset(lp, 0, sizeof(*lp));
1531 rc = next_entry(buf, fp, sizeof buf);
1533 pr_err("SELinux: mls: truncated level\n");
1536 lp->sens = le32_to_cpu(buf[0]);
1538 rc = ebitmap_read(&lp->cat, fp);
1540 pr_err("SELinux: mls: error reading level categories\n");
1546 static int user_read(struct policydb *p, struct hashtab *h, void *fp)
1549 struct user_datum *usrdatum;
1550 int rc, to_read = 2;
1554 usrdatum = kzalloc(sizeof(*usrdatum), GFP_KERNEL);
1558 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1561 rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
1565 len = le32_to_cpu(buf[0]);
1566 usrdatum->value = le32_to_cpu(buf[1]);
1567 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1568 usrdatum->bounds = le32_to_cpu(buf[2]);
1570 rc = str_read(&key, GFP_KERNEL, fp, len);
1574 rc = ebitmap_read(&usrdatum->roles, fp);
1578 if (p->policyvers >= POLICYDB_VERSION_MLS) {
1579 rc = mls_read_range_helper(&usrdatum->range, fp);
1582 rc = mls_read_level(&usrdatum->dfltlevel, fp);
1587 rc = hashtab_insert(h, key, usrdatum);
1592 user_destroy(key, usrdatum, NULL);
1596 static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
1599 struct level_datum *levdatum;
1604 levdatum = kzalloc(sizeof(*levdatum), GFP_ATOMIC);
1608 rc = next_entry(buf, fp, sizeof buf);
1612 len = le32_to_cpu(buf[0]);
1613 levdatum->isalias = le32_to_cpu(buf[1]);
1615 rc = str_read(&key, GFP_ATOMIC, fp, len);
1620 levdatum->level = kmalloc(sizeof(*levdatum->level), GFP_ATOMIC);
1621 if (!levdatum->level)
1624 rc = mls_read_level(levdatum->level, fp);
1628 rc = hashtab_insert(h, key, levdatum);
1633 sens_destroy(key, levdatum, NULL);
1637 static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
1640 struct cat_datum *catdatum;
1645 catdatum = kzalloc(sizeof(*catdatum), GFP_ATOMIC);
1649 rc = next_entry(buf, fp, sizeof buf);
1653 len = le32_to_cpu(buf[0]);
1654 catdatum->value = le32_to_cpu(buf[1]);
1655 catdatum->isalias = le32_to_cpu(buf[2]);
1657 rc = str_read(&key, GFP_ATOMIC, fp, len);
1661 rc = hashtab_insert(h, key, catdatum);
1666 cat_destroy(key, catdatum, NULL);
1670 static int (*read_f[SYM_NUM]) (struct policydb *p, struct hashtab *h, void *fp) =
1682 static int user_bounds_sanity_check(void *key, void *datum, void *datap)
1684 struct user_datum *upper, *user;
1685 struct policydb *p = datap;
1688 upper = user = datum;
1689 while (upper->bounds) {
1690 struct ebitmap_node *node;
1693 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
1694 pr_err("SELinux: user %s: "
1695 "too deep or looped boundary",
1700 upper = p->user_val_to_struct[upper->bounds - 1];
1701 ebitmap_for_each_positive_bit(&user->roles, node, bit) {
1702 if (ebitmap_get_bit(&upper->roles, bit))
1705 pr_err("SELinux: boundary violated policy: "
1706 "user=%s role=%s bounds=%s\n",
1707 sym_name(p, SYM_USERS, user->value - 1),
1708 sym_name(p, SYM_ROLES, bit),
1709 sym_name(p, SYM_USERS, upper->value - 1));
1718 static int role_bounds_sanity_check(void *key, void *datum, void *datap)
1720 struct role_datum *upper, *role;
1721 struct policydb *p = datap;
1724 upper = role = datum;
1725 while (upper->bounds) {
1726 struct ebitmap_node *node;
1729 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
1730 pr_err("SELinux: role %s: "
1731 "too deep or looped bounds\n",
1736 upper = p->role_val_to_struct[upper->bounds - 1];
1737 ebitmap_for_each_positive_bit(&role->types, node, bit) {
1738 if (ebitmap_get_bit(&upper->types, bit))
1741 pr_err("SELinux: boundary violated policy: "
1742 "role=%s type=%s bounds=%s\n",
1743 sym_name(p, SYM_ROLES, role->value - 1),
1744 sym_name(p, SYM_TYPES, bit),
1745 sym_name(p, SYM_ROLES, upper->value - 1));
1754 static int type_bounds_sanity_check(void *key, void *datum, void *datap)
1756 struct type_datum *upper;
1757 struct policydb *p = datap;
1761 while (upper->bounds) {
1762 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
1763 pr_err("SELinux: type %s: "
1764 "too deep or looped boundary\n",
1769 upper = flex_array_get_ptr(p->type_val_to_struct_array,
1773 if (upper->attribute) {
1774 pr_err("SELinux: type %s: "
1775 "bounded by attribute %s",
1777 sym_name(p, SYM_TYPES, upper->value - 1));
1785 static int policydb_bounds_sanity_check(struct policydb *p)
1789 if (p->policyvers < POLICYDB_VERSION_BOUNDARY)
1792 rc = hashtab_map(p->p_users.table,
1793 user_bounds_sanity_check, p);
1797 rc = hashtab_map(p->p_roles.table,
1798 role_bounds_sanity_check, p);
1802 rc = hashtab_map(p->p_types.table,
1803 type_bounds_sanity_check, p);
1810 u16 string_to_security_class(struct policydb *p, const char *name)
1812 struct class_datum *cladatum;
1814 cladatum = hashtab_search(p->p_classes.table, name);
1818 return cladatum->value;
1821 u32 string_to_av_perm(struct policydb *p, u16 tclass, const char *name)
1823 struct class_datum *cladatum;
1824 struct perm_datum *perdatum = NULL;
1825 struct common_datum *comdatum;
1827 if (!tclass || tclass > p->p_classes.nprim)
1830 cladatum = p->class_val_to_struct[tclass-1];
1831 comdatum = cladatum->comdatum;
1833 perdatum = hashtab_search(comdatum->permissions.table,
1836 perdatum = hashtab_search(cladatum->permissions.table,
1841 return 1U << (perdatum->value-1);
1844 static int range_read(struct policydb *p, void *fp)
1846 struct range_trans *rt = NULL;
1847 struct mls_range *r = NULL;
1852 if (p->policyvers < POLICYDB_VERSION_MLS)
1855 rc = next_entry(buf, fp, sizeof(u32));
1859 nel = le32_to_cpu(buf[0]);
1860 for (i = 0; i < nel; i++) {
1862 rt = kzalloc(sizeof(*rt), GFP_KERNEL);
1866 rc = next_entry(buf, fp, (sizeof(u32) * 2));
1870 rt->source_type = le32_to_cpu(buf[0]);
1871 rt->target_type = le32_to_cpu(buf[1]);
1872 if (p->policyvers >= POLICYDB_VERSION_RANGETRANS) {
1873 rc = next_entry(buf, fp, sizeof(u32));
1876 rt->target_class = le32_to_cpu(buf[0]);
1878 rt->target_class = p->process_class;
1881 if (!policydb_type_isvalid(p, rt->source_type) ||
1882 !policydb_type_isvalid(p, rt->target_type) ||
1883 !policydb_class_isvalid(p, rt->target_class))
1887 r = kzalloc(sizeof(*r), GFP_KERNEL);
1891 rc = mls_read_range_helper(r, fp);
1896 if (!mls_range_isvalid(p, r)) {
1897 pr_warn("SELinux: rangetrans: invalid range\n");
1901 rc = hashtab_insert(p->range_tr, rt, r);
1908 hash_eval(p->range_tr, "rangetr");
1916 static int filename_trans_read(struct policydb *p, void *fp)
1918 struct filename_trans *ft;
1919 struct filename_trans_datum *otype;
1925 if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
1928 rc = next_entry(buf, fp, sizeof(u32));
1931 nel = le32_to_cpu(buf[0]);
1933 for (i = 0; i < nel; i++) {
1938 ft = kzalloc(sizeof(*ft), GFP_KERNEL);
1943 otype = kmalloc(sizeof(*otype), GFP_KERNEL);
1947 /* length of the path component string */
1948 rc = next_entry(buf, fp, sizeof(u32));
1951 len = le32_to_cpu(buf[0]);
1953 /* path component string */
1954 rc = str_read(&name, GFP_KERNEL, fp, len);
1960 rc = next_entry(buf, fp, sizeof(u32) * 4);
1964 ft->stype = le32_to_cpu(buf[0]);
1965 ft->ttype = le32_to_cpu(buf[1]);
1966 ft->tclass = le32_to_cpu(buf[2]);
1968 otype->otype = le32_to_cpu(buf[3]);
1970 rc = ebitmap_set_bit(&p->filename_trans_ttypes, ft->ttype, 1);
1974 rc = hashtab_insert(p->filename_trans, ft, otype);
1977 * Do not return -EEXIST to the caller, or the system
1982 /* But free memory to avoid memory leak. */
1988 hash_eval(p->filename_trans, "filenametr");
1998 static int genfs_read(struct policydb *p, void *fp)
2001 u32 nel, nel2, len, len2;
2003 struct ocontext *l, *c;
2004 struct ocontext *newc = NULL;
2005 struct genfs *genfs_p, *genfs;
2006 struct genfs *newgenfs = NULL;
2008 rc = next_entry(buf, fp, sizeof(u32));
2011 nel = le32_to_cpu(buf[0]);
2013 for (i = 0; i < nel; i++) {
2014 rc = next_entry(buf, fp, sizeof(u32));
2017 len = le32_to_cpu(buf[0]);
2020 newgenfs = kzalloc(sizeof(*newgenfs), GFP_KERNEL);
2024 rc = str_read(&newgenfs->fstype, GFP_KERNEL, fp, len);
2028 for (genfs_p = NULL, genfs = p->genfs; genfs;
2029 genfs_p = genfs, genfs = genfs->next) {
2031 if (strcmp(newgenfs->fstype, genfs->fstype) == 0) {
2032 pr_err("SELinux: dup genfs fstype %s\n",
2036 if (strcmp(newgenfs->fstype, genfs->fstype) < 0)
2039 newgenfs->next = genfs;
2041 genfs_p->next = newgenfs;
2043 p->genfs = newgenfs;
2047 rc = next_entry(buf, fp, sizeof(u32));
2051 nel2 = le32_to_cpu(buf[0]);
2052 for (j = 0; j < nel2; j++) {
2053 rc = next_entry(buf, fp, sizeof(u32));
2056 len = le32_to_cpu(buf[0]);
2059 newc = kzalloc(sizeof(*newc), GFP_KERNEL);
2063 rc = str_read(&newc->u.name, GFP_KERNEL, fp, len);
2067 rc = next_entry(buf, fp, sizeof(u32));
2071 newc->v.sclass = le32_to_cpu(buf[0]);
2072 rc = context_read_and_validate(&newc->context[0], p, fp);
2076 for (l = NULL, c = genfs->head; c;
2077 l = c, c = c->next) {
2079 if (!strcmp(newc->u.name, c->u.name) &&
2080 (!c->v.sclass || !newc->v.sclass ||
2081 newc->v.sclass == c->v.sclass)) {
2082 pr_err("SELinux: dup genfs entry (%s,%s)\n",
2083 genfs->fstype, c->u.name);
2086 len = strlen(newc->u.name);
2087 len2 = strlen(c->u.name);
2103 kfree(newgenfs->fstype);
2106 ocontext_destroy(newc, OCON_FSUSE);
2111 static int ocontext_read(struct policydb *p, struct policydb_compat_info *info,
2116 __be64 prefixbuf[1];
2118 struct ocontext *l, *c;
2121 for (i = 0; i < info->ocon_num; i++) {
2122 rc = next_entry(buf, fp, sizeof(u32));
2125 nel = le32_to_cpu(buf[0]);
2128 for (j = 0; j < nel; j++) {
2130 c = kzalloc(sizeof(*c), GFP_KERNEL);
2136 p->ocontexts[i] = c;
2141 rc = next_entry(buf, fp, sizeof(u32));
2145 c->sid[0] = le32_to_cpu(buf[0]);
2146 rc = context_read_and_validate(&c->context[0], p, fp);
2152 rc = next_entry(buf, fp, sizeof(u32));
2155 len = le32_to_cpu(buf[0]);
2157 rc = str_read(&c->u.name, GFP_KERNEL, fp, len);
2161 rc = context_read_and_validate(&c->context[0], p, fp);
2164 rc = context_read_and_validate(&c->context[1], p, fp);
2169 rc = next_entry(buf, fp, sizeof(u32)*3);
2172 c->u.port.protocol = le32_to_cpu(buf[0]);
2173 c->u.port.low_port = le32_to_cpu(buf[1]);
2174 c->u.port.high_port = le32_to_cpu(buf[2]);
2175 rc = context_read_and_validate(&c->context[0], p, fp);
2180 rc = next_entry(nodebuf, fp, sizeof(u32) * 2);
2183 c->u.node.addr = nodebuf[0]; /* network order */
2184 c->u.node.mask = nodebuf[1]; /* network order */
2185 rc = context_read_and_validate(&c->context[0], p, fp);
2190 rc = next_entry(buf, fp, sizeof(u32)*2);
2195 c->v.behavior = le32_to_cpu(buf[0]);
2196 /* Determined at runtime, not in policy DB. */
2197 if (c->v.behavior == SECURITY_FS_USE_MNTPOINT)
2199 if (c->v.behavior > SECURITY_FS_USE_MAX)
2202 len = le32_to_cpu(buf[1]);
2203 rc = str_read(&c->u.name, GFP_KERNEL, fp, len);
2207 rc = context_read_and_validate(&c->context[0], p, fp);
2214 rc = next_entry(nodebuf, fp, sizeof(u32) * 8);
2217 for (k = 0; k < 4; k++)
2218 c->u.node6.addr[k] = nodebuf[k];
2219 for (k = 0; k < 4; k++)
2220 c->u.node6.mask[k] = nodebuf[k+4];
2221 rc = context_read_and_validate(&c->context[0], p, fp);
2227 u32 pkey_lo, pkey_hi;
2229 rc = next_entry(prefixbuf, fp, sizeof(u64));
2233 /* we need to have subnet_prefix in CPU order */
2234 c->u.ibpkey.subnet_prefix = be64_to_cpu(prefixbuf[0]);
2236 rc = next_entry(buf, fp, sizeof(u32) * 2);
2240 pkey_lo = le32_to_cpu(buf[0]);
2241 pkey_hi = le32_to_cpu(buf[1]);
2243 if (pkey_lo > U16_MAX || pkey_hi > U16_MAX) {
2248 c->u.ibpkey.low_pkey = pkey_lo;
2249 c->u.ibpkey.high_pkey = pkey_hi;
2251 rc = context_read_and_validate(&c->context[0],
2258 case OCON_IBENDPORT: {
2261 rc = next_entry(buf, fp, sizeof(u32) * 2);
2264 len = le32_to_cpu(buf[0]);
2266 rc = str_read(&c->u.ibendport.dev_name, GFP_KERNEL, fp, len);
2270 port = le32_to_cpu(buf[1]);
2271 if (port > U8_MAX || port == 0) {
2276 c->u.ibendport.port = port;
2278 rc = context_read_and_validate(&c->context[0],
2294 * Read the configuration data from a policy database binary
2295 * representation file into a policy database structure.
2297 int policydb_read(struct policydb *p, void *fp)
2299 struct role_allow *ra, *lra;
2300 struct role_trans *tr, *ltr;
2303 u32 len, nprim, nel;
2306 struct policydb_compat_info *info;
2308 rc = policydb_init(p);
2312 /* Read the magic number and string length. */
2313 rc = next_entry(buf, fp, sizeof(u32) * 2);
2318 if (le32_to_cpu(buf[0]) != POLICYDB_MAGIC) {
2319 pr_err("SELinux: policydb magic number 0x%x does "
2320 "not match expected magic number 0x%x\n",
2321 le32_to_cpu(buf[0]), POLICYDB_MAGIC);
2326 len = le32_to_cpu(buf[1]);
2327 if (len != strlen(POLICYDB_STRING)) {
2328 pr_err("SELinux: policydb string length %d does not "
2329 "match expected length %zu\n",
2330 len, strlen(POLICYDB_STRING));
2335 policydb_str = kmalloc(len + 1, GFP_KERNEL);
2336 if (!policydb_str) {
2337 pr_err("SELinux: unable to allocate memory for policydb "
2338 "string of length %d\n", len);
2342 rc = next_entry(policydb_str, fp, len);
2344 pr_err("SELinux: truncated policydb string identifier\n");
2345 kfree(policydb_str);
2350 policydb_str[len] = '\0';
2351 if (strcmp(policydb_str, POLICYDB_STRING)) {
2352 pr_err("SELinux: policydb string %s does not match "
2353 "my string %s\n", policydb_str, POLICYDB_STRING);
2354 kfree(policydb_str);
2357 /* Done with policydb_str. */
2358 kfree(policydb_str);
2359 policydb_str = NULL;
2361 /* Read the version and table sizes. */
2362 rc = next_entry(buf, fp, sizeof(u32)*4);
2367 p->policyvers = le32_to_cpu(buf[0]);
2368 if (p->policyvers < POLICYDB_VERSION_MIN ||
2369 p->policyvers > POLICYDB_VERSION_MAX) {
2370 pr_err("SELinux: policydb version %d does not match "
2371 "my version range %d-%d\n",
2372 le32_to_cpu(buf[0]), POLICYDB_VERSION_MIN, POLICYDB_VERSION_MAX);
2376 if ((le32_to_cpu(buf[1]) & POLICYDB_CONFIG_MLS)) {
2380 if (p->policyvers < POLICYDB_VERSION_MLS) {
2381 pr_err("SELinux: security policydb version %d "
2382 "(MLS) not backwards compatible\n",
2387 p->reject_unknown = !!(le32_to_cpu(buf[1]) & REJECT_UNKNOWN);
2388 p->allow_unknown = !!(le32_to_cpu(buf[1]) & ALLOW_UNKNOWN);
2390 if (p->policyvers >= POLICYDB_VERSION_POLCAP) {
2391 rc = ebitmap_read(&p->policycaps, fp);
2396 if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE) {
2397 rc = ebitmap_read(&p->permissive_map, fp);
2403 info = policydb_lookup_compat(p->policyvers);
2405 pr_err("SELinux: unable to find policy compat info "
2406 "for version %d\n", p->policyvers);
2411 if (le32_to_cpu(buf[2]) != info->sym_num ||
2412 le32_to_cpu(buf[3]) != info->ocon_num) {
2413 pr_err("SELinux: policydb table sizes (%d,%d) do "
2414 "not match mine (%d,%d)\n", le32_to_cpu(buf[2]),
2415 le32_to_cpu(buf[3]),
2416 info->sym_num, info->ocon_num);
2420 for (i = 0; i < info->sym_num; i++) {
2421 rc = next_entry(buf, fp, sizeof(u32)*2);
2424 nprim = le32_to_cpu(buf[0]);
2425 nel = le32_to_cpu(buf[1]);
2426 for (j = 0; j < nel; j++) {
2427 rc = read_f[i](p, p->symtab[i].table, fp);
2432 p->symtab[i].nprim = nprim;
2436 p->process_class = string_to_security_class(p, "process");
2437 if (!p->process_class)
2440 rc = avtab_read(&p->te_avtab, fp, p);
2444 if (p->policyvers >= POLICYDB_VERSION_BOOL) {
2445 rc = cond_read_list(p, fp);
2450 rc = next_entry(buf, fp, sizeof(u32));
2453 nel = le32_to_cpu(buf[0]);
2455 for (i = 0; i < nel; i++) {
2457 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
2464 rc = next_entry(buf, fp, sizeof(u32)*3);
2469 tr->role = le32_to_cpu(buf[0]);
2470 tr->type = le32_to_cpu(buf[1]);
2471 tr->new_role = le32_to_cpu(buf[2]);
2472 if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) {
2473 rc = next_entry(buf, fp, sizeof(u32));
2476 tr->tclass = le32_to_cpu(buf[0]);
2478 tr->tclass = p->process_class;
2481 if (!policydb_role_isvalid(p, tr->role) ||
2482 !policydb_type_isvalid(p, tr->type) ||
2483 !policydb_class_isvalid(p, tr->tclass) ||
2484 !policydb_role_isvalid(p, tr->new_role))
2489 rc = next_entry(buf, fp, sizeof(u32));
2492 nel = le32_to_cpu(buf[0]);
2494 for (i = 0; i < nel; i++) {
2496 ra = kzalloc(sizeof(*ra), GFP_KERNEL);
2503 rc = next_entry(buf, fp, sizeof(u32)*2);
2508 ra->role = le32_to_cpu(buf[0]);
2509 ra->new_role = le32_to_cpu(buf[1]);
2510 if (!policydb_role_isvalid(p, ra->role) ||
2511 !policydb_role_isvalid(p, ra->new_role))
2516 rc = filename_trans_read(p, fp);
2520 rc = policydb_index(p);
2525 p->process_trans_perms = string_to_av_perm(p, p->process_class, "transition");
2526 p->process_trans_perms |= string_to_av_perm(p, p->process_class, "dyntransition");
2527 if (!p->process_trans_perms)
2530 rc = ocontext_read(p, info, fp);
2534 rc = genfs_read(p, fp);
2538 rc = range_read(p, fp);
2543 p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap),
2545 GFP_KERNEL | __GFP_ZERO);
2546 if (!p->type_attr_map_array)
2549 /* preallocate so we don't have to worry about the put ever failing */
2550 rc = flex_array_prealloc(p->type_attr_map_array, 0, p->p_types.nprim,
2551 GFP_KERNEL | __GFP_ZERO);
2555 for (i = 0; i < p->p_types.nprim; i++) {
2556 struct ebitmap *e = flex_array_get(p->type_attr_map_array, i);
2560 if (p->policyvers >= POLICYDB_VERSION_AVTAB) {
2561 rc = ebitmap_read(e, fp);
2565 /* add the type itself as the degenerate case */
2566 rc = ebitmap_set_bit(e, i, 1);
2571 rc = policydb_bounds_sanity_check(p);
2579 policydb_destroy(p);
2584 * Write a MLS level structure to a policydb binary
2585 * representation file.
2587 static int mls_write_level(struct mls_level *l, void *fp)
2592 buf[0] = cpu_to_le32(l->sens);
2593 rc = put_entry(buf, sizeof(u32), 1, fp);
2597 rc = ebitmap_write(&l->cat, fp);
2605 * Write a MLS range structure to a policydb binary
2606 * representation file.
2608 static int mls_write_range_helper(struct mls_range *r, void *fp)
2614 eq = mls_level_eq(&r->level[1], &r->level[0]);
2620 buf[0] = cpu_to_le32(items-1);
2621 buf[1] = cpu_to_le32(r->level[0].sens);
2623 buf[2] = cpu_to_le32(r->level[1].sens);
2625 BUG_ON(items > ARRAY_SIZE(buf));
2627 rc = put_entry(buf, sizeof(u32), items, fp);
2631 rc = ebitmap_write(&r->level[0].cat, fp);
2635 rc = ebitmap_write(&r->level[1].cat, fp);
2643 static int sens_write(void *vkey, void *datum, void *ptr)
2646 struct level_datum *levdatum = datum;
2647 struct policy_data *pd = ptr;
2654 buf[0] = cpu_to_le32(len);
2655 buf[1] = cpu_to_le32(levdatum->isalias);
2656 rc = put_entry(buf, sizeof(u32), 2, fp);
2660 rc = put_entry(key, 1, len, fp);
2664 rc = mls_write_level(levdatum->level, fp);
2671 static int cat_write(void *vkey, void *datum, void *ptr)
2674 struct cat_datum *catdatum = datum;
2675 struct policy_data *pd = ptr;
2682 buf[0] = cpu_to_le32(len);
2683 buf[1] = cpu_to_le32(catdatum->value);
2684 buf[2] = cpu_to_le32(catdatum->isalias);
2685 rc = put_entry(buf, sizeof(u32), 3, fp);
2689 rc = put_entry(key, 1, len, fp);
2696 static int role_trans_write(struct policydb *p, void *fp)
2698 struct role_trans *r = p->role_tr;
2699 struct role_trans *tr;
2705 for (tr = r; tr; tr = tr->next)
2707 buf[0] = cpu_to_le32(nel);
2708 rc = put_entry(buf, sizeof(u32), 1, fp);
2711 for (tr = r; tr; tr = tr->next) {
2712 buf[0] = cpu_to_le32(tr->role);
2713 buf[1] = cpu_to_le32(tr->type);
2714 buf[2] = cpu_to_le32(tr->new_role);
2715 rc = put_entry(buf, sizeof(u32), 3, fp);
2718 if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) {
2719 buf[0] = cpu_to_le32(tr->tclass);
2720 rc = put_entry(buf, sizeof(u32), 1, fp);
2729 static int role_allow_write(struct role_allow *r, void *fp)
2731 struct role_allow *ra;
2737 for (ra = r; ra; ra = ra->next)
2739 buf[0] = cpu_to_le32(nel);
2740 rc = put_entry(buf, sizeof(u32), 1, fp);
2743 for (ra = r; ra; ra = ra->next) {
2744 buf[0] = cpu_to_le32(ra->role);
2745 buf[1] = cpu_to_le32(ra->new_role);
2746 rc = put_entry(buf, sizeof(u32), 2, fp);
2754 * Write a security context structure
2755 * to a policydb binary representation file.
2757 static int context_write(struct policydb *p, struct context *c,
2763 buf[0] = cpu_to_le32(c->user);
2764 buf[1] = cpu_to_le32(c->role);
2765 buf[2] = cpu_to_le32(c->type);
2767 rc = put_entry(buf, sizeof(u32), 3, fp);
2771 rc = mls_write_range_helper(&c->range, fp);
2779 * The following *_write functions are used to
2780 * write the symbol data to a policy database
2781 * binary representation file.
2784 static int perm_write(void *vkey, void *datum, void *fp)
2787 struct perm_datum *perdatum = datum;
2793 buf[0] = cpu_to_le32(len);
2794 buf[1] = cpu_to_le32(perdatum->value);
2795 rc = put_entry(buf, sizeof(u32), 2, fp);
2799 rc = put_entry(key, 1, len, fp);
2806 static int common_write(void *vkey, void *datum, void *ptr)
2809 struct common_datum *comdatum = datum;
2810 struct policy_data *pd = ptr;
2817 buf[0] = cpu_to_le32(len);
2818 buf[1] = cpu_to_le32(comdatum->value);
2819 buf[2] = cpu_to_le32(comdatum->permissions.nprim);
2820 buf[3] = cpu_to_le32(comdatum->permissions.table->nel);
2821 rc = put_entry(buf, sizeof(u32), 4, fp);
2825 rc = put_entry(key, 1, len, fp);
2829 rc = hashtab_map(comdatum->permissions.table, perm_write, fp);
2836 static int type_set_write(struct type_set *t, void *fp)
2841 if (ebitmap_write(&t->types, fp))
2843 if (ebitmap_write(&t->negset, fp))
2846 buf[0] = cpu_to_le32(t->flags);
2847 rc = put_entry(buf, sizeof(u32), 1, fp);
2854 static int write_cons_helper(struct policydb *p, struct constraint_node *node,
2857 struct constraint_node *c;
2858 struct constraint_expr *e;
2863 for (c = node; c; c = c->next) {
2865 for (e = c->expr; e; e = e->next)
2867 buf[0] = cpu_to_le32(c->permissions);
2868 buf[1] = cpu_to_le32(nel);
2869 rc = put_entry(buf, sizeof(u32), 2, fp);
2872 for (e = c->expr; e; e = e->next) {
2873 buf[0] = cpu_to_le32(e->expr_type);
2874 buf[1] = cpu_to_le32(e->attr);
2875 buf[2] = cpu_to_le32(e->op);
2876 rc = put_entry(buf, sizeof(u32), 3, fp);
2880 switch (e->expr_type) {
2882 rc = ebitmap_write(&e->names, fp);
2885 if (p->policyvers >=
2886 POLICYDB_VERSION_CONSTRAINT_NAMES) {
2887 rc = type_set_write(e->type_names, fp);
2901 static int class_write(void *vkey, void *datum, void *ptr)
2904 struct class_datum *cladatum = datum;
2905 struct policy_data *pd = ptr;
2907 struct policydb *p = pd->p;
2908 struct constraint_node *c;
2915 if (cladatum->comkey)
2916 len2 = strlen(cladatum->comkey);
2921 for (c = cladatum->constraints; c; c = c->next)
2924 buf[0] = cpu_to_le32(len);
2925 buf[1] = cpu_to_le32(len2);
2926 buf[2] = cpu_to_le32(cladatum->value);
2927 buf[3] = cpu_to_le32(cladatum->permissions.nprim);
2928 if (cladatum->permissions.table)
2929 buf[4] = cpu_to_le32(cladatum->permissions.table->nel);
2932 buf[5] = cpu_to_le32(ncons);
2933 rc = put_entry(buf, sizeof(u32), 6, fp);
2937 rc = put_entry(key, 1, len, fp);
2941 if (cladatum->comkey) {
2942 rc = put_entry(cladatum->comkey, 1, len2, fp);
2947 rc = hashtab_map(cladatum->permissions.table, perm_write, fp);
2951 rc = write_cons_helper(p, cladatum->constraints, fp);
2955 /* write out the validatetrans rule */
2957 for (c = cladatum->validatetrans; c; c = c->next)
2960 buf[0] = cpu_to_le32(ncons);
2961 rc = put_entry(buf, sizeof(u32), 1, fp);
2965 rc = write_cons_helper(p, cladatum->validatetrans, fp);
2969 if (p->policyvers >= POLICYDB_VERSION_NEW_OBJECT_DEFAULTS) {
2970 buf[0] = cpu_to_le32(cladatum->default_user);
2971 buf[1] = cpu_to_le32(cladatum->default_role);
2972 buf[2] = cpu_to_le32(cladatum->default_range);
2974 rc = put_entry(buf, sizeof(uint32_t), 3, fp);
2979 if (p->policyvers >= POLICYDB_VERSION_DEFAULT_TYPE) {
2980 buf[0] = cpu_to_le32(cladatum->default_type);
2981 rc = put_entry(buf, sizeof(uint32_t), 1, fp);
2989 static int role_write(void *vkey, void *datum, void *ptr)
2992 struct role_datum *role = datum;
2993 struct policy_data *pd = ptr;
2995 struct policydb *p = pd->p;
3002 buf[items++] = cpu_to_le32(len);
3003 buf[items++] = cpu_to_le32(role->value);
3004 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
3005 buf[items++] = cpu_to_le32(role->bounds);
3007 BUG_ON(items > ARRAY_SIZE(buf));
3009 rc = put_entry(buf, sizeof(u32), items, fp);
3013 rc = put_entry(key, 1, len, fp);
3017 rc = ebitmap_write(&role->dominates, fp);
3021 rc = ebitmap_write(&role->types, fp);
3028 static int type_write(void *vkey, void *datum, void *ptr)
3031 struct type_datum *typdatum = datum;
3032 struct policy_data *pd = ptr;
3033 struct policydb *p = pd->p;
3041 buf[items++] = cpu_to_le32(len);
3042 buf[items++] = cpu_to_le32(typdatum->value);
3043 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) {
3046 if (typdatum->primary)
3047 properties |= TYPEDATUM_PROPERTY_PRIMARY;
3049 if (typdatum->attribute)
3050 properties |= TYPEDATUM_PROPERTY_ATTRIBUTE;
3052 buf[items++] = cpu_to_le32(properties);
3053 buf[items++] = cpu_to_le32(typdatum->bounds);
3055 buf[items++] = cpu_to_le32(typdatum->primary);
3057 BUG_ON(items > ARRAY_SIZE(buf));
3058 rc = put_entry(buf, sizeof(u32), items, fp);
3062 rc = put_entry(key, 1, len, fp);
3069 static int user_write(void *vkey, void *datum, void *ptr)
3072 struct user_datum *usrdatum = datum;
3073 struct policy_data *pd = ptr;
3074 struct policydb *p = pd->p;
3082 buf[items++] = cpu_to_le32(len);
3083 buf[items++] = cpu_to_le32(usrdatum->value);
3084 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
3085 buf[items++] = cpu_to_le32(usrdatum->bounds);
3086 BUG_ON(items > ARRAY_SIZE(buf));
3087 rc = put_entry(buf, sizeof(u32), items, fp);
3091 rc = put_entry(key, 1, len, fp);
3095 rc = ebitmap_write(&usrdatum->roles, fp);
3099 rc = mls_write_range_helper(&usrdatum->range, fp);
3103 rc = mls_write_level(&usrdatum->dfltlevel, fp);
3110 static int (*write_f[SYM_NUM]) (void *key, void *datum,
3123 static int ocontext_write(struct policydb *p, struct policydb_compat_info *info,
3126 unsigned int i, j, rc;
3128 __be64 prefixbuf[1];
3132 for (i = 0; i < info->ocon_num; i++) {
3134 for (c = p->ocontexts[i]; c; c = c->next)
3136 buf[0] = cpu_to_le32(nel);
3137 rc = put_entry(buf, sizeof(u32), 1, fp);
3140 for (c = p->ocontexts[i]; c; c = c->next) {
3143 buf[0] = cpu_to_le32(c->sid[0]);
3144 rc = put_entry(buf, sizeof(u32), 1, fp);
3147 rc = context_write(p, &c->context[0], fp);
3153 len = strlen(c->u.name);
3154 buf[0] = cpu_to_le32(len);
3155 rc = put_entry(buf, sizeof(u32), 1, fp);
3158 rc = put_entry(c->u.name, 1, len, fp);
3161 rc = context_write(p, &c->context[0], fp);
3164 rc = context_write(p, &c->context[1], fp);
3169 buf[0] = cpu_to_le32(c->u.port.protocol);
3170 buf[1] = cpu_to_le32(c->u.port.low_port);
3171 buf[2] = cpu_to_le32(c->u.port.high_port);
3172 rc = put_entry(buf, sizeof(u32), 3, fp);
3175 rc = context_write(p, &c->context[0], fp);
3180 nodebuf[0] = c->u.node.addr; /* network order */
3181 nodebuf[1] = c->u.node.mask; /* network order */
3182 rc = put_entry(nodebuf, sizeof(u32), 2, fp);
3185 rc = context_write(p, &c->context[0], fp);
3190 buf[0] = cpu_to_le32(c->v.behavior);
3191 len = strlen(c->u.name);
3192 buf[1] = cpu_to_le32(len);
3193 rc = put_entry(buf, sizeof(u32), 2, fp);
3196 rc = put_entry(c->u.name, 1, len, fp);
3199 rc = context_write(p, &c->context[0], fp);
3204 for (j = 0; j < 4; j++)
3205 nodebuf[j] = c->u.node6.addr[j]; /* network order */
3206 for (j = 0; j < 4; j++)
3207 nodebuf[j + 4] = c->u.node6.mask[j]; /* network order */
3208 rc = put_entry(nodebuf, sizeof(u32), 8, fp);
3211 rc = context_write(p, &c->context[0], fp);
3216 /* subnet_prefix is in CPU order */
3217 prefixbuf[0] = cpu_to_be64(c->u.ibpkey.subnet_prefix);
3219 rc = put_entry(prefixbuf, sizeof(u64), 1, fp);
3223 buf[0] = cpu_to_le32(c->u.ibpkey.low_pkey);
3224 buf[1] = cpu_to_le32(c->u.ibpkey.high_pkey);
3226 rc = put_entry(buf, sizeof(u32), 2, fp);
3229 rc = context_write(p, &c->context[0], fp);
3233 case OCON_IBENDPORT:
3234 len = strlen(c->u.ibendport.dev_name);
3235 buf[0] = cpu_to_le32(len);
3236 buf[1] = cpu_to_le32(c->u.ibendport.port);
3237 rc = put_entry(buf, sizeof(u32), 2, fp);
3240 rc = put_entry(c->u.ibendport.dev_name, 1, len, fp);
3243 rc = context_write(p, &c->context[0], fp);
3253 static int genfs_write(struct policydb *p, void *fp)
3255 struct genfs *genfs;
3262 for (genfs = p->genfs; genfs; genfs = genfs->next)
3264 buf[0] = cpu_to_le32(len);
3265 rc = put_entry(buf, sizeof(u32), 1, fp);
3268 for (genfs = p->genfs; genfs; genfs = genfs->next) {
3269 len = strlen(genfs->fstype);
3270 buf[0] = cpu_to_le32(len);
3271 rc = put_entry(buf, sizeof(u32), 1, fp);
3274 rc = put_entry(genfs->fstype, 1, len, fp);
3278 for (c = genfs->head; c; c = c->next)
3280 buf[0] = cpu_to_le32(len);
3281 rc = put_entry(buf, sizeof(u32), 1, fp);
3284 for (c = genfs->head; c; c = c->next) {
3285 len = strlen(c->u.name);
3286 buf[0] = cpu_to_le32(len);
3287 rc = put_entry(buf, sizeof(u32), 1, fp);
3290 rc = put_entry(c->u.name, 1, len, fp);
3293 buf[0] = cpu_to_le32(c->v.sclass);
3294 rc = put_entry(buf, sizeof(u32), 1, fp);
3297 rc = context_write(p, &c->context[0], fp);
3305 static int hashtab_cnt(void *key, void *data, void *ptr)
3313 static int range_write_helper(void *key, void *data, void *ptr)
3316 struct range_trans *rt = key;
3317 struct mls_range *r = data;
3318 struct policy_data *pd = ptr;
3320 struct policydb *p = pd->p;
3323 buf[0] = cpu_to_le32(rt->source_type);
3324 buf[1] = cpu_to_le32(rt->target_type);
3325 rc = put_entry(buf, sizeof(u32), 2, fp);
3328 if (p->policyvers >= POLICYDB_VERSION_RANGETRANS) {
3329 buf[0] = cpu_to_le32(rt->target_class);
3330 rc = put_entry(buf, sizeof(u32), 1, fp);
3334 rc = mls_write_range_helper(r, fp);
3341 static int range_write(struct policydb *p, void *fp)
3345 struct policy_data pd;
3350 /* count the number of entries in the hashtab */
3352 rc = hashtab_map(p->range_tr, hashtab_cnt, &nel);
3356 buf[0] = cpu_to_le32(nel);
3357 rc = put_entry(buf, sizeof(u32), 1, fp);
3361 /* actually write all of the entries */
3362 rc = hashtab_map(p->range_tr, range_write_helper, &pd);
3369 static int filename_write_helper(void *key, void *data, void *ptr)
3372 struct filename_trans *ft = key;
3373 struct filename_trans_datum *otype = data;
3378 len = strlen(ft->name);
3379 buf[0] = cpu_to_le32(len);
3380 rc = put_entry(buf, sizeof(u32), 1, fp);
3384 rc = put_entry(ft->name, sizeof(char), len, fp);
3388 buf[0] = cpu_to_le32(ft->stype);
3389 buf[1] = cpu_to_le32(ft->ttype);
3390 buf[2] = cpu_to_le32(ft->tclass);
3391 buf[3] = cpu_to_le32(otype->otype);
3393 rc = put_entry(buf, sizeof(u32), 4, fp);
3400 static int filename_trans_write(struct policydb *p, void *fp)
3406 if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
3410 rc = hashtab_map(p->filename_trans, hashtab_cnt, &nel);
3414 buf[0] = cpu_to_le32(nel);
3415 rc = put_entry(buf, sizeof(u32), 1, fp);
3419 rc = hashtab_map(p->filename_trans, filename_write_helper, fp);
3427 * Write the configuration data in a policy database
3428 * structure to a policy database binary representation
3431 int policydb_write(struct policydb *p, void *fp)
3433 unsigned int i, num_syms;
3438 struct policydb_compat_info *info;
3441 * refuse to write policy older than compressed avtab
3442 * to simplify the writer. There are other tests dropped
3443 * since we assume this throughout the writer code. Be
3444 * careful if you ever try to remove this restriction
3446 if (p->policyvers < POLICYDB_VERSION_AVTAB) {
3447 pr_err("SELinux: refusing to write policy version %d."
3448 " Because it is less than version %d\n", p->policyvers,
3449 POLICYDB_VERSION_AVTAB);
3455 config |= POLICYDB_CONFIG_MLS;
3457 if (p->reject_unknown)
3458 config |= REJECT_UNKNOWN;
3459 if (p->allow_unknown)
3460 config |= ALLOW_UNKNOWN;
3462 /* Write the magic number and string identifiers. */
3463 buf[0] = cpu_to_le32(POLICYDB_MAGIC);
3464 len = strlen(POLICYDB_STRING);
3465 buf[1] = cpu_to_le32(len);
3466 rc = put_entry(buf, sizeof(u32), 2, fp);
3469 rc = put_entry(POLICYDB_STRING, 1, len, fp);
3473 /* Write the version, config, and table sizes. */
3474 info = policydb_lookup_compat(p->policyvers);
3476 pr_err("SELinux: compatibility lookup failed for policy "
3477 "version %d", p->policyvers);
3481 buf[0] = cpu_to_le32(p->policyvers);
3482 buf[1] = cpu_to_le32(config);
3483 buf[2] = cpu_to_le32(info->sym_num);
3484 buf[3] = cpu_to_le32(info->ocon_num);
3486 rc = put_entry(buf, sizeof(u32), 4, fp);
3490 if (p->policyvers >= POLICYDB_VERSION_POLCAP) {
3491 rc = ebitmap_write(&p->policycaps, fp);
3496 if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE) {
3497 rc = ebitmap_write(&p->permissive_map, fp);
3502 num_syms = info->sym_num;
3503 for (i = 0; i < num_syms; i++) {
3504 struct policy_data pd;
3509 buf[0] = cpu_to_le32(p->symtab[i].nprim);
3510 buf[1] = cpu_to_le32(p->symtab[i].table->nel);
3512 rc = put_entry(buf, sizeof(u32), 2, fp);
3515 rc = hashtab_map(p->symtab[i].table, write_f[i], &pd);
3520 rc = avtab_write(p, &p->te_avtab, fp);
3524 rc = cond_write_list(p, p->cond_list, fp);
3528 rc = role_trans_write(p, fp);
3532 rc = role_allow_write(p->role_allow, fp);
3536 rc = filename_trans_write(p, fp);
3540 rc = ocontext_write(p, info, fp);
3544 rc = genfs_write(p, fp);
3548 rc = range_write(p, fp);
3552 for (i = 0; i < p->p_types.nprim; i++) {
3553 struct ebitmap *e = flex_array_get(p->type_attr_map_array, i);
3556 rc = ebitmap_write(e, fp);