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 printk(KERN_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)
540 printk(KERN_DEBUG "SELinux: %d users, %d roles, %d types, %d bools",
541 p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, p->p_bools.nprim);
543 printk(KERN_CONT ", %d sens, %d cats", p->p_levels.nprim,
545 printk(KERN_CONT "\n");
547 printk(KERN_DEBUG "SELinux: %d classes, %d rules\n",
548 p->p_classes.nprim, p->te_avtab.nel);
551 avtab_hash_eval(&p->te_avtab, "rules");
552 symtab_hash_eval(p->symtab);
555 p->class_val_to_struct = kcalloc(p->p_classes.nprim,
556 sizeof(*p->class_val_to_struct),
558 if (!p->class_val_to_struct)
561 p->role_val_to_struct = kcalloc(p->p_roles.nprim,
562 sizeof(*p->role_val_to_struct),
564 if (!p->role_val_to_struct)
567 p->user_val_to_struct = kcalloc(p->p_users.nprim,
568 sizeof(*p->user_val_to_struct),
570 if (!p->user_val_to_struct)
573 /* Yes, I want the sizeof the pointer, not the structure */
574 p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *),
576 GFP_KERNEL | __GFP_ZERO);
577 if (!p->type_val_to_struct_array)
580 rc = flex_array_prealloc(p->type_val_to_struct_array, 0,
581 p->p_types.nprim, GFP_KERNEL | __GFP_ZERO);
585 rc = cond_init_bool_indexes(p);
589 for (i = 0; i < SYM_NUM; i++) {
590 p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *),
592 GFP_KERNEL | __GFP_ZERO);
593 if (!p->sym_val_to_name[i])
596 rc = flex_array_prealloc(p->sym_val_to_name[i],
597 0, p->symtab[i].nprim,
598 GFP_KERNEL | __GFP_ZERO);
602 rc = hashtab_map(p->symtab[i].table, index_f[i], p);
612 * The following *_destroy functions are used to
613 * free any memory allocated for each kind of
614 * symbol data in the policy database.
617 static int perm_destroy(void *key, void *datum, void *p)
624 static int common_destroy(void *key, void *datum, void *p)
626 struct common_datum *comdatum;
631 hashtab_map(comdatum->permissions.table, perm_destroy, NULL);
632 hashtab_destroy(comdatum->permissions.table);
638 static void constraint_expr_destroy(struct constraint_expr *expr)
641 ebitmap_destroy(&expr->names);
642 if (expr->type_names) {
643 ebitmap_destroy(&expr->type_names->types);
644 ebitmap_destroy(&expr->type_names->negset);
645 kfree(expr->type_names);
651 static int cls_destroy(void *key, void *datum, void *p)
653 struct class_datum *cladatum;
654 struct constraint_node *constraint, *ctemp;
655 struct constraint_expr *e, *etmp;
660 hashtab_map(cladatum->permissions.table, perm_destroy, NULL);
661 hashtab_destroy(cladatum->permissions.table);
662 constraint = cladatum->constraints;
664 e = constraint->expr;
668 constraint_expr_destroy(etmp);
671 constraint = constraint->next;
675 constraint = cladatum->validatetrans;
677 e = constraint->expr;
681 constraint_expr_destroy(etmp);
684 constraint = constraint->next;
687 kfree(cladatum->comkey);
693 static int role_destroy(void *key, void *datum, void *p)
695 struct role_datum *role;
700 ebitmap_destroy(&role->dominates);
701 ebitmap_destroy(&role->types);
707 static int type_destroy(void *key, void *datum, void *p)
714 static int user_destroy(void *key, void *datum, void *p)
716 struct user_datum *usrdatum;
721 ebitmap_destroy(&usrdatum->roles);
722 ebitmap_destroy(&usrdatum->range.level[0].cat);
723 ebitmap_destroy(&usrdatum->range.level[1].cat);
724 ebitmap_destroy(&usrdatum->dfltlevel.cat);
730 static int sens_destroy(void *key, void *datum, void *p)
732 struct level_datum *levdatum;
738 ebitmap_destroy(&levdatum->level->cat);
739 kfree(levdatum->level);
745 static int cat_destroy(void *key, void *datum, void *p)
752 static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) =
764 static int filenametr_destroy(void *key, void *datum, void *p)
766 struct filename_trans *ft = key;
774 static int range_tr_destroy(void *key, void *datum, void *p)
776 struct mls_range *rt = datum;
778 ebitmap_destroy(&rt->level[0].cat);
779 ebitmap_destroy(&rt->level[1].cat);
785 static void ocontext_destroy(struct ocontext *c, int i)
790 context_destroy(&c->context[0]);
791 context_destroy(&c->context[1]);
792 if (i == OCON_ISID || i == OCON_FS ||
793 i == OCON_NETIF || i == OCON_FSUSE)
799 * Free any memory allocated by a policy database structure.
801 void policydb_destroy(struct policydb *p)
803 struct ocontext *c, *ctmp;
804 struct genfs *g, *gtmp;
806 struct role_allow *ra, *lra = NULL;
807 struct role_trans *tr, *ltr = NULL;
809 for (i = 0; i < SYM_NUM; i++) {
811 hashtab_map(p->symtab[i].table, destroy_f[i], NULL);
812 hashtab_destroy(p->symtab[i].table);
815 for (i = 0; i < SYM_NUM; i++) {
816 if (p->sym_val_to_name[i])
817 flex_array_free(p->sym_val_to_name[i]);
820 kfree(p->class_val_to_struct);
821 kfree(p->role_val_to_struct);
822 kfree(p->user_val_to_struct);
823 if (p->type_val_to_struct_array)
824 flex_array_free(p->type_val_to_struct_array);
826 avtab_destroy(&p->te_avtab);
828 for (i = 0; i < OCON_NUM; i++) {
834 ocontext_destroy(ctmp, i);
836 p->ocontexts[i] = NULL;
847 ocontext_destroy(ctmp, OCON_FSUSE);
855 cond_policydb_destroy(p);
857 for (tr = p->role_tr; tr; tr = tr->next) {
864 for (ra = p->role_allow; ra; ra = ra->next) {
871 hashtab_map(p->filename_trans, filenametr_destroy, NULL);
872 hashtab_destroy(p->filename_trans);
874 hashtab_map(p->range_tr, range_tr_destroy, NULL);
875 hashtab_destroy(p->range_tr);
877 if (p->type_attr_map_array) {
878 for (i = 0; i < p->p_types.nprim; i++) {
881 e = flex_array_get(p->type_attr_map_array, i);
886 flex_array_free(p->type_attr_map_array);
889 ebitmap_destroy(&p->filename_trans_ttypes);
890 ebitmap_destroy(&p->policycaps);
891 ebitmap_destroy(&p->permissive_map);
895 * Load the initial SIDs specified in a policy database
896 * structure into a SID table.
898 int policydb_load_isids(struct policydb *p, struct sidtab *s)
900 struct ocontext *head, *c;
905 printk(KERN_ERR "SELinux: out of memory on SID table init\n");
909 head = p->ocontexts[OCON_ISID];
910 for (c = head; c; c = c->next) {
912 if (!c->context[0].user) {
913 printk(KERN_ERR "SELinux: SID %s was never defined.\n",
918 rc = sidtab_insert(s, c->sid[0], &c->context[0]);
920 printk(KERN_ERR "SELinux: unable to load initial SID %s.\n",
930 int policydb_class_isvalid(struct policydb *p, unsigned int class)
932 if (!class || class > p->p_classes.nprim)
937 int policydb_role_isvalid(struct policydb *p, unsigned int role)
939 if (!role || role > p->p_roles.nprim)
944 int policydb_type_isvalid(struct policydb *p, unsigned int type)
946 if (!type || type > p->p_types.nprim)
952 * Return 1 if the fields in the security context
953 * structure `c' are valid. Return 0 otherwise.
955 int policydb_context_isvalid(struct policydb *p, struct context *c)
957 struct role_datum *role;
958 struct user_datum *usrdatum;
960 if (!c->role || c->role > p->p_roles.nprim)
963 if (!c->user || c->user > p->p_users.nprim)
966 if (!c->type || c->type > p->p_types.nprim)
969 if (c->role != OBJECT_R_VAL) {
971 * Role must be authorized for the type.
973 role = p->role_val_to_struct[c->role - 1];
974 if (!role || !ebitmap_get_bit(&role->types, c->type - 1))
975 /* role may not be associated with type */
979 * User must be authorized for the role.
981 usrdatum = p->user_val_to_struct[c->user - 1];
985 if (!ebitmap_get_bit(&usrdatum->roles, c->role - 1))
986 /* user may not be associated with role */
990 if (!mls_context_isvalid(p, c))
997 * Read a MLS range structure from a policydb binary
998 * representation file.
1000 static int mls_read_range_helper(struct mls_range *r, void *fp)
1006 rc = next_entry(buf, fp, sizeof(u32));
1011 items = le32_to_cpu(buf[0]);
1012 if (items > ARRAY_SIZE(buf)) {
1013 printk(KERN_ERR "SELinux: mls: range overflow\n");
1017 rc = next_entry(buf, fp, sizeof(u32) * items);
1019 printk(KERN_ERR "SELinux: mls: truncated range\n");
1023 r->level[0].sens = le32_to_cpu(buf[0]);
1025 r->level[1].sens = le32_to_cpu(buf[1]);
1027 r->level[1].sens = r->level[0].sens;
1029 rc = ebitmap_read(&r->level[0].cat, fp);
1031 printk(KERN_ERR "SELinux: mls: error reading low categories\n");
1035 rc = ebitmap_read(&r->level[1].cat, fp);
1037 printk(KERN_ERR "SELinux: mls: error reading high categories\n");
1041 rc = ebitmap_cpy(&r->level[1].cat, &r->level[0].cat);
1043 printk(KERN_ERR "SELinux: mls: out of memory\n");
1050 ebitmap_destroy(&r->level[0].cat);
1056 * Read and validate a security context structure
1057 * from a policydb binary representation file.
1059 static int context_read_and_validate(struct context *c,
1066 rc = next_entry(buf, fp, sizeof buf);
1068 printk(KERN_ERR "SELinux: context truncated\n");
1071 c->user = le32_to_cpu(buf[0]);
1072 c->role = le32_to_cpu(buf[1]);
1073 c->type = le32_to_cpu(buf[2]);
1074 if (p->policyvers >= POLICYDB_VERSION_MLS) {
1075 rc = mls_read_range_helper(&c->range, fp);
1077 printk(KERN_ERR "SELinux: error reading MLS range of context\n");
1083 if (!policydb_context_isvalid(p, c)) {
1084 printk(KERN_ERR "SELinux: invalid security context\n");
1094 * The following *_read functions are used to
1095 * read the symbol data from a policy database
1096 * binary representation file.
1099 static int str_read(char **strp, gfp_t flags, void *fp, u32 len)
1104 if ((len == 0) || (len == (u32)-1))
1107 str = kmalloc(len + 1, flags | __GFP_NOWARN);
1111 /* it's expected the caller should free the str */
1114 rc = next_entry(str, fp, len);
1122 static int perm_read(struct policydb *p, struct hashtab *h, void *fp)
1125 struct perm_datum *perdatum;
1130 perdatum = kzalloc(sizeof(*perdatum), GFP_KERNEL);
1134 rc = next_entry(buf, fp, sizeof buf);
1138 len = le32_to_cpu(buf[0]);
1139 perdatum->value = le32_to_cpu(buf[1]);
1141 rc = str_read(&key, GFP_KERNEL, fp, len);
1145 rc = hashtab_insert(h, key, perdatum);
1151 perm_destroy(key, perdatum, NULL);
1155 static int common_read(struct policydb *p, struct hashtab *h, void *fp)
1158 struct common_datum *comdatum;
1163 comdatum = kzalloc(sizeof(*comdatum), GFP_KERNEL);
1167 rc = next_entry(buf, fp, sizeof buf);
1171 len = le32_to_cpu(buf[0]);
1172 comdatum->value = le32_to_cpu(buf[1]);
1174 rc = symtab_init(&comdatum->permissions, PERM_SYMTAB_SIZE);
1177 comdatum->permissions.nprim = le32_to_cpu(buf[2]);
1178 nel = le32_to_cpu(buf[3]);
1180 rc = str_read(&key, GFP_KERNEL, fp, len);
1184 for (i = 0; i < nel; i++) {
1185 rc = perm_read(p, comdatum->permissions.table, fp);
1190 rc = hashtab_insert(h, key, comdatum);
1195 common_destroy(key, comdatum, NULL);
1199 static void type_set_init(struct type_set *t)
1201 ebitmap_init(&t->types);
1202 ebitmap_init(&t->negset);
1205 static int type_set_read(struct type_set *t, void *fp)
1210 if (ebitmap_read(&t->types, fp))
1212 if (ebitmap_read(&t->negset, fp))
1215 rc = next_entry(buf, fp, sizeof(u32));
1218 t->flags = le32_to_cpu(buf[0]);
1224 static int read_cons_helper(struct policydb *p,
1225 struct constraint_node **nodep,
1226 int ncons, int allowxtarget, void *fp)
1228 struct constraint_node *c, *lc;
1229 struct constraint_expr *e, *le;
1232 int rc, i, j, depth;
1235 for (i = 0; i < ncons; i++) {
1236 c = kzalloc(sizeof(*c), GFP_KERNEL);
1245 rc = next_entry(buf, fp, (sizeof(u32) * 2));
1248 c->permissions = le32_to_cpu(buf[0]);
1249 nexpr = le32_to_cpu(buf[1]);
1252 for (j = 0; j < nexpr; j++) {
1253 e = kzalloc(sizeof(*e), GFP_KERNEL);
1262 rc = next_entry(buf, fp, (sizeof(u32) * 3));
1265 e->expr_type = le32_to_cpu(buf[0]);
1266 e->attr = le32_to_cpu(buf[1]);
1267 e->op = le32_to_cpu(buf[2]);
1269 switch (e->expr_type) {
1281 if (depth == (CEXPR_MAXDEPTH - 1))
1286 if (!allowxtarget && (e->attr & CEXPR_XTARGET))
1288 if (depth == (CEXPR_MAXDEPTH - 1))
1291 rc = ebitmap_read(&e->names, fp);
1294 if (p->policyvers >=
1295 POLICYDB_VERSION_CONSTRAINT_NAMES) {
1296 e->type_names = kzalloc(sizeof
1301 type_set_init(e->type_names);
1302 rc = type_set_read(e->type_names, fp);
1320 static int class_read(struct policydb *p, struct hashtab *h, void *fp)
1323 struct class_datum *cladatum;
1325 u32 len, len2, ncons, nel;
1328 cladatum = kzalloc(sizeof(*cladatum), GFP_KERNEL);
1332 rc = next_entry(buf, fp, sizeof(u32)*6);
1336 len = le32_to_cpu(buf[0]);
1337 len2 = le32_to_cpu(buf[1]);
1338 cladatum->value = le32_to_cpu(buf[2]);
1340 rc = symtab_init(&cladatum->permissions, PERM_SYMTAB_SIZE);
1343 cladatum->permissions.nprim = le32_to_cpu(buf[3]);
1344 nel = le32_to_cpu(buf[4]);
1346 ncons = le32_to_cpu(buf[5]);
1348 rc = str_read(&key, GFP_KERNEL, fp, len);
1353 rc = str_read(&cladatum->comkey, GFP_KERNEL, fp, len2);
1358 cladatum->comdatum = hashtab_search(p->p_commons.table, cladatum->comkey);
1359 if (!cladatum->comdatum) {
1360 printk(KERN_ERR "SELinux: unknown common %s\n", cladatum->comkey);
1364 for (i = 0; i < nel; i++) {
1365 rc = perm_read(p, cladatum->permissions.table, fp);
1370 rc = read_cons_helper(p, &cladatum->constraints, ncons, 0, fp);
1374 if (p->policyvers >= POLICYDB_VERSION_VALIDATETRANS) {
1375 /* grab the validatetrans rules */
1376 rc = next_entry(buf, fp, sizeof(u32));
1379 ncons = le32_to_cpu(buf[0]);
1380 rc = read_cons_helper(p, &cladatum->validatetrans,
1386 if (p->policyvers >= POLICYDB_VERSION_NEW_OBJECT_DEFAULTS) {
1387 rc = next_entry(buf, fp, sizeof(u32) * 3);
1391 cladatum->default_user = le32_to_cpu(buf[0]);
1392 cladatum->default_role = le32_to_cpu(buf[1]);
1393 cladatum->default_range = le32_to_cpu(buf[2]);
1396 if (p->policyvers >= POLICYDB_VERSION_DEFAULT_TYPE) {
1397 rc = next_entry(buf, fp, sizeof(u32) * 1);
1400 cladatum->default_type = le32_to_cpu(buf[0]);
1403 rc = hashtab_insert(h, key, cladatum);
1409 cls_destroy(key, cladatum, NULL);
1413 static int role_read(struct policydb *p, struct hashtab *h, void *fp)
1416 struct role_datum *role;
1417 int rc, to_read = 2;
1421 role = kzalloc(sizeof(*role), GFP_KERNEL);
1425 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1428 rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
1432 len = le32_to_cpu(buf[0]);
1433 role->value = le32_to_cpu(buf[1]);
1434 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1435 role->bounds = le32_to_cpu(buf[2]);
1437 rc = str_read(&key, GFP_KERNEL, fp, len);
1441 rc = ebitmap_read(&role->dominates, fp);
1445 rc = ebitmap_read(&role->types, fp);
1449 if (strcmp(key, OBJECT_R) == 0) {
1451 if (role->value != OBJECT_R_VAL) {
1452 printk(KERN_ERR "SELinux: Role %s has wrong value %d\n",
1453 OBJECT_R, role->value);
1460 rc = hashtab_insert(h, key, role);
1465 role_destroy(key, role, NULL);
1469 static int type_read(struct policydb *p, struct hashtab *h, void *fp)
1472 struct type_datum *typdatum;
1473 int rc, to_read = 3;
1477 typdatum = kzalloc(sizeof(*typdatum), GFP_KERNEL);
1481 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1484 rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
1488 len = le32_to_cpu(buf[0]);
1489 typdatum->value = le32_to_cpu(buf[1]);
1490 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) {
1491 u32 prop = le32_to_cpu(buf[2]);
1493 if (prop & TYPEDATUM_PROPERTY_PRIMARY)
1494 typdatum->primary = 1;
1495 if (prop & TYPEDATUM_PROPERTY_ATTRIBUTE)
1496 typdatum->attribute = 1;
1498 typdatum->bounds = le32_to_cpu(buf[3]);
1500 typdatum->primary = le32_to_cpu(buf[2]);
1503 rc = str_read(&key, GFP_KERNEL, fp, len);
1507 rc = hashtab_insert(h, key, typdatum);
1512 type_destroy(key, typdatum, NULL);
1518 * Read a MLS level structure from a policydb binary
1519 * representation file.
1521 static int mls_read_level(struct mls_level *lp, void *fp)
1526 memset(lp, 0, sizeof(*lp));
1528 rc = next_entry(buf, fp, sizeof buf);
1530 printk(KERN_ERR "SELinux: mls: truncated level\n");
1533 lp->sens = le32_to_cpu(buf[0]);
1535 rc = ebitmap_read(&lp->cat, fp);
1537 printk(KERN_ERR "SELinux: mls: error reading level categories\n");
1543 static int user_read(struct policydb *p, struct hashtab *h, void *fp)
1546 struct user_datum *usrdatum;
1547 int rc, to_read = 2;
1551 usrdatum = kzalloc(sizeof(*usrdatum), GFP_KERNEL);
1555 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1558 rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
1562 len = le32_to_cpu(buf[0]);
1563 usrdatum->value = le32_to_cpu(buf[1]);
1564 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
1565 usrdatum->bounds = le32_to_cpu(buf[2]);
1567 rc = str_read(&key, GFP_KERNEL, fp, len);
1571 rc = ebitmap_read(&usrdatum->roles, fp);
1575 if (p->policyvers >= POLICYDB_VERSION_MLS) {
1576 rc = mls_read_range_helper(&usrdatum->range, fp);
1579 rc = mls_read_level(&usrdatum->dfltlevel, fp);
1584 rc = hashtab_insert(h, key, usrdatum);
1589 user_destroy(key, usrdatum, NULL);
1593 static int sens_read(struct policydb *p, struct hashtab *h, void *fp)
1596 struct level_datum *levdatum;
1601 levdatum = kzalloc(sizeof(*levdatum), GFP_ATOMIC);
1605 rc = next_entry(buf, fp, sizeof buf);
1609 len = le32_to_cpu(buf[0]);
1610 levdatum->isalias = le32_to_cpu(buf[1]);
1612 rc = str_read(&key, GFP_ATOMIC, fp, len);
1617 levdatum->level = kmalloc(sizeof(*levdatum->level), GFP_ATOMIC);
1618 if (!levdatum->level)
1621 rc = mls_read_level(levdatum->level, fp);
1625 rc = hashtab_insert(h, key, levdatum);
1630 sens_destroy(key, levdatum, NULL);
1634 static int cat_read(struct policydb *p, struct hashtab *h, void *fp)
1637 struct cat_datum *catdatum;
1642 catdatum = kzalloc(sizeof(*catdatum), GFP_ATOMIC);
1646 rc = next_entry(buf, fp, sizeof buf);
1650 len = le32_to_cpu(buf[0]);
1651 catdatum->value = le32_to_cpu(buf[1]);
1652 catdatum->isalias = le32_to_cpu(buf[2]);
1654 rc = str_read(&key, GFP_ATOMIC, fp, len);
1658 rc = hashtab_insert(h, key, catdatum);
1663 cat_destroy(key, catdatum, NULL);
1667 static int (*read_f[SYM_NUM]) (struct policydb *p, struct hashtab *h, void *fp) =
1679 static int user_bounds_sanity_check(void *key, void *datum, void *datap)
1681 struct user_datum *upper, *user;
1682 struct policydb *p = datap;
1685 upper = user = datum;
1686 while (upper->bounds) {
1687 struct ebitmap_node *node;
1690 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
1691 printk(KERN_ERR "SELinux: user %s: "
1692 "too deep or looped boundary",
1697 upper = p->user_val_to_struct[upper->bounds - 1];
1698 ebitmap_for_each_positive_bit(&user->roles, node, bit) {
1699 if (ebitmap_get_bit(&upper->roles, bit))
1703 "SELinux: boundary violated policy: "
1704 "user=%s role=%s bounds=%s\n",
1705 sym_name(p, SYM_USERS, user->value - 1),
1706 sym_name(p, SYM_ROLES, bit),
1707 sym_name(p, SYM_USERS, upper->value - 1));
1716 static int role_bounds_sanity_check(void *key, void *datum, void *datap)
1718 struct role_datum *upper, *role;
1719 struct policydb *p = datap;
1722 upper = role = datum;
1723 while (upper->bounds) {
1724 struct ebitmap_node *node;
1727 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
1728 printk(KERN_ERR "SELinux: role %s: "
1729 "too deep or looped bounds\n",
1734 upper = p->role_val_to_struct[upper->bounds - 1];
1735 ebitmap_for_each_positive_bit(&role->types, node, bit) {
1736 if (ebitmap_get_bit(&upper->types, bit))
1740 "SELinux: boundary violated policy: "
1741 "role=%s type=%s bounds=%s\n",
1742 sym_name(p, SYM_ROLES, role->value - 1),
1743 sym_name(p, SYM_TYPES, bit),
1744 sym_name(p, SYM_ROLES, upper->value - 1));
1753 static int type_bounds_sanity_check(void *key, void *datum, void *datap)
1755 struct type_datum *upper;
1756 struct policydb *p = datap;
1760 while (upper->bounds) {
1761 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
1762 printk(KERN_ERR "SELinux: type %s: "
1763 "too deep or looped boundary\n",
1768 upper = flex_array_get_ptr(p->type_val_to_struct_array,
1772 if (upper->attribute) {
1773 printk(KERN_ERR "SELinux: type %s: "
1774 "bounded by attribute %s",
1776 sym_name(p, SYM_TYPES, upper->value - 1));
1784 static int policydb_bounds_sanity_check(struct policydb *p)
1788 if (p->policyvers < POLICYDB_VERSION_BOUNDARY)
1791 rc = hashtab_map(p->p_users.table,
1792 user_bounds_sanity_check, p);
1796 rc = hashtab_map(p->p_roles.table,
1797 role_bounds_sanity_check, p);
1801 rc = hashtab_map(p->p_types.table,
1802 type_bounds_sanity_check, p);
1809 u16 string_to_security_class(struct policydb *p, const char *name)
1811 struct class_datum *cladatum;
1813 cladatum = hashtab_search(p->p_classes.table, name);
1817 return cladatum->value;
1820 u32 string_to_av_perm(struct policydb *p, u16 tclass, const char *name)
1822 struct class_datum *cladatum;
1823 struct perm_datum *perdatum = NULL;
1824 struct common_datum *comdatum;
1826 if (!tclass || tclass > p->p_classes.nprim)
1829 cladatum = p->class_val_to_struct[tclass-1];
1830 comdatum = cladatum->comdatum;
1832 perdatum = hashtab_search(comdatum->permissions.table,
1835 perdatum = hashtab_search(cladatum->permissions.table,
1840 return 1U << (perdatum->value-1);
1843 static int range_read(struct policydb *p, void *fp)
1845 struct range_trans *rt = NULL;
1846 struct mls_range *r = NULL;
1851 if (p->policyvers < POLICYDB_VERSION_MLS)
1854 rc = next_entry(buf, fp, sizeof(u32));
1858 nel = le32_to_cpu(buf[0]);
1859 for (i = 0; i < nel; i++) {
1861 rt = kzalloc(sizeof(*rt), GFP_KERNEL);
1865 rc = next_entry(buf, fp, (sizeof(u32) * 2));
1869 rt->source_type = le32_to_cpu(buf[0]);
1870 rt->target_type = le32_to_cpu(buf[1]);
1871 if (p->policyvers >= POLICYDB_VERSION_RANGETRANS) {
1872 rc = next_entry(buf, fp, sizeof(u32));
1875 rt->target_class = le32_to_cpu(buf[0]);
1877 rt->target_class = p->process_class;
1880 if (!policydb_type_isvalid(p, rt->source_type) ||
1881 !policydb_type_isvalid(p, rt->target_type) ||
1882 !policydb_class_isvalid(p, rt->target_class))
1886 r = kzalloc(sizeof(*r), GFP_KERNEL);
1890 rc = mls_read_range_helper(r, fp);
1895 if (!mls_range_isvalid(p, r)) {
1896 printk(KERN_WARNING "SELinux: rangetrans: invalid range\n");
1900 rc = hashtab_insert(p->range_tr, rt, r);
1907 hash_eval(p->range_tr, "rangetr");
1915 static int filename_trans_read(struct policydb *p, void *fp)
1917 struct filename_trans *ft;
1918 struct filename_trans_datum *otype;
1924 if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
1927 rc = next_entry(buf, fp, sizeof(u32));
1930 nel = le32_to_cpu(buf[0]);
1932 for (i = 0; i < nel; i++) {
1937 ft = kzalloc(sizeof(*ft), GFP_KERNEL);
1942 otype = kmalloc(sizeof(*otype), GFP_KERNEL);
1946 /* length of the path component string */
1947 rc = next_entry(buf, fp, sizeof(u32));
1950 len = le32_to_cpu(buf[0]);
1952 /* path component string */
1953 rc = str_read(&name, GFP_KERNEL, fp, len);
1959 rc = next_entry(buf, fp, sizeof(u32) * 4);
1963 ft->stype = le32_to_cpu(buf[0]);
1964 ft->ttype = le32_to_cpu(buf[1]);
1965 ft->tclass = le32_to_cpu(buf[2]);
1967 otype->otype = le32_to_cpu(buf[3]);
1969 rc = ebitmap_set_bit(&p->filename_trans_ttypes, ft->ttype, 1);
1973 rc = hashtab_insert(p->filename_trans, ft, otype);
1976 * Do not return -EEXIST to the caller, or the system
1981 /* But free memory to avoid memory leak. */
1987 hash_eval(p->filename_trans, "filenametr");
1997 static int genfs_read(struct policydb *p, void *fp)
2000 u32 nel, nel2, len, len2;
2002 struct ocontext *l, *c;
2003 struct ocontext *newc = NULL;
2004 struct genfs *genfs_p, *genfs;
2005 struct genfs *newgenfs = NULL;
2007 rc = next_entry(buf, fp, sizeof(u32));
2010 nel = le32_to_cpu(buf[0]);
2012 for (i = 0; i < nel; i++) {
2013 rc = next_entry(buf, fp, sizeof(u32));
2016 len = le32_to_cpu(buf[0]);
2019 newgenfs = kzalloc(sizeof(*newgenfs), GFP_KERNEL);
2023 rc = str_read(&newgenfs->fstype, GFP_KERNEL, fp, len);
2027 for (genfs_p = NULL, genfs = p->genfs; genfs;
2028 genfs_p = genfs, genfs = genfs->next) {
2030 if (strcmp(newgenfs->fstype, genfs->fstype) == 0) {
2031 printk(KERN_ERR "SELinux: dup genfs fstype %s\n",
2035 if (strcmp(newgenfs->fstype, genfs->fstype) < 0)
2038 newgenfs->next = genfs;
2040 genfs_p->next = newgenfs;
2042 p->genfs = newgenfs;
2046 rc = next_entry(buf, fp, sizeof(u32));
2050 nel2 = le32_to_cpu(buf[0]);
2051 for (j = 0; j < nel2; j++) {
2052 rc = next_entry(buf, fp, sizeof(u32));
2055 len = le32_to_cpu(buf[0]);
2058 newc = kzalloc(sizeof(*newc), GFP_KERNEL);
2062 rc = str_read(&newc->u.name, GFP_KERNEL, fp, len);
2066 rc = next_entry(buf, fp, sizeof(u32));
2070 newc->v.sclass = le32_to_cpu(buf[0]);
2071 rc = context_read_and_validate(&newc->context[0], p, fp);
2075 for (l = NULL, c = genfs->head; c;
2076 l = c, c = c->next) {
2078 if (!strcmp(newc->u.name, c->u.name) &&
2079 (!c->v.sclass || !newc->v.sclass ||
2080 newc->v.sclass == c->v.sclass)) {
2081 printk(KERN_ERR "SELinux: dup genfs entry (%s,%s)\n",
2082 genfs->fstype, c->u.name);
2085 len = strlen(newc->u.name);
2086 len2 = strlen(c->u.name);
2102 kfree(newgenfs->fstype);
2105 ocontext_destroy(newc, OCON_FSUSE);
2110 static int ocontext_read(struct policydb *p, struct policydb_compat_info *info,
2115 __be64 prefixbuf[1];
2117 struct ocontext *l, *c;
2120 for (i = 0; i < info->ocon_num; i++) {
2121 rc = next_entry(buf, fp, sizeof(u32));
2124 nel = le32_to_cpu(buf[0]);
2127 for (j = 0; j < nel; j++) {
2129 c = kzalloc(sizeof(*c), GFP_KERNEL);
2135 p->ocontexts[i] = c;
2140 rc = next_entry(buf, fp, sizeof(u32));
2144 c->sid[0] = le32_to_cpu(buf[0]);
2145 rc = context_read_and_validate(&c->context[0], p, fp);
2151 rc = next_entry(buf, fp, sizeof(u32));
2154 len = le32_to_cpu(buf[0]);
2156 rc = str_read(&c->u.name, GFP_KERNEL, fp, len);
2160 rc = context_read_and_validate(&c->context[0], p, fp);
2163 rc = context_read_and_validate(&c->context[1], p, fp);
2168 rc = next_entry(buf, fp, sizeof(u32)*3);
2171 c->u.port.protocol = le32_to_cpu(buf[0]);
2172 c->u.port.low_port = le32_to_cpu(buf[1]);
2173 c->u.port.high_port = le32_to_cpu(buf[2]);
2174 rc = context_read_and_validate(&c->context[0], p, fp);
2179 rc = next_entry(nodebuf, fp, sizeof(u32) * 2);
2182 c->u.node.addr = nodebuf[0]; /* network order */
2183 c->u.node.mask = nodebuf[1]; /* network order */
2184 rc = context_read_and_validate(&c->context[0], p, fp);
2189 rc = next_entry(buf, fp, sizeof(u32)*2);
2194 c->v.behavior = le32_to_cpu(buf[0]);
2195 /* Determined at runtime, not in policy DB. */
2196 if (c->v.behavior == SECURITY_FS_USE_MNTPOINT)
2198 if (c->v.behavior > SECURITY_FS_USE_MAX)
2201 len = le32_to_cpu(buf[1]);
2202 rc = str_read(&c->u.name, GFP_KERNEL, fp, len);
2206 rc = context_read_and_validate(&c->context[0], p, fp);
2213 rc = next_entry(nodebuf, fp, sizeof(u32) * 8);
2216 for (k = 0; k < 4; k++)
2217 c->u.node6.addr[k] = nodebuf[k];
2218 for (k = 0; k < 4; k++)
2219 c->u.node6.mask[k] = nodebuf[k+4];
2220 rc = context_read_and_validate(&c->context[0], p, fp);
2226 u32 pkey_lo, pkey_hi;
2228 rc = next_entry(prefixbuf, fp, sizeof(u64));
2232 /* we need to have subnet_prefix in CPU order */
2233 c->u.ibpkey.subnet_prefix = be64_to_cpu(prefixbuf[0]);
2235 rc = next_entry(buf, fp, sizeof(u32) * 2);
2239 pkey_lo = le32_to_cpu(buf[0]);
2240 pkey_hi = le32_to_cpu(buf[1]);
2242 if (pkey_lo > U16_MAX || pkey_hi > U16_MAX) {
2247 c->u.ibpkey.low_pkey = pkey_lo;
2248 c->u.ibpkey.high_pkey = pkey_hi;
2250 rc = context_read_and_validate(&c->context[0],
2257 case OCON_IBENDPORT: {
2260 rc = next_entry(buf, fp, sizeof(u32) * 2);
2263 len = le32_to_cpu(buf[0]);
2265 rc = str_read(&c->u.ibendport.dev_name, GFP_KERNEL, fp, len);
2269 port = le32_to_cpu(buf[1]);
2270 if (port > U8_MAX || port == 0) {
2275 c->u.ibendport.port = port;
2277 rc = context_read_and_validate(&c->context[0],
2293 * Read the configuration data from a policy database binary
2294 * representation file into a policy database structure.
2296 int policydb_read(struct policydb *p, void *fp)
2298 struct role_allow *ra, *lra;
2299 struct role_trans *tr, *ltr;
2302 u32 len, nprim, nel;
2305 struct policydb_compat_info *info;
2307 rc = policydb_init(p);
2311 /* Read the magic number and string length. */
2312 rc = next_entry(buf, fp, sizeof(u32) * 2);
2317 if (le32_to_cpu(buf[0]) != POLICYDB_MAGIC) {
2318 printk(KERN_ERR "SELinux: policydb magic number 0x%x does "
2319 "not match expected magic number 0x%x\n",
2320 le32_to_cpu(buf[0]), POLICYDB_MAGIC);
2325 len = le32_to_cpu(buf[1]);
2326 if (len != strlen(POLICYDB_STRING)) {
2327 printk(KERN_ERR "SELinux: policydb string length %d does not "
2328 "match expected length %zu\n",
2329 len, strlen(POLICYDB_STRING));
2334 policydb_str = kmalloc(len + 1, GFP_KERNEL);
2335 if (!policydb_str) {
2336 printk(KERN_ERR "SELinux: unable to allocate memory for policydb "
2337 "string of length %d\n", len);
2341 rc = next_entry(policydb_str, fp, len);
2343 printk(KERN_ERR "SELinux: truncated policydb string identifier\n");
2344 kfree(policydb_str);
2349 policydb_str[len] = '\0';
2350 if (strcmp(policydb_str, POLICYDB_STRING)) {
2351 printk(KERN_ERR "SELinux: policydb string %s does not match "
2352 "my string %s\n", policydb_str, POLICYDB_STRING);
2353 kfree(policydb_str);
2356 /* Done with policydb_str. */
2357 kfree(policydb_str);
2358 policydb_str = NULL;
2360 /* Read the version and table sizes. */
2361 rc = next_entry(buf, fp, sizeof(u32)*4);
2366 p->policyvers = le32_to_cpu(buf[0]);
2367 if (p->policyvers < POLICYDB_VERSION_MIN ||
2368 p->policyvers > POLICYDB_VERSION_MAX) {
2369 printk(KERN_ERR "SELinux: policydb version %d does not match "
2370 "my version range %d-%d\n",
2371 le32_to_cpu(buf[0]), POLICYDB_VERSION_MIN, POLICYDB_VERSION_MAX);
2375 if ((le32_to_cpu(buf[1]) & POLICYDB_CONFIG_MLS)) {
2379 if (p->policyvers < POLICYDB_VERSION_MLS) {
2380 printk(KERN_ERR "SELinux: security policydb version %d "
2381 "(MLS) not backwards compatible\n",
2386 p->reject_unknown = !!(le32_to_cpu(buf[1]) & REJECT_UNKNOWN);
2387 p->allow_unknown = !!(le32_to_cpu(buf[1]) & ALLOW_UNKNOWN);
2389 if (p->policyvers >= POLICYDB_VERSION_POLCAP) {
2390 rc = ebitmap_read(&p->policycaps, fp);
2395 if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE) {
2396 rc = ebitmap_read(&p->permissive_map, fp);
2402 info = policydb_lookup_compat(p->policyvers);
2404 printk(KERN_ERR "SELinux: unable to find policy compat info "
2405 "for version %d\n", p->policyvers);
2410 if (le32_to_cpu(buf[2]) != info->sym_num ||
2411 le32_to_cpu(buf[3]) != info->ocon_num) {
2412 printk(KERN_ERR "SELinux: policydb table sizes (%d,%d) do "
2413 "not match mine (%d,%d)\n", le32_to_cpu(buf[2]),
2414 le32_to_cpu(buf[3]),
2415 info->sym_num, info->ocon_num);
2419 for (i = 0; i < info->sym_num; i++) {
2420 rc = next_entry(buf, fp, sizeof(u32)*2);
2423 nprim = le32_to_cpu(buf[0]);
2424 nel = le32_to_cpu(buf[1]);
2425 for (j = 0; j < nel; j++) {
2426 rc = read_f[i](p, p->symtab[i].table, fp);
2431 p->symtab[i].nprim = nprim;
2435 p->process_class = string_to_security_class(p, "process");
2436 if (!p->process_class)
2439 rc = avtab_read(&p->te_avtab, fp, p);
2443 if (p->policyvers >= POLICYDB_VERSION_BOOL) {
2444 rc = cond_read_list(p, fp);
2449 rc = next_entry(buf, fp, sizeof(u32));
2452 nel = le32_to_cpu(buf[0]);
2454 for (i = 0; i < nel; i++) {
2456 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
2463 rc = next_entry(buf, fp, sizeof(u32)*3);
2468 tr->role = le32_to_cpu(buf[0]);
2469 tr->type = le32_to_cpu(buf[1]);
2470 tr->new_role = le32_to_cpu(buf[2]);
2471 if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) {
2472 rc = next_entry(buf, fp, sizeof(u32));
2475 tr->tclass = le32_to_cpu(buf[0]);
2477 tr->tclass = p->process_class;
2480 if (!policydb_role_isvalid(p, tr->role) ||
2481 !policydb_type_isvalid(p, tr->type) ||
2482 !policydb_class_isvalid(p, tr->tclass) ||
2483 !policydb_role_isvalid(p, tr->new_role))
2488 rc = next_entry(buf, fp, sizeof(u32));
2491 nel = le32_to_cpu(buf[0]);
2493 for (i = 0; i < nel; i++) {
2495 ra = kzalloc(sizeof(*ra), GFP_KERNEL);
2502 rc = next_entry(buf, fp, sizeof(u32)*2);
2507 ra->role = le32_to_cpu(buf[0]);
2508 ra->new_role = le32_to_cpu(buf[1]);
2509 if (!policydb_role_isvalid(p, ra->role) ||
2510 !policydb_role_isvalid(p, ra->new_role))
2515 rc = filename_trans_read(p, fp);
2519 rc = policydb_index(p);
2524 p->process_trans_perms = string_to_av_perm(p, p->process_class, "transition");
2525 p->process_trans_perms |= string_to_av_perm(p, p->process_class, "dyntransition");
2526 if (!p->process_trans_perms)
2529 rc = ocontext_read(p, info, fp);
2533 rc = genfs_read(p, fp);
2537 rc = range_read(p, fp);
2542 p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap),
2544 GFP_KERNEL | __GFP_ZERO);
2545 if (!p->type_attr_map_array)
2548 /* preallocate so we don't have to worry about the put ever failing */
2549 rc = flex_array_prealloc(p->type_attr_map_array, 0, p->p_types.nprim,
2550 GFP_KERNEL | __GFP_ZERO);
2554 for (i = 0; i < p->p_types.nprim; i++) {
2555 struct ebitmap *e = flex_array_get(p->type_attr_map_array, i);
2559 if (p->policyvers >= POLICYDB_VERSION_AVTAB) {
2560 rc = ebitmap_read(e, fp);
2564 /* add the type itself as the degenerate case */
2565 rc = ebitmap_set_bit(e, i, 1);
2570 rc = policydb_bounds_sanity_check(p);
2578 policydb_destroy(p);
2583 * Write a MLS level structure to a policydb binary
2584 * representation file.
2586 static int mls_write_level(struct mls_level *l, void *fp)
2591 buf[0] = cpu_to_le32(l->sens);
2592 rc = put_entry(buf, sizeof(u32), 1, fp);
2596 rc = ebitmap_write(&l->cat, fp);
2604 * Write a MLS range structure to a policydb binary
2605 * representation file.
2607 static int mls_write_range_helper(struct mls_range *r, void *fp)
2613 eq = mls_level_eq(&r->level[1], &r->level[0]);
2619 buf[0] = cpu_to_le32(items-1);
2620 buf[1] = cpu_to_le32(r->level[0].sens);
2622 buf[2] = cpu_to_le32(r->level[1].sens);
2624 BUG_ON(items > ARRAY_SIZE(buf));
2626 rc = put_entry(buf, sizeof(u32), items, fp);
2630 rc = ebitmap_write(&r->level[0].cat, fp);
2634 rc = ebitmap_write(&r->level[1].cat, fp);
2642 static int sens_write(void *vkey, void *datum, void *ptr)
2645 struct level_datum *levdatum = datum;
2646 struct policy_data *pd = ptr;
2653 buf[0] = cpu_to_le32(len);
2654 buf[1] = cpu_to_le32(levdatum->isalias);
2655 rc = put_entry(buf, sizeof(u32), 2, fp);
2659 rc = put_entry(key, 1, len, fp);
2663 rc = mls_write_level(levdatum->level, fp);
2670 static int cat_write(void *vkey, void *datum, void *ptr)
2673 struct cat_datum *catdatum = datum;
2674 struct policy_data *pd = ptr;
2681 buf[0] = cpu_to_le32(len);
2682 buf[1] = cpu_to_le32(catdatum->value);
2683 buf[2] = cpu_to_le32(catdatum->isalias);
2684 rc = put_entry(buf, sizeof(u32), 3, fp);
2688 rc = put_entry(key, 1, len, fp);
2695 static int role_trans_write(struct policydb *p, void *fp)
2697 struct role_trans *r = p->role_tr;
2698 struct role_trans *tr;
2704 for (tr = r; tr; tr = tr->next)
2706 buf[0] = cpu_to_le32(nel);
2707 rc = put_entry(buf, sizeof(u32), 1, fp);
2710 for (tr = r; tr; tr = tr->next) {
2711 buf[0] = cpu_to_le32(tr->role);
2712 buf[1] = cpu_to_le32(tr->type);
2713 buf[2] = cpu_to_le32(tr->new_role);
2714 rc = put_entry(buf, sizeof(u32), 3, fp);
2717 if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) {
2718 buf[0] = cpu_to_le32(tr->tclass);
2719 rc = put_entry(buf, sizeof(u32), 1, fp);
2728 static int role_allow_write(struct role_allow *r, void *fp)
2730 struct role_allow *ra;
2736 for (ra = r; ra; ra = ra->next)
2738 buf[0] = cpu_to_le32(nel);
2739 rc = put_entry(buf, sizeof(u32), 1, fp);
2742 for (ra = r; ra; ra = ra->next) {
2743 buf[0] = cpu_to_le32(ra->role);
2744 buf[1] = cpu_to_le32(ra->new_role);
2745 rc = put_entry(buf, sizeof(u32), 2, fp);
2753 * Write a security context structure
2754 * to a policydb binary representation file.
2756 static int context_write(struct policydb *p, struct context *c,
2762 buf[0] = cpu_to_le32(c->user);
2763 buf[1] = cpu_to_le32(c->role);
2764 buf[2] = cpu_to_le32(c->type);
2766 rc = put_entry(buf, sizeof(u32), 3, fp);
2770 rc = mls_write_range_helper(&c->range, fp);
2778 * The following *_write functions are used to
2779 * write the symbol data to a policy database
2780 * binary representation file.
2783 static int perm_write(void *vkey, void *datum, void *fp)
2786 struct perm_datum *perdatum = datum;
2792 buf[0] = cpu_to_le32(len);
2793 buf[1] = cpu_to_le32(perdatum->value);
2794 rc = put_entry(buf, sizeof(u32), 2, fp);
2798 rc = put_entry(key, 1, len, fp);
2805 static int common_write(void *vkey, void *datum, void *ptr)
2808 struct common_datum *comdatum = datum;
2809 struct policy_data *pd = ptr;
2816 buf[0] = cpu_to_le32(len);
2817 buf[1] = cpu_to_le32(comdatum->value);
2818 buf[2] = cpu_to_le32(comdatum->permissions.nprim);
2819 buf[3] = cpu_to_le32(comdatum->permissions.table->nel);
2820 rc = put_entry(buf, sizeof(u32), 4, fp);
2824 rc = put_entry(key, 1, len, fp);
2828 rc = hashtab_map(comdatum->permissions.table, perm_write, fp);
2835 static int type_set_write(struct type_set *t, void *fp)
2840 if (ebitmap_write(&t->types, fp))
2842 if (ebitmap_write(&t->negset, fp))
2845 buf[0] = cpu_to_le32(t->flags);
2846 rc = put_entry(buf, sizeof(u32), 1, fp);
2853 static int write_cons_helper(struct policydb *p, struct constraint_node *node,
2856 struct constraint_node *c;
2857 struct constraint_expr *e;
2862 for (c = node; c; c = c->next) {
2864 for (e = c->expr; e; e = e->next)
2866 buf[0] = cpu_to_le32(c->permissions);
2867 buf[1] = cpu_to_le32(nel);
2868 rc = put_entry(buf, sizeof(u32), 2, fp);
2871 for (e = c->expr; e; e = e->next) {
2872 buf[0] = cpu_to_le32(e->expr_type);
2873 buf[1] = cpu_to_le32(e->attr);
2874 buf[2] = cpu_to_le32(e->op);
2875 rc = put_entry(buf, sizeof(u32), 3, fp);
2879 switch (e->expr_type) {
2881 rc = ebitmap_write(&e->names, fp);
2884 if (p->policyvers >=
2885 POLICYDB_VERSION_CONSTRAINT_NAMES) {
2886 rc = type_set_write(e->type_names, fp);
2900 static int class_write(void *vkey, void *datum, void *ptr)
2903 struct class_datum *cladatum = datum;
2904 struct policy_data *pd = ptr;
2906 struct policydb *p = pd->p;
2907 struct constraint_node *c;
2914 if (cladatum->comkey)
2915 len2 = strlen(cladatum->comkey);
2920 for (c = cladatum->constraints; c; c = c->next)
2923 buf[0] = cpu_to_le32(len);
2924 buf[1] = cpu_to_le32(len2);
2925 buf[2] = cpu_to_le32(cladatum->value);
2926 buf[3] = cpu_to_le32(cladatum->permissions.nprim);
2927 if (cladatum->permissions.table)
2928 buf[4] = cpu_to_le32(cladatum->permissions.table->nel);
2931 buf[5] = cpu_to_le32(ncons);
2932 rc = put_entry(buf, sizeof(u32), 6, fp);
2936 rc = put_entry(key, 1, len, fp);
2940 if (cladatum->comkey) {
2941 rc = put_entry(cladatum->comkey, 1, len2, fp);
2946 rc = hashtab_map(cladatum->permissions.table, perm_write, fp);
2950 rc = write_cons_helper(p, cladatum->constraints, fp);
2954 /* write out the validatetrans rule */
2956 for (c = cladatum->validatetrans; c; c = c->next)
2959 buf[0] = cpu_to_le32(ncons);
2960 rc = put_entry(buf, sizeof(u32), 1, fp);
2964 rc = write_cons_helper(p, cladatum->validatetrans, fp);
2968 if (p->policyvers >= POLICYDB_VERSION_NEW_OBJECT_DEFAULTS) {
2969 buf[0] = cpu_to_le32(cladatum->default_user);
2970 buf[1] = cpu_to_le32(cladatum->default_role);
2971 buf[2] = cpu_to_le32(cladatum->default_range);
2973 rc = put_entry(buf, sizeof(uint32_t), 3, fp);
2978 if (p->policyvers >= POLICYDB_VERSION_DEFAULT_TYPE) {
2979 buf[0] = cpu_to_le32(cladatum->default_type);
2980 rc = put_entry(buf, sizeof(uint32_t), 1, fp);
2988 static int role_write(void *vkey, void *datum, void *ptr)
2991 struct role_datum *role = datum;
2992 struct policy_data *pd = ptr;
2994 struct policydb *p = pd->p;
3001 buf[items++] = cpu_to_le32(len);
3002 buf[items++] = cpu_to_le32(role->value);
3003 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
3004 buf[items++] = cpu_to_le32(role->bounds);
3006 BUG_ON(items > ARRAY_SIZE(buf));
3008 rc = put_entry(buf, sizeof(u32), items, fp);
3012 rc = put_entry(key, 1, len, fp);
3016 rc = ebitmap_write(&role->dominates, fp);
3020 rc = ebitmap_write(&role->types, fp);
3027 static int type_write(void *vkey, void *datum, void *ptr)
3030 struct type_datum *typdatum = datum;
3031 struct policy_data *pd = ptr;
3032 struct policydb *p = pd->p;
3040 buf[items++] = cpu_to_le32(len);
3041 buf[items++] = cpu_to_le32(typdatum->value);
3042 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) {
3045 if (typdatum->primary)
3046 properties |= TYPEDATUM_PROPERTY_PRIMARY;
3048 if (typdatum->attribute)
3049 properties |= TYPEDATUM_PROPERTY_ATTRIBUTE;
3051 buf[items++] = cpu_to_le32(properties);
3052 buf[items++] = cpu_to_le32(typdatum->bounds);
3054 buf[items++] = cpu_to_le32(typdatum->primary);
3056 BUG_ON(items > ARRAY_SIZE(buf));
3057 rc = put_entry(buf, sizeof(u32), items, fp);
3061 rc = put_entry(key, 1, len, fp);
3068 static int user_write(void *vkey, void *datum, void *ptr)
3071 struct user_datum *usrdatum = datum;
3072 struct policy_data *pd = ptr;
3073 struct policydb *p = pd->p;
3081 buf[items++] = cpu_to_le32(len);
3082 buf[items++] = cpu_to_le32(usrdatum->value);
3083 if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
3084 buf[items++] = cpu_to_le32(usrdatum->bounds);
3085 BUG_ON(items > ARRAY_SIZE(buf));
3086 rc = put_entry(buf, sizeof(u32), items, fp);
3090 rc = put_entry(key, 1, len, fp);
3094 rc = ebitmap_write(&usrdatum->roles, fp);
3098 rc = mls_write_range_helper(&usrdatum->range, fp);
3102 rc = mls_write_level(&usrdatum->dfltlevel, fp);
3109 static int (*write_f[SYM_NUM]) (void *key, void *datum,
3122 static int ocontext_write(struct policydb *p, struct policydb_compat_info *info,
3125 unsigned int i, j, rc;
3127 __be64 prefixbuf[1];
3131 for (i = 0; i < info->ocon_num; i++) {
3133 for (c = p->ocontexts[i]; c; c = c->next)
3135 buf[0] = cpu_to_le32(nel);
3136 rc = put_entry(buf, sizeof(u32), 1, fp);
3139 for (c = p->ocontexts[i]; c; c = c->next) {
3142 buf[0] = cpu_to_le32(c->sid[0]);
3143 rc = put_entry(buf, sizeof(u32), 1, fp);
3146 rc = context_write(p, &c->context[0], fp);
3152 len = strlen(c->u.name);
3153 buf[0] = cpu_to_le32(len);
3154 rc = put_entry(buf, sizeof(u32), 1, fp);
3157 rc = put_entry(c->u.name, 1, len, fp);
3160 rc = context_write(p, &c->context[0], fp);
3163 rc = context_write(p, &c->context[1], fp);
3168 buf[0] = cpu_to_le32(c->u.port.protocol);
3169 buf[1] = cpu_to_le32(c->u.port.low_port);
3170 buf[2] = cpu_to_le32(c->u.port.high_port);
3171 rc = put_entry(buf, sizeof(u32), 3, fp);
3174 rc = context_write(p, &c->context[0], fp);
3179 nodebuf[0] = c->u.node.addr; /* network order */
3180 nodebuf[1] = c->u.node.mask; /* network order */
3181 rc = put_entry(nodebuf, sizeof(u32), 2, fp);
3184 rc = context_write(p, &c->context[0], fp);
3189 buf[0] = cpu_to_le32(c->v.behavior);
3190 len = strlen(c->u.name);
3191 buf[1] = cpu_to_le32(len);
3192 rc = put_entry(buf, sizeof(u32), 2, fp);
3195 rc = put_entry(c->u.name, 1, len, fp);
3198 rc = context_write(p, &c->context[0], fp);
3203 for (j = 0; j < 4; j++)
3204 nodebuf[j] = c->u.node6.addr[j]; /* network order */
3205 for (j = 0; j < 4; j++)
3206 nodebuf[j + 4] = c->u.node6.mask[j]; /* network order */
3207 rc = put_entry(nodebuf, sizeof(u32), 8, fp);
3210 rc = context_write(p, &c->context[0], fp);
3215 /* subnet_prefix is in CPU order */
3216 prefixbuf[0] = cpu_to_be64(c->u.ibpkey.subnet_prefix);
3218 rc = put_entry(prefixbuf, sizeof(u64), 1, fp);
3222 buf[0] = cpu_to_le32(c->u.ibpkey.low_pkey);
3223 buf[1] = cpu_to_le32(c->u.ibpkey.high_pkey);
3225 rc = put_entry(buf, sizeof(u32), 2, fp);
3228 rc = context_write(p, &c->context[0], fp);
3232 case OCON_IBENDPORT:
3233 len = strlen(c->u.ibendport.dev_name);
3234 buf[0] = cpu_to_le32(len);
3235 buf[1] = cpu_to_le32(c->u.ibendport.port);
3236 rc = put_entry(buf, sizeof(u32), 2, fp);
3239 rc = put_entry(c->u.ibendport.dev_name, 1, len, fp);
3242 rc = context_write(p, &c->context[0], fp);
3252 static int genfs_write(struct policydb *p, void *fp)
3254 struct genfs *genfs;
3261 for (genfs = p->genfs; genfs; genfs = genfs->next)
3263 buf[0] = cpu_to_le32(len);
3264 rc = put_entry(buf, sizeof(u32), 1, fp);
3267 for (genfs = p->genfs; genfs; genfs = genfs->next) {
3268 len = strlen(genfs->fstype);
3269 buf[0] = cpu_to_le32(len);
3270 rc = put_entry(buf, sizeof(u32), 1, fp);
3273 rc = put_entry(genfs->fstype, 1, len, fp);
3277 for (c = genfs->head; c; c = c->next)
3279 buf[0] = cpu_to_le32(len);
3280 rc = put_entry(buf, sizeof(u32), 1, fp);
3283 for (c = genfs->head; c; c = c->next) {
3284 len = strlen(c->u.name);
3285 buf[0] = cpu_to_le32(len);
3286 rc = put_entry(buf, sizeof(u32), 1, fp);
3289 rc = put_entry(c->u.name, 1, len, fp);
3292 buf[0] = cpu_to_le32(c->v.sclass);
3293 rc = put_entry(buf, sizeof(u32), 1, fp);
3296 rc = context_write(p, &c->context[0], fp);
3304 static int hashtab_cnt(void *key, void *data, void *ptr)
3312 static int range_write_helper(void *key, void *data, void *ptr)
3315 struct range_trans *rt = key;
3316 struct mls_range *r = data;
3317 struct policy_data *pd = ptr;
3319 struct policydb *p = pd->p;
3322 buf[0] = cpu_to_le32(rt->source_type);
3323 buf[1] = cpu_to_le32(rt->target_type);
3324 rc = put_entry(buf, sizeof(u32), 2, fp);
3327 if (p->policyvers >= POLICYDB_VERSION_RANGETRANS) {
3328 buf[0] = cpu_to_le32(rt->target_class);
3329 rc = put_entry(buf, sizeof(u32), 1, fp);
3333 rc = mls_write_range_helper(r, fp);
3340 static int range_write(struct policydb *p, void *fp)
3344 struct policy_data pd;
3349 /* count the number of entries in the hashtab */
3351 rc = hashtab_map(p->range_tr, hashtab_cnt, &nel);
3355 buf[0] = cpu_to_le32(nel);
3356 rc = put_entry(buf, sizeof(u32), 1, fp);
3360 /* actually write all of the entries */
3361 rc = hashtab_map(p->range_tr, range_write_helper, &pd);
3368 static int filename_write_helper(void *key, void *data, void *ptr)
3371 struct filename_trans *ft = key;
3372 struct filename_trans_datum *otype = data;
3377 len = strlen(ft->name);
3378 buf[0] = cpu_to_le32(len);
3379 rc = put_entry(buf, sizeof(u32), 1, fp);
3383 rc = put_entry(ft->name, sizeof(char), len, fp);
3387 buf[0] = cpu_to_le32(ft->stype);
3388 buf[1] = cpu_to_le32(ft->ttype);
3389 buf[2] = cpu_to_le32(ft->tclass);
3390 buf[3] = cpu_to_le32(otype->otype);
3392 rc = put_entry(buf, sizeof(u32), 4, fp);
3399 static int filename_trans_write(struct policydb *p, void *fp)
3405 if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
3409 rc = hashtab_map(p->filename_trans, hashtab_cnt, &nel);
3413 buf[0] = cpu_to_le32(nel);
3414 rc = put_entry(buf, sizeof(u32), 1, fp);
3418 rc = hashtab_map(p->filename_trans, filename_write_helper, fp);
3426 * Write the configuration data in a policy database
3427 * structure to a policy database binary representation
3430 int policydb_write(struct policydb *p, void *fp)
3432 unsigned int i, num_syms;
3437 struct policydb_compat_info *info;
3440 * refuse to write policy older than compressed avtab
3441 * to simplify the writer. There are other tests dropped
3442 * since we assume this throughout the writer code. Be
3443 * careful if you ever try to remove this restriction
3445 if (p->policyvers < POLICYDB_VERSION_AVTAB) {
3446 printk(KERN_ERR "SELinux: refusing to write policy version %d."
3447 " Because it is less than version %d\n", p->policyvers,
3448 POLICYDB_VERSION_AVTAB);
3454 config |= POLICYDB_CONFIG_MLS;
3456 if (p->reject_unknown)
3457 config |= REJECT_UNKNOWN;
3458 if (p->allow_unknown)
3459 config |= ALLOW_UNKNOWN;
3461 /* Write the magic number and string identifiers. */
3462 buf[0] = cpu_to_le32(POLICYDB_MAGIC);
3463 len = strlen(POLICYDB_STRING);
3464 buf[1] = cpu_to_le32(len);
3465 rc = put_entry(buf, sizeof(u32), 2, fp);
3468 rc = put_entry(POLICYDB_STRING, 1, len, fp);
3472 /* Write the version, config, and table sizes. */
3473 info = policydb_lookup_compat(p->policyvers);
3475 printk(KERN_ERR "SELinux: compatibility lookup failed for policy "
3476 "version %d", p->policyvers);
3480 buf[0] = cpu_to_le32(p->policyvers);
3481 buf[1] = cpu_to_le32(config);
3482 buf[2] = cpu_to_le32(info->sym_num);
3483 buf[3] = cpu_to_le32(info->ocon_num);
3485 rc = put_entry(buf, sizeof(u32), 4, fp);
3489 if (p->policyvers >= POLICYDB_VERSION_POLCAP) {
3490 rc = ebitmap_write(&p->policycaps, fp);
3495 if (p->policyvers >= POLICYDB_VERSION_PERMISSIVE) {
3496 rc = ebitmap_write(&p->permissive_map, fp);
3501 num_syms = info->sym_num;
3502 for (i = 0; i < num_syms; i++) {
3503 struct policy_data pd;
3508 buf[0] = cpu_to_le32(p->symtab[i].nprim);
3509 buf[1] = cpu_to_le32(p->symtab[i].table->nel);
3511 rc = put_entry(buf, sizeof(u32), 2, fp);
3514 rc = hashtab_map(p->symtab[i].table, write_f[i], &pd);
3519 rc = avtab_write(p, &p->te_avtab, fp);
3523 rc = cond_write_list(p, p->cond_list, fp);
3527 rc = role_trans_write(p, fp);
3531 rc = role_allow_write(p->role_allow, fp);
3535 rc = filename_trans_write(p, fp);
3539 rc = ocontext_write(p, info, fp);
3543 rc = genfs_write(p, fp);
3547 rc = range_write(p, fp);
3551 for (i = 0; i < p->p_types.nprim; i++) {
3552 struct ebitmap *e = flex_array_get(p->type_attr_map_array, i);
3555 rc = ebitmap_write(e, fp);