Lines Matching +full:rc +full:- +full:map +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-only
17 * Updated: Hewlett-Packard <paul@paul-moore.com>
35 * Copyright (C) 2006, 2007 Hewlett-Packard Development Company, L.P.
36 * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
37 * Copyright (C) 2003 - 2004, 2006 Tresys Technology, LLC
96 const struct security_class_mapping *map, in selinux_set_mapping() argument
103 if (!map) in selinux_set_mapping()
104 return -EINVAL; in selinux_set_mapping()
106 while (map[i].name) in selinux_set_mapping()
110 out_map->mapping = kcalloc(++i, sizeof(*out_map->mapping), GFP_ATOMIC); in selinux_set_mapping()
111 if (!out_map->mapping) in selinux_set_mapping()
112 return -ENOMEM; in selinux_set_mapping()
116 while (map[j].name) { in selinux_set_mapping()
117 const struct security_class_mapping *p_in = map + (j++); in selinux_set_mapping()
118 struct selinux_mapping *p_out = out_map->mapping + j; in selinux_set_mapping()
122 if (!strcmp(p_in->name, "")) { in selinux_set_mapping()
123 p_out->num_perms = 0; in selinux_set_mapping()
127 p_out->value = string_to_security_class(pol, p_in->name); in selinux_set_mapping()
128 if (!p_out->value) { in selinux_set_mapping()
130 p_in->name); in selinux_set_mapping()
131 if (pol->reject_unknown) in selinux_set_mapping()
133 p_out->num_perms = 0; in selinux_set_mapping()
139 while (p_in->perms[k]) { in selinux_set_mapping()
141 if (!*p_in->perms[k]) { in selinux_set_mapping()
145 p_out->perms[k] = string_to_av_perm(pol, p_out->value, in selinux_set_mapping()
146 p_in->perms[k]); in selinux_set_mapping()
147 if (!p_out->perms[k]) { in selinux_set_mapping()
149 p_in->perms[k], p_in->name); in selinux_set_mapping()
150 if (pol->reject_unknown) in selinux_set_mapping()
157 p_out->num_perms = k; in selinux_set_mapping()
162 pol->allow_unknown ? "allowed" : "denied"); in selinux_set_mapping()
164 out_map->size = i; in selinux_set_mapping()
167 kfree(out_map->mapping); in selinux_set_mapping()
168 out_map->mapping = NULL; in selinux_set_mapping()
169 return -EINVAL; in selinux_set_mapping()
176 static u16 unmap_class(struct selinux_map *map, u16 tclass) in unmap_class() argument
178 if (tclass < map->size) in unmap_class()
179 return map->mapping[tclass].value; in unmap_class()
187 static u16 map_class(struct selinux_map *map, u16 pol_value) in map_class() argument
191 for (i = 1; i < map->size; i++) { in map_class()
192 if (map->mapping[i].value == pol_value) in map_class()
199 static void map_decision(struct selinux_map *map, in map_decision() argument
203 if (tclass < map->size) { in map_decision()
204 struct selinux_mapping *mapping = &map->mapping[tclass]; in map_decision()
205 unsigned int i, n = mapping->num_perms; in map_decision()
209 if (avd->allowed & mapping->perms[i]) in map_decision()
211 if (allow_unknown && !mapping->perms[i]) in map_decision()
214 avd->allowed = result; in map_decision()
217 if (avd->auditallow & mapping->perms[i]) in map_decision()
219 avd->auditallow = result; in map_decision()
222 if (avd->auditdeny & mapping->perms[i]) in map_decision()
224 if (!allow_unknown && !mapping->perms[i]) in map_decision()
234 avd->auditdeny = result; in map_decision()
248 mls_enabled = policy->policydb.mls_enabled; in security_mls_enabled()
276 int sp = -1; in constraint_expr_eval()
278 for (e = cexpr; e; e = e->next) { in constraint_expr_eval()
279 switch (e->expr_type) { in constraint_expr_eval()
286 sp--; in constraint_expr_eval()
291 sp--; in constraint_expr_eval()
295 if (sp == (CEXPR_MAXDEPTH - 1)) in constraint_expr_eval()
297 switch (e->attr) { in constraint_expr_eval()
299 val1 = scontext->user; in constraint_expr_eval()
300 val2 = tcontext->user; in constraint_expr_eval()
303 val1 = scontext->type; in constraint_expr_eval()
304 val2 = tcontext->type; in constraint_expr_eval()
307 val1 = scontext->role; in constraint_expr_eval()
308 val2 = tcontext->role; in constraint_expr_eval()
309 r1 = policydb->role_val_to_struct[val1 - 1]; in constraint_expr_eval()
310 r2 = policydb->role_val_to_struct[val2 - 1]; in constraint_expr_eval()
311 switch (e->op) { in constraint_expr_eval()
313 s[++sp] = ebitmap_get_bit(&r1->dominates, in constraint_expr_eval()
314 val2 - 1); in constraint_expr_eval()
317 s[++sp] = ebitmap_get_bit(&r2->dominates, in constraint_expr_eval()
318 val1 - 1); in constraint_expr_eval()
321 s[++sp] = (!ebitmap_get_bit(&r1->dominates, in constraint_expr_eval()
322 val2 - 1) && in constraint_expr_eval()
323 !ebitmap_get_bit(&r2->dominates, in constraint_expr_eval()
324 val1 - 1)); in constraint_expr_eval()
331 l1 = &(scontext->range.level[0]); in constraint_expr_eval()
332 l2 = &(tcontext->range.level[0]); in constraint_expr_eval()
335 l1 = &(scontext->range.level[0]); in constraint_expr_eval()
336 l2 = &(tcontext->range.level[1]); in constraint_expr_eval()
339 l1 = &(scontext->range.level[1]); in constraint_expr_eval()
340 l2 = &(tcontext->range.level[0]); in constraint_expr_eval()
343 l1 = &(scontext->range.level[1]); in constraint_expr_eval()
344 l2 = &(tcontext->range.level[1]); in constraint_expr_eval()
347 l1 = &(scontext->range.level[0]); in constraint_expr_eval()
348 l2 = &(scontext->range.level[1]); in constraint_expr_eval()
351 l1 = &(tcontext->range.level[0]); in constraint_expr_eval()
352 l2 = &(tcontext->range.level[1]); in constraint_expr_eval()
355 switch (e->op) { in constraint_expr_eval()
381 switch (e->op) { in constraint_expr_eval()
394 if (sp == (CEXPR_MAXDEPTH-1)) in constraint_expr_eval()
397 if (e->attr & CEXPR_TARGET) in constraint_expr_eval()
399 else if (e->attr & CEXPR_XTARGET) { in constraint_expr_eval()
406 if (e->attr & CEXPR_USER) in constraint_expr_eval()
407 val1 = c->user; in constraint_expr_eval()
408 else if (e->attr & CEXPR_ROLE) in constraint_expr_eval()
409 val1 = c->role; in constraint_expr_eval()
410 else if (e->attr & CEXPR_TYPE) in constraint_expr_eval()
411 val1 = c->type; in constraint_expr_eval()
417 switch (e->op) { in constraint_expr_eval()
419 s[++sp] = ebitmap_get_bit(&e->names, val1 - 1); in constraint_expr_eval()
422 s[++sp] = !ebitmap_get_bit(&e->names, val1 - 1); in constraint_expr_eval()
440 * security_dump_masked_av - dumps masked permissions during
448 BUG_ON(pdatum->value < 1 || pdatum->value > 32); in dump_masked_av_helper()
450 permission_names[pdatum->value - 1] = (char *)k; in dump_masked_av_helper()
476 tclass_name = sym_name(policydb, SYM_CLASSES, tclass - 1); in security_dump_masked_av()
477 tclass_dat = policydb->class_val_to_struct[tclass - 1]; in security_dump_masked_av()
478 common_dat = tclass_dat->comdatum; in security_dump_masked_av()
482 hashtab_map(&common_dat->permissions.table, in security_dump_masked_av()
486 if (hashtab_map(&tclass_dat->permissions.table, in security_dump_masked_av()
529 * security_boundary_permission - drops violated permissions
545 source = policydb->type_val_to_struct[scontext->type - 1]; in type_attribute_bounds_av()
548 if (!source->bounds) in type_attribute_bounds_av()
551 target = policydb->type_val_to_struct[tcontext->type - 1]; in type_attribute_bounds_av()
557 lo_scontext.type = source->bounds; in type_attribute_bounds_av()
559 if (target->bounds) { in type_attribute_bounds_av()
561 lo_tcontext.type = target->bounds; in type_attribute_bounds_av()
571 masked = ~lo_avd.allowed & avd->allowed; in type_attribute_bounds_av()
577 avd->allowed &= ~masked; in type_attribute_bounds_av()
594 if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLDRIVER) { in services_compute_xperms_drivers()
596 for (i = 0; i < ARRAY_SIZE(xperms->drivers.p); i++) in services_compute_xperms_drivers()
597 xperms->drivers.p[i] |= node->datum.u.xperms->perms.p[i]; in services_compute_xperms_drivers()
598 } else if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLFUNCTION) { in services_compute_xperms_drivers()
600 security_xperm_set(xperms->drivers.p, in services_compute_xperms_drivers()
601 node->datum.u.xperms->driver); in services_compute_xperms_drivers()
604 xperms->len = 1; in services_compute_xperms_drivers()
627 avd->allowed = 0; in context_struct_compute_av()
628 avd->auditallow = 0; in context_struct_compute_av()
629 avd->auditdeny = 0xffffffff; in context_struct_compute_av()
631 memset(&xperms->drivers, 0, sizeof(xperms->drivers)); in context_struct_compute_av()
632 xperms->len = 0; in context_struct_compute_av()
635 if (unlikely(!tclass || tclass > policydb->p_classes.nprim)) { in context_struct_compute_av()
640 tclass_datum = policydb->class_val_to_struct[tclass - 1]; in context_struct_compute_av()
648 sattr = &policydb->type_attr_map_array[scontext->type - 1]; in context_struct_compute_av()
649 tattr = &policydb->type_attr_map_array[tcontext->type - 1]; in context_struct_compute_av()
654 for (node = avtab_search_node(&policydb->te_avtab, in context_struct_compute_av()
658 if (node->key.specified == AVTAB_ALLOWED) in context_struct_compute_av()
659 avd->allowed |= node->datum.u.data; in context_struct_compute_av()
660 else if (node->key.specified == AVTAB_AUDITALLOW) in context_struct_compute_av()
661 avd->auditallow |= node->datum.u.data; in context_struct_compute_av()
662 else if (node->key.specified == AVTAB_AUDITDENY) in context_struct_compute_av()
663 avd->auditdeny &= node->datum.u.data; in context_struct_compute_av()
664 else if (xperms && (node->key.specified & AVTAB_XPERMS)) in context_struct_compute_av()
669 cond_compute_av(&policydb->te_cond_avtab, &avkey, in context_struct_compute_av()
679 constraint = tclass_datum->constraints; in context_struct_compute_av()
681 if ((constraint->permissions & (avd->allowed)) && in context_struct_compute_av()
683 constraint->expr)) { in context_struct_compute_av()
684 avd->allowed &= ~(constraint->permissions); in context_struct_compute_av()
686 constraint = constraint->next; in context_struct_compute_av()
694 if (tclass == policydb->process_class && in context_struct_compute_av()
695 (avd->allowed & policydb->process_trans_perms) && in context_struct_compute_av()
696 scontext->role != tcontext->role) { in context_struct_compute_av()
697 for (ra = policydb->role_allow; ra; ra = ra->next) { in context_struct_compute_av()
698 if (scontext->role == ra->role && in context_struct_compute_av()
699 tcontext->role == ra->new_role) in context_struct_compute_av()
703 avd->allowed &= ~policydb->process_trans_perms; in context_struct_compute_av()
721 struct policydb *p = &policy->policydb; in security_validtrans_handle_fail()
722 struct sidtab *sidtab = policy->sidtab; in security_validtrans_handle_fail()
735 o, n, t, sym_name(p, SYM_CLASSES, tclass-1)); in security_validtrans_handle_fail()
743 return -EPERM; in security_validtrans_handle_fail()
758 int rc = 0; in security_compute_validatetrans() local
767 policydb = &policy->policydb; in security_compute_validatetrans()
768 sidtab = policy->sidtab; in security_compute_validatetrans()
771 tclass = unmap_class(&policy->map, orig_tclass); in security_compute_validatetrans()
775 if (!tclass || tclass > policydb->p_classes.nprim) { in security_compute_validatetrans()
776 rc = -EINVAL; in security_compute_validatetrans()
779 tclass_datum = policydb->class_val_to_struct[tclass - 1]; in security_compute_validatetrans()
785 rc = -EINVAL; in security_compute_validatetrans()
793 rc = -EINVAL; in security_compute_validatetrans()
801 rc = -EINVAL; in security_compute_validatetrans()
805 constraint = tclass_datum->validatetrans; in security_compute_validatetrans()
807 if (!constraint_expr_eval(policydb, &oentry->context, in security_compute_validatetrans()
808 &nentry->context, &tentry->context, in security_compute_validatetrans()
809 constraint->expr)) { in security_compute_validatetrans()
811 rc = -EPERM; in security_compute_validatetrans()
813 rc = security_validtrans_handle_fail(policy, in security_compute_validatetrans()
820 constraint = constraint->next; in security_compute_validatetrans()
825 return rc; in security_compute_validatetrans()
843 * security_bounded_transition - check whether the given
859 int rc; in security_bounded_transition() local
866 policydb = &policy->policydb; in security_bounded_transition()
867 sidtab = policy->sidtab; in security_bounded_transition()
869 rc = -EINVAL; in security_bounded_transition()
877 rc = -EINVAL; in security_bounded_transition()
885 rc = 0; in security_bounded_transition()
887 if (old_entry->context.type == new_entry->context.type) in security_bounded_transition()
890 index = new_entry->context.type; in security_bounded_transition()
892 type = policydb->type_val_to_struct[index - 1]; in security_bounded_transition()
896 rc = -EPERM; in security_bounded_transition()
897 if (!type->bounds) in security_bounded_transition()
901 rc = 0; in security_bounded_transition()
902 if (type->bounds == old_entry->context.type) in security_bounded_transition()
905 index = type->bounds; in security_bounded_transition()
908 if (rc) { in security_bounded_transition()
930 return rc; in security_bounded_transition()
935 avd->allowed = 0; in avd_init()
936 avd->auditallow = 0; in avd_init()
937 avd->auditdeny = 0xffffffff; in avd_init()
939 avd->seqno = policy->latest_granting; in avd_init()
941 avd->seqno = 0; in avd_init()
942 avd->flags = 0; in avd_init()
950 if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLFUNCTION) { in services_compute_xperms_decision()
951 if (xpermd->driver != node->datum.u.xperms->driver) in services_compute_xperms_decision()
953 } else if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLDRIVER) { in services_compute_xperms_decision()
954 if (!security_xperm_test(node->datum.u.xperms->perms.p, in services_compute_xperms_decision()
955 xpermd->driver)) in services_compute_xperms_decision()
961 if (node->key.specified == AVTAB_XPERMS_ALLOWED) { in services_compute_xperms_decision()
962 xpermd->used |= XPERMS_ALLOWED; in services_compute_xperms_decision()
963 if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLDRIVER) { in services_compute_xperms_decision()
964 memset(xpermd->allowed->p, 0xff, in services_compute_xperms_decision()
965 sizeof(xpermd->allowed->p)); in services_compute_xperms_decision()
967 if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLFUNCTION) { in services_compute_xperms_decision()
968 for (i = 0; i < ARRAY_SIZE(xpermd->allowed->p); i++) in services_compute_xperms_decision()
969 xpermd->allowed->p[i] |= in services_compute_xperms_decision()
970 node->datum.u.xperms->perms.p[i]; in services_compute_xperms_decision()
972 } else if (node->key.specified == AVTAB_XPERMS_AUDITALLOW) { in services_compute_xperms_decision()
973 xpermd->used |= XPERMS_AUDITALLOW; in services_compute_xperms_decision()
974 if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLDRIVER) { in services_compute_xperms_decision()
975 memset(xpermd->auditallow->p, 0xff, in services_compute_xperms_decision()
976 sizeof(xpermd->auditallow->p)); in services_compute_xperms_decision()
978 if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLFUNCTION) { in services_compute_xperms_decision()
979 for (i = 0; i < ARRAY_SIZE(xpermd->auditallow->p); i++) in services_compute_xperms_decision()
980 xpermd->auditallow->p[i] |= in services_compute_xperms_decision()
981 node->datum.u.xperms->perms.p[i]; in services_compute_xperms_decision()
983 } else if (node->key.specified == AVTAB_XPERMS_DONTAUDIT) { in services_compute_xperms_decision()
984 xpermd->used |= XPERMS_DONTAUDIT; in services_compute_xperms_decision()
985 if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLDRIVER) { in services_compute_xperms_decision()
986 memset(xpermd->dontaudit->p, 0xff, in services_compute_xperms_decision()
987 sizeof(xpermd->dontaudit->p)); in services_compute_xperms_decision()
989 if (node->datum.u.xperms->specified == AVTAB_XPERMS_IOCTLFUNCTION) { in services_compute_xperms_decision()
990 for (i = 0; i < ARRAY_SIZE(xpermd->dontaudit->p); i++) in services_compute_xperms_decision()
991 xpermd->dontaudit->p[i] |= in services_compute_xperms_decision()
992 node->datum.u.xperms->perms.p[i]; in services_compute_xperms_decision()
1016 xpermd->driver = driver; in security_compute_xperms_decision()
1017 xpermd->used = 0; in security_compute_xperms_decision()
1018 memset(xpermd->allowed->p, 0, sizeof(xpermd->allowed->p)); in security_compute_xperms_decision()
1019 memset(xpermd->auditallow->p, 0, sizeof(xpermd->auditallow->p)); in security_compute_xperms_decision()
1020 memset(xpermd->dontaudit->p, 0, sizeof(xpermd->dontaudit->p)); in security_compute_xperms_decision()
1027 policydb = &policy->policydb; in security_compute_xperms_decision()
1028 sidtab = policy->sidtab; in security_compute_xperms_decision()
1044 tclass = unmap_class(&policy->map, orig_tclass); in security_compute_xperms_decision()
1046 if (policydb->allow_unknown) in security_compute_xperms_decision()
1052 if (unlikely(!tclass || tclass > policydb->p_classes.nprim)) { in security_compute_xperms_decision()
1059 sattr = &policydb->type_attr_map_array[scontext->type - 1]; in security_compute_xperms_decision()
1060 tattr = &policydb->type_attr_map_array[tcontext->type - 1]; in security_compute_xperms_decision()
1065 for (node = avtab_search_node(&policydb->te_avtab, in security_compute_xperms_decision()
1071 cond_compute_xperms(&policydb->te_cond_avtab, in security_compute_xperms_decision()
1079 memset(xpermd->allowed->p, 0xff, sizeof(xpermd->allowed->p)); in security_compute_xperms_decision()
1084 * security_compute_av - Compute access vector decisions.
1109 xperms->len = 0; in security_compute_av()
1113 policydb = &policy->policydb; in security_compute_av()
1114 sidtab = policy->sidtab; in security_compute_av()
1124 if (ebitmap_get_bit(&policydb->permissive_map, scontext->type)) in security_compute_av()
1125 avd->flags |= AVD_FLAGS_PERMISSIVE; in security_compute_av()
1134 tclass = unmap_class(&policy->map, orig_tclass); in security_compute_av()
1136 if (policydb->allow_unknown) in security_compute_av()
1142 map_decision(&policy->map, orig_tclass, avd, in security_compute_av()
1143 policydb->allow_unknown); in security_compute_av()
1148 avd->allowed = 0xffffffff; in security_compute_av()
1168 policydb = &policy->policydb; in security_compute_av_user()
1169 sidtab = policy->sidtab; in security_compute_av_user()
1179 if (ebitmap_get_bit(&policydb->permissive_map, scontext->type)) in security_compute_av_user()
1180 avd->flags |= AVD_FLAGS_PERMISSIVE; in security_compute_av_user()
1190 if (policydb->allow_unknown) in security_compute_av_user()
1201 avd->allowed = 0xffffffff; in security_compute_av_user()
1222 if (context->len) { in context_struct_to_string()
1223 *scontext_len = context->len; in context_struct_to_string()
1225 *scontext = kstrdup(context->str, GFP_ATOMIC); in context_struct_to_string()
1227 return -ENOMEM; in context_struct_to_string()
1233 *scontext_len += strlen(sym_name(p, SYM_USERS, context->user - 1)) + 1; in context_struct_to_string()
1234 *scontext_len += strlen(sym_name(p, SYM_ROLES, context->role - 1)) + 1; in context_struct_to_string()
1235 *scontext_len += strlen(sym_name(p, SYM_TYPES, context->type - 1)) + 1; in context_struct_to_string()
1244 return -ENOMEM; in context_struct_to_string()
1248 * Copy the user name, role name and type name into the context. in context_struct_to_string()
1251 sym_name(p, SYM_USERS, context->user - 1), in context_struct_to_string()
1252 sym_name(p, SYM_ROLES, context->role - 1), in context_struct_to_string()
1253 sym_name(p, SYM_TYPES, context->type - 1)); in context_struct_to_string()
1267 int rc = sidtab_sid2str_get(sidtab, entry, scontext, scontext_len); in sidtab_entry_to_string() local
1269 if (rc != -ENOENT) in sidtab_entry_to_string()
1270 return rc; in sidtab_entry_to_string()
1272 rc = context_struct_to_string(p, &entry->context, scontext, in sidtab_entry_to_string()
1274 if (!rc && scontext) in sidtab_entry_to_string()
1276 return rc; in sidtab_entry_to_string()
1284 int rc; in security_sidtab_hash_stats() local
1289 return -EINVAL; in security_sidtab_hash_stats()
1294 rc = sidtab_hash_stats(policy->sidtab, page); in security_sidtab_hash_stats()
1297 return rc; in security_sidtab_hash_stats()
1315 int rc = 0; in security_sid_to_context_core() local
1330 * both non-null and not "kernel" to mean that a policy in security_sid_to_context_core()
1338 return -EINVAL; in security_sid_to_context_core()
1344 return -ENOMEM; in security_sid_to_context_core()
1350 return -EINVAL; in security_sid_to_context_core()
1354 policydb = &policy->policydb; in security_sid_to_context_core()
1355 sidtab = policy->sidtab; in security_sid_to_context_core()
1364 rc = -EINVAL; in security_sid_to_context_core()
1367 if (only_invalid && !entry->context.len) in security_sid_to_context_core()
1370 rc = sidtab_entry_to_string(policydb, sidtab, entry, scontext, in security_sid_to_context_core()
1375 return rc; in security_sid_to_context_core()
1380 * security_sid_to_context - Obtain a context for a given SID.
1403 * security_sid_to_context_inval - Obtain a context for a given SID if it
1435 int rc = 0; in string_to_context_struct() local
1441 rc = -EINVAL; in string_to_context_struct()
1454 usrdatum = symtab_search(&pol->p_users, scontextp); in string_to_context_struct()
1458 ctx->user = usrdatum->value; in string_to_context_struct()
1470 role = symtab_search(&pol->p_roles, scontextp); in string_to_context_struct()
1473 ctx->role = role->value; in string_to_context_struct()
1482 typdatum = symtab_search(&pol->p_types, scontextp); in string_to_context_struct()
1483 if (!typdatum || typdatum->attribute) in string_to_context_struct()
1486 ctx->type = typdatum->value; in string_to_context_struct()
1488 rc = mls_context_to_sid(pol, oldc, p, ctx, sidtabp, def_sid); in string_to_context_struct()
1489 if (rc) in string_to_context_struct()
1493 rc = -EINVAL; in string_to_context_struct()
1496 rc = 0; in string_to_context_struct()
1498 if (rc) in string_to_context_struct()
1500 return rc; in string_to_context_struct()
1512 int rc = 0; in security_context_to_sid_core() local
1516 return -EINVAL; in security_context_to_sid_core()
1521 return -ENOMEM; in security_context_to_sid_core()
1541 rc = -ENOMEM; in security_context_to_sid_core()
1549 policydb = &policy->policydb; in security_context_to_sid_core()
1550 sidtab = policy->sidtab; in security_context_to_sid_core()
1551 rc = string_to_context_struct(policydb, sidtab, scontext2, in security_context_to_sid_core()
1553 if (rc == -EINVAL && force) { in security_context_to_sid_core()
1557 } else if (rc) in security_context_to_sid_core()
1559 rc = sidtab_context_to_sid(sidtab, &context, sid); in security_context_to_sid_core()
1560 if (rc == -ESTALE) { in security_context_to_sid_core()
1575 return rc; in security_context_to_sid_core()
1579 * security_context_to_sid - Obtain a SID for a given security context.
1587 * Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient
1604 * security_context_to_sid_default - Obtain a SID for a given security context,
1611 * @gfp_flags: the allocator get-free-page (GFP) flags
1619 * Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient
1643 struct policydb *policydb = &policy->policydb; in compute_sid_handle_invalid_context()
1644 struct sidtab *sidtab = policy->sidtab; in compute_sid_handle_invalid_context()
1661 audit_log_n_untrustedstring(ab, n, nlen - 1); in compute_sid_handle_invalid_context()
1663 s, t, sym_name(policydb, SYM_CLASSES, tclass-1)); in compute_sid_handle_invalid_context()
1671 return -EACCES; in compute_sid_handle_invalid_context()
1687 if (!ebitmap_get_bit(&policydb->filename_trans_ttypes, ttype)) in filename_compute_type()
1692 ft.name = objname; in filename_compute_type()
1696 if (ebitmap_get_bit(&datum->stypes, stype - 1)) { in filename_compute_type()
1697 newcontext->type = datum->otype; in filename_compute_type()
1700 datum = datum->next; in filename_compute_type()
1721 int rc = 0; in security_compute_sid() local
1745 tclass = unmap_class(&policy->map, orig_tclass); in security_compute_sid()
1749 sock = security_is_socket_class(map_class(&policy->map, in security_compute_sid()
1753 policydb = &policy->policydb; in security_compute_sid()
1754 sidtab = policy->sidtab; in security_compute_sid()
1760 rc = -EINVAL; in security_compute_sid()
1767 rc = -EINVAL; in security_compute_sid()
1771 scontext = &sentry->context; in security_compute_sid()
1772 tcontext = &tentry->context; in security_compute_sid()
1774 if (tclass && tclass <= policydb->p_classes.nprim) in security_compute_sid()
1775 cladatum = policydb->class_val_to_struct[tclass - 1]; in security_compute_sid()
1781 if (cladatum && cladatum->default_user == DEFAULT_TARGET) { in security_compute_sid()
1782 newcontext.user = tcontext->user; in security_compute_sid()
1786 newcontext.user = scontext->user; in security_compute_sid()
1791 newcontext.user = tcontext->user; in security_compute_sid()
1796 if (cladatum && cladatum->default_role == DEFAULT_SOURCE) { in security_compute_sid()
1797 newcontext.role = scontext->role; in security_compute_sid()
1798 } else if (cladatum && cladatum->default_role == DEFAULT_TARGET) { in security_compute_sid()
1799 newcontext.role = tcontext->role; in security_compute_sid()
1801 if ((tclass == policydb->process_class) || sock) in security_compute_sid()
1802 newcontext.role = scontext->role; in security_compute_sid()
1810 avkey.source_type = scontext->type; in security_compute_sid()
1811 avkey.target_type = tcontext->type; in security_compute_sid()
1814 avnode = avtab_search_node(&policydb->te_avtab, &avkey); in security_compute_sid()
1818 node = avtab_search_node(&policydb->te_cond_avtab, &avkey); in security_compute_sid()
1820 if (node->key.specified & AVTAB_ENABLED) { in security_compute_sid()
1832 newcontext.type = avnode->datum.u.data; in security_compute_sid()
1833 } else if (cladatum && cladatum->default_type == DEFAULT_SOURCE) { in security_compute_sid()
1834 newcontext.type = scontext->type; in security_compute_sid()
1835 } else if (cladatum && cladatum->default_type == DEFAULT_TARGET) { in security_compute_sid()
1836 newcontext.type = tcontext->type; in security_compute_sid()
1838 if ((tclass == policydb->process_class) || sock) { in security_compute_sid()
1840 newcontext.type = scontext->type; in security_compute_sid()
1843 newcontext.type = tcontext->type; in security_compute_sid()
1849 filename_compute_type(policydb, &newcontext, scontext->type, in security_compute_sid()
1850 tcontext->type, tclass, objname); in security_compute_sid()
1852 /* Check for class-specific changes. */ in security_compute_sid()
1857 .role = scontext->role, in security_compute_sid()
1858 .type = tcontext->type, in security_compute_sid()
1864 newcontext.role = rtd->new_role; in security_compute_sid()
1869 rc = mls_compute_sid(policydb, scontext, tcontext, tclass, specified, in security_compute_sid()
1871 if (rc) in security_compute_sid()
1876 rc = compute_sid_handle_invalid_context(policy, sentry, in security_compute_sid()
1879 if (rc) in security_compute_sid()
1883 rc = sidtab_context_to_sid(sidtab, &newcontext, out_sid); in security_compute_sid()
1884 if (rc == -ESTALE) { in security_compute_sid()
1893 return rc; in security_compute_sid()
1897 * security_transition_sid - Compute the SID for a new subject/object.
1901 * @qstr: object name
1906 * Return -%EINVAL if any of the parameters are invalid, -%ENOMEM
1915 qstr ? qstr->name : NULL, out_sid, true); in security_transition_sid()
1927 * security_member_sid - Compute the SID for member selection.
1935 * Return -%EINVAL if any of the parameters are invalid, -%ENOMEM
1950 * security_change_sid - Compute the SID for object relabeling.
1958 * Return -%EINVAL if any of the parameters are invalid, -%ENOMEM
1979 return -EINVAL; in convert_context_handle_invalid_context()
1990 * services_convert_context - Convert a security context across policies.
1997 * specified in the policy @args->oldp to the values specified in the policy
1998 * @args->newp, storing the new context in @newc, and verifying that the
2011 int rc; in services_convert_context() local
2013 if (oldc->str) { in services_convert_context()
2014 s = kstrdup(oldc->str, gfp_flags); in services_convert_context()
2016 return -ENOMEM; in services_convert_context()
2018 rc = string_to_context_struct(args->newp, NULL, s, newc, SECSID_NULL); in services_convert_context()
2019 if (rc == -EINVAL) { in services_convert_context()
2023 * IMPORTANT: We need to copy the contents of oldc->str in services_convert_context()
2027 memcpy(s, oldc->str, oldc->len); in services_convert_context()
2029 newc->str = s; in services_convert_context()
2030 newc->len = oldc->len; in services_convert_context()
2034 if (rc) { in services_convert_context()
2036 pr_err("SELinux: Unable to map context %s, rc = %d.\n", in services_convert_context()
2037 oldc->str, -rc); in services_convert_context()
2038 return rc; in services_convert_context()
2041 oldc->str); in services_convert_context()
2048 usrdatum = symtab_search(&args->newp->p_users, in services_convert_context()
2049 sym_name(args->oldp, SYM_USERS, oldc->user - 1)); in services_convert_context()
2052 newc->user = usrdatum->value; in services_convert_context()
2055 role = symtab_search(&args->newp->p_roles, in services_convert_context()
2056 sym_name(args->oldp, SYM_ROLES, oldc->role - 1)); in services_convert_context()
2059 newc->role = role->value; in services_convert_context()
2062 typdatum = symtab_search(&args->newp->p_types, in services_convert_context()
2063 sym_name(args->oldp, SYM_TYPES, oldc->type - 1)); in services_convert_context()
2066 newc->type = typdatum->value; in services_convert_context()
2069 if (args->oldp->mls_enabled && args->newp->mls_enabled) { in services_convert_context()
2070 rc = mls_convert_context(args->oldp, args->newp, oldc, newc); in services_convert_context()
2071 if (rc) in services_convert_context()
2073 } else if (!args->oldp->mls_enabled && args->newp->mls_enabled) { in services_convert_context()
2075 * Switching between non-MLS and MLS policy: in services_convert_context()
2081 oc = args->newp->ocontexts[OCON_ISID]; in services_convert_context()
2082 while (oc && oc->sid[0] != SECINITSID_UNLABELED) in services_convert_context()
2083 oc = oc->next; in services_convert_context()
2089 rc = mls_range_set(newc, &oc->context[0].range); in services_convert_context()
2090 if (rc) in services_convert_context()
2095 if (!policydb_context_isvalid(args->newp, newc)) { in services_convert_context()
2096 rc = convert_context_handle_invalid_context(args->oldp, oldc); in services_convert_context()
2097 if (rc) in services_convert_context()
2103 /* Map old representation to string and save it. */ in services_convert_context()
2104 rc = context_struct_to_string(args->oldp, oldc, &s, &len); in services_convert_context()
2105 if (rc) in services_convert_context()
2106 return rc; in services_convert_context()
2108 newc->str = s; in services_convert_context()
2109 newc->len = len; in services_convert_context()
2111 newc->str); in services_convert_context()
2121 p = &policy->policydb; in security_load_policycaps()
2125 ebitmap_get_bit(&p->policycaps, i)); in security_load_policycaps()
2130 ebitmap_get_bit(&p->policycaps, i)); in security_load_policycaps()
2132 ebitmap_for_each_positive_bit(&p->policycaps, node, i) { in security_load_policycaps()
2147 sidtab_destroy(policy->sidtab); in selinux_policy_free()
2148 kfree(policy->map.mapping); in selinux_policy_free()
2149 policydb_destroy(&policy->policydb); in selinux_policy_free()
2150 kfree(policy->sidtab); in selinux_policy_free()
2156 cond_policydb_destroy_dup(&policy->policydb); in selinux_policy_cond_free()
2165 oldpolicy = rcu_dereference_protected(state->policy, in selinux_policy_cancel()
2166 lockdep_is_held(&state->policy_mutex)); in selinux_policy_cancel()
2168 sidtab_cancel_convert(oldpolicy->sidtab); in selinux_policy_cancel()
2169 selinux_policy_free(load_state->policy); in selinux_policy_cancel()
2170 kfree(load_state->convert_data); in selinux_policy_cancel()
2187 struct selinux_policy *oldpolicy, *newpolicy = load_state->policy; in selinux_policy_commit()
2191 oldpolicy = rcu_dereference_protected(state->policy, in selinux_policy_commit()
2192 lockdep_is_held(&state->policy_mutex)); in selinux_policy_commit()
2196 if (oldpolicy->policydb.mls_enabled && !newpolicy->policydb.mls_enabled) in selinux_policy_commit()
2198 else if (!oldpolicy->policydb.mls_enabled && newpolicy->policydb.mls_enabled) in selinux_policy_commit()
2204 newpolicy->latest_granting = oldpolicy->latest_granting + 1; in selinux_policy_commit()
2206 newpolicy->latest_granting = 1; in selinux_policy_commit()
2207 seqno = newpolicy->latest_granting; in selinux_policy_commit()
2211 sidtab_freeze_begin(oldpolicy->sidtab, &flags); in selinux_policy_commit()
2212 rcu_assign_pointer(state->policy, newpolicy); in selinux_policy_commit()
2213 sidtab_freeze_end(oldpolicy->sidtab, &flags); in selinux_policy_commit()
2215 rcu_assign_pointer(state->policy, newpolicy); in selinux_policy_commit()
2234 kfree(load_state->convert_data); in selinux_policy_commit()
2241 * security_load_policy - Load a security policy configuration.
2257 int rc = 0; in security_load_policy() local
2262 return -ENOMEM; in security_load_policy()
2264 newpolicy->sidtab = kzalloc(sizeof(*newpolicy->sidtab), GFP_KERNEL); in security_load_policy()
2265 if (!newpolicy->sidtab) { in security_load_policy()
2266 rc = -ENOMEM; in security_load_policy()
2270 rc = policydb_read(&newpolicy->policydb, fp); in security_load_policy()
2271 if (rc) in security_load_policy()
2274 newpolicy->policydb.len = len; in security_load_policy()
2275 rc = selinux_set_mapping(&newpolicy->policydb, secclass_map, in security_load_policy()
2276 &newpolicy->map); in security_load_policy()
2277 if (rc) in security_load_policy()
2280 rc = policydb_load_isids(&newpolicy->policydb, newpolicy->sidtab); in security_load_policy()
2281 if (rc) { in security_load_policy()
2288 load_state->policy = newpolicy; in security_load_policy()
2289 load_state->convert_data = NULL; in security_load_policy()
2293 oldpolicy = rcu_dereference_protected(state->policy, in security_load_policy()
2294 lockdep_is_held(&state->policy_mutex)); in security_load_policy()
2297 rc = security_preserve_bools(oldpolicy, newpolicy); in security_load_policy()
2298 if (rc) { in security_load_policy()
2310 rc = -ENOMEM; in security_load_policy()
2314 convert_data->args.oldp = &oldpolicy->policydb; in security_load_policy()
2315 convert_data->args.newp = &newpolicy->policydb; in security_load_policy()
2317 convert_data->sidtab_params.args = &convert_data->args; in security_load_policy()
2318 convert_data->sidtab_params.target = newpolicy->sidtab; in security_load_policy()
2320 rc = sidtab_convert(oldpolicy->sidtab, &convert_data->sidtab_params); in security_load_policy()
2321 if (rc) { in security_load_policy()
2328 load_state->policy = newpolicy; in security_load_policy()
2329 load_state->convert_data = convert_data; in security_load_policy()
2335 sidtab_destroy(newpolicy->sidtab); in security_load_policy()
2337 kfree(newpolicy->map.mapping); in security_load_policy()
2339 policydb_destroy(&newpolicy->policydb); in security_load_policy()
2341 kfree(newpolicy->sidtab); in security_load_policy()
2345 return rc; in security_load_policy()
2349 * ocontext_to_sid - Helper to safely get sid for an ocontext
2356 * on-demand when needed. Since updating the SID value is an SMP-sensitive
2359 * WARNING: This function may return -ESTALE, indicating that the caller
2360 * must retry the operation after re-acquiring the policy pointer!
2365 int rc; in ocontext_to_sid() local
2369 sid = smp_load_acquire(&c->sid[index]); in ocontext_to_sid()
2371 rc = sidtab_context_to_sid(sidtab, &c->context[index], &sid); in ocontext_to_sid()
2372 if (rc) in ocontext_to_sid()
2373 return rc; in ocontext_to_sid()
2379 smp_store_release(&c->sid[index], sid); in ocontext_to_sid()
2386 * security_port_sid - Obtain the SID for a port.
2397 int rc; in security_port_sid() local
2405 rc = 0; in security_port_sid()
2408 policydb = &policy->policydb; in security_port_sid()
2409 sidtab = policy->sidtab; in security_port_sid()
2411 c = policydb->ocontexts[OCON_PORT]; in security_port_sid()
2413 if (c->u.port.protocol == protocol && in security_port_sid()
2414 c->u.port.low_port <= port && in security_port_sid()
2415 c->u.port.high_port >= port) in security_port_sid()
2417 c = c->next; in security_port_sid()
2421 rc = ocontext_to_sid(sidtab, c, 0, out_sid); in security_port_sid()
2422 if (rc == -ESTALE) { in security_port_sid()
2426 if (rc) in security_port_sid()
2434 return rc; in security_port_sid()
2438 * security_ib_pkey_sid - Obtain the SID for a pkey.
2449 int rc; in security_ib_pkey_sid() local
2457 rc = 0; in security_ib_pkey_sid()
2460 policydb = &policy->policydb; in security_ib_pkey_sid()
2461 sidtab = policy->sidtab; in security_ib_pkey_sid()
2463 c = policydb->ocontexts[OCON_IBPKEY]; in security_ib_pkey_sid()
2465 if (c->u.ibpkey.low_pkey <= pkey_num && in security_ib_pkey_sid()
2466 c->u.ibpkey.high_pkey >= pkey_num && in security_ib_pkey_sid()
2467 c->u.ibpkey.subnet_prefix == subnet_prefix) in security_ib_pkey_sid()
2470 c = c->next; in security_ib_pkey_sid()
2474 rc = ocontext_to_sid(sidtab, c, 0, out_sid); in security_ib_pkey_sid()
2475 if (rc == -ESTALE) { in security_ib_pkey_sid()
2479 if (rc) in security_ib_pkey_sid()
2486 return rc; in security_ib_pkey_sid()
2490 * security_ib_endport_sid - Obtain the SID for a subnet management interface.
2491 * @dev_name: device name
2501 int rc; in security_ib_endport_sid() local
2509 rc = 0; in security_ib_endport_sid()
2512 policydb = &policy->policydb; in security_ib_endport_sid()
2513 sidtab = policy->sidtab; in security_ib_endport_sid()
2515 c = policydb->ocontexts[OCON_IBENDPORT]; in security_ib_endport_sid()
2517 if (c->u.ibendport.port == port_num && in security_ib_endport_sid()
2518 !strncmp(c->u.ibendport.dev_name, in security_ib_endport_sid()
2523 c = c->next; in security_ib_endport_sid()
2527 rc = ocontext_to_sid(sidtab, c, 0, out_sid); in security_ib_endport_sid()
2528 if (rc == -ESTALE) { in security_ib_endport_sid()
2532 if (rc) in security_ib_endport_sid()
2539 return rc; in security_ib_endport_sid()
2543 * security_netif_sid - Obtain the SID for a network interface.
2544 * @name: interface name
2547 int security_netif_sid(char *name, u32 *if_sid) in security_netif_sid() argument
2552 int rc; in security_netif_sid() local
2561 rc = 0; in security_netif_sid()
2564 policydb = &policy->policydb; in security_netif_sid()
2565 sidtab = policy->sidtab; in security_netif_sid()
2567 c = policydb->ocontexts[OCON_NETIF]; in security_netif_sid()
2569 if (strcmp(name, c->u.name) == 0) in security_netif_sid()
2571 c = c->next; in security_netif_sid()
2575 rc = ocontext_to_sid(sidtab, c, 0, if_sid); in security_netif_sid()
2576 if (rc == -ESTALE) { in security_netif_sid()
2580 if (rc) in security_netif_sid()
2587 return rc; in security_netif_sid()
2604 * security_node_sid - Obtain the SID for a node (host).
2618 int rc; in security_node_sid() local
2629 policydb = &policy->policydb; in security_node_sid()
2630 sidtab = policy->sidtab; in security_node_sid()
2636 rc = -EINVAL; in security_node_sid()
2642 c = policydb->ocontexts[OCON_NODE]; in security_node_sid()
2644 if (c->u.node.addr == (addr & c->u.node.mask)) in security_node_sid()
2646 c = c->next; in security_node_sid()
2652 rc = -EINVAL; in security_node_sid()
2655 c = policydb->ocontexts[OCON_NODE6]; in security_node_sid()
2657 if (match_ipv6_addrmask(addrp, c->u.node6.addr, in security_node_sid()
2658 c->u.node6.mask)) in security_node_sid()
2660 c = c->next; in security_node_sid()
2665 rc = 0; in security_node_sid()
2671 rc = ocontext_to_sid(sidtab, c, 0, out_sid); in security_node_sid()
2672 if (rc == -ESTALE) { in security_node_sid()
2676 if (rc) in security_node_sid()
2682 rc = 0; in security_node_sid()
2685 return rc; in security_node_sid()
2691 * security_get_user_sids - Obtain reachable SIDs for a user.
2718 int rc; in security_get_user_sids() local
2728 return -ENOMEM; in security_get_user_sids()
2734 policydb = &policy->policydb; in security_get_user_sids()
2735 sidtab = policy->sidtab; in security_get_user_sids()
2739 rc = -EINVAL; in security_get_user_sids()
2744 rc = -EINVAL; in security_get_user_sids()
2745 user = symtab_search(&policydb->p_users, username); in security_get_user_sids()
2749 usercon.user = user->value; in security_get_user_sids()
2751 ebitmap_for_each_positive_bit(&user->roles, rnode, i) { in security_get_user_sids()
2752 role = policydb->role_val_to_struct[i]; in security_get_user_sids()
2754 ebitmap_for_each_positive_bit(&role->types, tnode, j) { in security_get_user_sids()
2761 rc = sidtab_context_to_sid(sidtab, &usercon, &sid); in security_get_user_sids()
2762 if (rc == -ESTALE) { in security_get_user_sids()
2766 if (rc) in security_get_user_sids()
2771 rc = -ENOMEM; in security_get_user_sids()
2783 rc = 0; in security_get_user_sids()
2786 if (rc || !mynel) { in security_get_user_sids()
2788 return rc; in security_get_user_sids()
2791 rc = -ENOMEM; in security_get_user_sids()
2795 return rc; in security_get_user_sids()
2799 rc = avc_has_perm_noaudit(fromsid, mysids[i], in security_get_user_sids()
2803 if (!rc) in security_get_user_sids()
2814 * __security_genfs_sid - Helper to obtain a SID for a file in a filesystem
2825 * WARNING: This function may return -ESTALE, indicating that the caller
2826 * must retry the operation after re-acquiring the policy pointer!
2834 struct policydb *policydb = &policy->policydb; in __security_genfs_sid()
2835 struct sidtab *sidtab = policy->sidtab; in __security_genfs_sid()
2844 sclass = unmap_class(&policy->map, orig_sclass); in __security_genfs_sid()
2847 for (genfs = policydb->genfs; genfs; genfs = genfs->next) { in __security_genfs_sid()
2848 cmp = strcmp(fstype, genfs->fstype); in __security_genfs_sid()
2854 return -ENOENT; in __security_genfs_sid()
2856 for (c = genfs->head; c; c = c->next) { in __security_genfs_sid()
2857 size_t len = strlen(c->u.name); in __security_genfs_sid()
2858 if ((!c->v.sclass || sclass == c->v.sclass) && in __security_genfs_sid()
2859 (strncmp(c->u.name, path, len) == 0)) in __security_genfs_sid()
2864 return -ENOENT; in __security_genfs_sid()
2870 * security_genfs_sid - Obtain a SID for a file in a filesystem
2898 } while (retval == -ESTALE); in security_genfs_sid()
2913 * security_fs_use - Determine how to handle labeling for a filesystem.
2921 int rc; in security_fs_use() local
2924 const char *fstype = sb->s_type->name; in security_fs_use()
2927 sbsec->behavior = SECURITY_FS_USE_NONE; in security_fs_use()
2928 sbsec->sid = SECINITSID_UNLABELED; in security_fs_use()
2935 policydb = &policy->policydb; in security_fs_use()
2936 sidtab = policy->sidtab; in security_fs_use()
2938 c = policydb->ocontexts[OCON_FSUSE]; in security_fs_use()
2940 if (strcmp(fstype, c->u.name) == 0) in security_fs_use()
2942 c = c->next; in security_fs_use()
2946 sbsec->behavior = c->v.behavior; in security_fs_use()
2947 rc = ocontext_to_sid(sidtab, c, 0, &sbsec->sid); in security_fs_use()
2948 if (rc == -ESTALE) { in security_fs_use()
2952 if (rc) in security_fs_use()
2955 rc = __security_genfs_sid(policy, fstype, "/", in security_fs_use()
2956 SECCLASS_DIR, &sbsec->sid); in security_fs_use()
2957 if (rc == -ESTALE) { in security_fs_use()
2961 if (rc) { in security_fs_use()
2962 sbsec->behavior = SECURITY_FS_USE_NONE; in security_fs_use()
2963 rc = 0; in security_fs_use()
2965 sbsec->behavior = SECURITY_FS_USE_GENFS; in security_fs_use()
2971 return rc; in security_fs_use()
2979 int rc; in security_get_bools() local
2981 policydb = &policy->policydb; in security_get_bools()
2986 rc = 0; in security_get_bools()
2987 *len = policydb->p_bools.nprim; in security_get_bools()
2991 rc = -ENOMEM; in security_get_bools()
2996 rc = -ENOMEM; in security_get_bools()
3002 (*values)[i] = policydb->bool_val_to_struct[i]->state; in security_get_bools()
3004 rc = -ENOMEM; in security_get_bools()
3010 rc = 0; in security_get_bools()
3012 return rc; in security_get_bools()
3031 int rc; in security_set_bools() local
3035 return -EINVAL; in security_set_bools()
3037 oldpolicy = rcu_dereference_protected(state->policy, in security_set_bools()
3038 lockdep_is_held(&state->policy_mutex)); in security_set_bools()
3041 if (WARN_ON(len != oldpolicy->policydb.p_bools.nprim)) in security_set_bools()
3042 return -EINVAL; in security_set_bools()
3046 return -ENOMEM; in security_set_bools()
3052 rc = cond_policydb_dup(&newpolicy->policydb, &oldpolicy->policydb); in security_set_bools()
3053 if (rc) { in security_set_bools()
3055 return -ENOMEM; in security_set_bools()
3061 int old_state = newpolicy->policydb.bool_val_to_struct[i]->state; in security_set_bools()
3067 sym_name(&newpolicy->policydb, SYM_BOOLS, i), in security_set_bools()
3072 newpolicy->policydb.bool_val_to_struct[i]->state = new_state; in security_set_bools()
3076 /* Re-evaluate the conditional rules in the copy */ in security_set_bools()
3077 evaluate_cond_nodes(&newpolicy->policydb); in security_set_bools()
3080 newpolicy->latest_granting = oldpolicy->latest_granting + 1; in security_set_bools()
3081 seqno = newpolicy->latest_granting; in security_set_bools()
3084 rcu_assign_pointer(state->policy, newpolicy); in security_set_bools()
3103 int rc; in security_get_bool_value() local
3111 policydb = &policy->policydb; in security_get_bool_value()
3113 rc = -EFAULT; in security_get_bool_value()
3114 len = policydb->p_bools.nprim; in security_get_bool_value()
3118 rc = policydb->bool_val_to_struct[index]->state; in security_get_bool_value()
3121 return rc; in security_get_bool_value()
3127 int rc, *bvalues = NULL; in security_preserve_bools() local
3132 rc = security_get_bools(oldpolicy, &nbools, &bnames, &bvalues); in security_preserve_bools()
3133 if (rc) in security_preserve_bools()
3136 booldatum = symtab_search(&newpolicy->policydb.p_bools, in security_preserve_bools()
3139 booldatum->state = bvalues[i]; in security_preserve_bools()
3141 evaluate_cond_nodes(&newpolicy->policydb); in security_preserve_bools()
3150 return rc; in security_preserve_bools()
3154 * security_sid_mls_copy() - computes a new sid based on the given
3167 int rc; in security_sid_mls_copy() local
3175 rc = 0; in security_sid_mls_copy()
3180 policydb = &policy->policydb; in security_sid_mls_copy()
3181 sidtab = policy->sidtab; in security_sid_mls_copy()
3183 if (!policydb->mls_enabled) { in security_sid_mls_copy()
3188 rc = -EINVAL; in security_sid_mls_copy()
3196 rc = -EINVAL; in security_sid_mls_copy()
3204 newcon.user = context1->user; in security_sid_mls_copy()
3205 newcon.role = context1->role; in security_sid_mls_copy()
3206 newcon.type = context1->type; in security_sid_mls_copy()
3207 rc = mls_context_cpy(&newcon, context2); in security_sid_mls_copy()
3208 if (rc) in security_sid_mls_copy()
3213 rc = convert_context_handle_invalid_context(policydb, in security_sid_mls_copy()
3215 if (rc) { in security_sid_mls_copy()
3226 audit_log_n_untrustedstring(ab, s, len - 1); in security_sid_mls_copy()
3233 rc = sidtab_context_to_sid(sidtab, &newcon, new_sid); in security_sid_mls_copy()
3234 if (rc == -ESTALE) { in security_sid_mls_copy()
3242 return rc; in security_sid_mls_copy()
3246 * security_net_peersid_resolve - Compare and resolve two network peer SIDs
3259 * ------------------------------+-----------------+-----------------
3263 * multiple, inconsistent labels | -<errno> | SECSID_NULL
3273 int rc; in security_net_peersid_resolve() local
3299 policydb = &policy->policydb; in security_net_peersid_resolve()
3300 sidtab = policy->sidtab; in security_net_peersid_resolve()
3305 * security server was initialized and state->initialized was true. in security_net_peersid_resolve()
3307 if (!policydb->mls_enabled) { in security_net_peersid_resolve()
3308 rc = 0; in security_net_peersid_resolve()
3312 rc = -EINVAL; in security_net_peersid_resolve()
3319 rc = -EINVAL; in security_net_peersid_resolve()
3326 rc = (mls_context_cmp(nlbl_ctx, xfrm_ctx) ? 0 : -EACCES); in security_net_peersid_resolve()
3327 if (rc) in security_net_peersid_resolve()
3338 return rc; in security_net_peersid_resolve()
3344 char *name = k, **classes = args; in get_classes_callback() local
3345 u32 value = datum->value - 1; in get_classes_callback()
3347 classes[value] = kstrdup(name, GFP_ATOMIC); in get_classes_callback()
3349 return -ENOMEM; in get_classes_callback()
3358 int rc; in security_get_classes() local
3360 policydb = &policy->policydb; in security_get_classes()
3362 rc = -ENOMEM; in security_get_classes()
3363 *nclasses = policydb->p_classes.nprim; in security_get_classes()
3368 rc = hashtab_map(&policydb->p_classes.table, get_classes_callback, in security_get_classes()
3370 if (rc) { in security_get_classes()
3379 return rc; in security_get_classes()
3385 char *name = k, **perms = args; in get_permissions_callback() local
3386 u32 value = datum->value - 1; in get_permissions_callback()
3388 perms[value] = kstrdup(name, GFP_ATOMIC); in get_permissions_callback()
3390 return -ENOMEM; in get_permissions_callback()
3400 int rc; in security_get_permissions() local
3403 policydb = &policy->policydb; in security_get_permissions()
3405 rc = -EINVAL; in security_get_permissions()
3406 match = symtab_search(&policydb->p_classes, class); in security_get_permissions()
3413 rc = -ENOMEM; in security_get_permissions()
3414 *nperms = match->permissions.nprim; in security_get_permissions()
3419 if (match->comdatum) { in security_get_permissions()
3420 rc = hashtab_map(&match->comdatum->permissions.table, in security_get_permissions()
3422 if (rc) in security_get_permissions()
3426 rc = hashtab_map(&match->permissions.table, get_permissions_callback, in security_get_permissions()
3428 if (rc) in security_get_permissions()
3432 return rc; in security_get_permissions()
3438 return rc; in security_get_permissions()
3451 value = policy->policydb.reject_unknown; in security_get_reject_unknown()
3466 value = policy->policydb.allow_unknown; in security_get_allow_unknown()
3472 * security_policycap_supported - Check for a specific policy capability
3484 int rc; in security_policycap_supported() local
3491 rc = ebitmap_get_bit(&policy->policydb.policycaps, req_cap); in security_policycap_supported()
3494 return rc; in security_policycap_supported()
3507 context_destroy(&rule->au_ctxt); in selinux_audit_rule_free()
3523 int rc = 0; in selinux_audit_rule_init() local
3528 return -EOPNOTSUPP; in selinux_audit_rule_init()
3539 return -EINVAL; in selinux_audit_rule_init()
3545 /* we do not allow a range, indicated by the presence of '-' */ in selinux_audit_rule_init()
3546 if (strchr(rulestr, '-')) in selinux_audit_rule_init()
3547 return -EINVAL; in selinux_audit_rule_init()
3551 return -EINVAL; in selinux_audit_rule_init()
3556 return -ENOMEM; in selinux_audit_rule_init()
3557 context_init(&tmprule->au_ctxt); in selinux_audit_rule_init()
3560 policy = rcu_dereference(state->policy); in selinux_audit_rule_init()
3561 policydb = &policy->policydb; in selinux_audit_rule_init()
3562 tmprule->au_seqno = policy->latest_granting; in selinux_audit_rule_init()
3566 userdatum = symtab_search(&policydb->p_users, rulestr); in selinux_audit_rule_init()
3568 rc = -EINVAL; in selinux_audit_rule_init()
3571 tmprule->au_ctxt.user = userdatum->value; in selinux_audit_rule_init()
3575 roledatum = symtab_search(&policydb->p_roles, rulestr); in selinux_audit_rule_init()
3577 rc = -EINVAL; in selinux_audit_rule_init()
3580 tmprule->au_ctxt.role = roledatum->value; in selinux_audit_rule_init()
3584 typedatum = symtab_search(&policydb->p_types, rulestr); in selinux_audit_rule_init()
3586 rc = -EINVAL; in selinux_audit_rule_init()
3589 tmprule->au_ctxt.type = typedatum->value; in selinux_audit_rule_init()
3595 rc = mls_from_string(policydb, rulestr, &tmprule->au_ctxt, in selinux_audit_rule_init()
3597 if (rc) in selinux_audit_rule_init()
3610 return rc; in selinux_audit_rule_init()
3618 for (i = 0; i < rule->field_count; i++) { in selinux_audit_rule_known()
3619 struct audit_field *f = &rule->fields[i]; in selinux_audit_rule_known()
3620 switch (f->type) { in selinux_audit_rule_known()
3649 return -ENOENT; in selinux_audit_rule_match()
3657 policy = rcu_dereference(state->policy); in selinux_audit_rule_match()
3659 if (rule->au_seqno < policy->latest_granting) { in selinux_audit_rule_match()
3660 match = -ESTALE; in selinux_audit_rule_match()
3664 ctxt = sidtab_search(policy->sidtab, sid); in selinux_audit_rule_match()
3668 match = -ENOENT; in selinux_audit_rule_match()
3679 match = (ctxt->user == rule->au_ctxt.user); in selinux_audit_rule_match()
3682 match = (ctxt->user != rule->au_ctxt.user); in selinux_audit_rule_match()
3690 match = (ctxt->role == rule->au_ctxt.role); in selinux_audit_rule_match()
3693 match = (ctxt->role != rule->au_ctxt.role); in selinux_audit_rule_match()
3701 match = (ctxt->type == rule->au_ctxt.type); in selinux_audit_rule_match()
3704 match = (ctxt->type != rule->au_ctxt.type); in selinux_audit_rule_match()
3714 &ctxt->range.level[0] : &ctxt->range.level[1]); in selinux_audit_rule_match()
3717 match = mls_level_eq(&rule->au_ctxt.range.level[0], in selinux_audit_rule_match()
3721 match = !mls_level_eq(&rule->au_ctxt.range.level[0], in selinux_audit_rule_match()
3725 match = (mls_level_dom(&rule->au_ctxt.range.level[0], in selinux_audit_rule_match()
3727 !mls_level_eq(&rule->au_ctxt.range.level[0], in selinux_audit_rule_match()
3731 match = mls_level_dom(&rule->au_ctxt.range.level[0], in selinux_audit_rule_match()
3736 &rule->au_ctxt.range.level[0]) && in selinux_audit_rule_match()
3738 &rule->au_ctxt.range.level[0])); in selinux_audit_rule_match()
3742 &rule->au_ctxt.range.level[0]); in selinux_audit_rule_match()
3773 * security_netlbl_cache_add - Add an entry to the NetLabel cache
3791 secattr->cache = netlbl_secattr_cache_alloc(GFP_ATOMIC); in security_netlbl_cache_add()
3792 if (secattr->cache == NULL) { in security_netlbl_cache_add()
3798 secattr->cache->free = kfree; in security_netlbl_cache_add()
3799 secattr->cache->data = sid_cache; in security_netlbl_cache_add()
3800 secattr->flags |= NETLBL_SECATTR_CACHE; in security_netlbl_cache_add()
3804 * security_netlbl_secattr_to_sid - Convert a NetLabel secattr to a SELinux SID
3824 int rc; in security_netlbl_secattr_to_sid() local
3834 rc = 0; in security_netlbl_secattr_to_sid()
3837 policydb = &policy->policydb; in security_netlbl_secattr_to_sid()
3838 sidtab = policy->sidtab; in security_netlbl_secattr_to_sid()
3840 if (secattr->flags & NETLBL_SECATTR_CACHE) in security_netlbl_secattr_to_sid()
3841 *sid = *(u32 *)secattr->cache->data; in security_netlbl_secattr_to_sid()
3842 else if (secattr->flags & NETLBL_SECATTR_SECID) in security_netlbl_secattr_to_sid()
3843 *sid = secattr->attr.secid; in security_netlbl_secattr_to_sid()
3844 else if (secattr->flags & NETLBL_SECATTR_MLS_LVL) { in security_netlbl_secattr_to_sid()
3845 rc = -EIDRM; in security_netlbl_secattr_to_sid()
3851 ctx_new.user = ctx->user; in security_netlbl_secattr_to_sid()
3852 ctx_new.role = ctx->role; in security_netlbl_secattr_to_sid()
3853 ctx_new.type = ctx->type; in security_netlbl_secattr_to_sid()
3855 if (secattr->flags & NETLBL_SECATTR_MLS_CAT) { in security_netlbl_secattr_to_sid()
3856 rc = mls_import_netlbl_cat(policydb, &ctx_new, secattr); in security_netlbl_secattr_to_sid()
3857 if (rc) in security_netlbl_secattr_to_sid()
3860 rc = -EIDRM; in security_netlbl_secattr_to_sid()
3866 rc = sidtab_context_to_sid(sidtab, &ctx_new, sid); in security_netlbl_secattr_to_sid()
3868 if (rc == -ESTALE) { in security_netlbl_secattr_to_sid()
3872 if (rc) in security_netlbl_secattr_to_sid()
3881 return rc; in security_netlbl_secattr_to_sid()
3885 * security_netlbl_sid_to_secattr - Convert a SELinux SID to a NetLabel secattr
3898 int rc; in security_netlbl_sid_to_secattr() local
3906 policydb = &policy->policydb; in security_netlbl_sid_to_secattr()
3908 rc = -ENOENT; in security_netlbl_sid_to_secattr()
3909 ctx = sidtab_search(policy->sidtab, sid); in security_netlbl_sid_to_secattr()
3913 rc = -ENOMEM; in security_netlbl_sid_to_secattr()
3914 secattr->domain = kstrdup(sym_name(policydb, SYM_TYPES, ctx->type - 1), in security_netlbl_sid_to_secattr()
3916 if (secattr->domain == NULL) in security_netlbl_sid_to_secattr()
3919 secattr->attr.secid = sid; in security_netlbl_sid_to_secattr()
3920 secattr->flags |= NETLBL_SECATTR_DOMAIN_CPY | NETLBL_SECATTR_SECID; in security_netlbl_sid_to_secattr()
3922 rc = mls_export_netlbl_cat(policydb, ctx, secattr); in security_netlbl_sid_to_secattr()
3925 return rc; in security_netlbl_sid_to_secattr()
3930 * __security_read_policy - read the policy.
3939 int rc; in __security_read_policy() local
3945 rc = policydb_write(&policy->policydb, &fp); in __security_read_policy()
3946 if (rc) in __security_read_policy()
3947 return rc; in __security_read_policy()
3949 *len = (unsigned long)fp.data - (unsigned long)data; in __security_read_policy()
3954 * security_read_policy - read the policy.
3965 state->policy, lockdep_is_held(&state->policy_mutex)); in security_read_policy()
3967 return -EINVAL; in security_read_policy()
3969 *len = policy->policydb.len; in security_read_policy()
3972 return -ENOMEM; in security_read_policy()
3978 * security_read_state_kernel - read the policy.
3995 state->policy, lockdep_is_held(&state->policy_mutex)); in security_read_state_kernel()
3997 return -EINVAL; in security_read_state_kernel()
3999 *len = policy->policydb.len; in security_read_state_kernel()
4002 return -ENOMEM; in security_read_state_kernel()