1 2 /* Author : Stephen Smalley, <sds (at) epoch.ncsc.mil> */ 3 4 /* 5 * Updated: Joshua Brindle <jbrindle (at) tresys.com> 6 * Karl MacMillan <kmacmillan (at) tresys.com> 7 * Jason Tang <jtang (at) tresys.com> 8 * 9 * Module support 10 * 11 * Updated: Trusted Computer Solutions, Inc. <dgoeddel (at) trustedcs.com> 12 * 13 * Support for enhanced MLS infrastructure. 14 * 15 * Updated: Frank Mayer <mayerf (at) tresys.com> and Karl MacMillan <kmacmillan (at) tresys.com> 16 * 17 * Added conditional policy language extensions 18 * 19 * Updated: Red Hat, Inc. James Morris <jmorris (at) redhat.com> 20 * 21 * Fine-grained netlink support 22 * IPv6 support 23 * Code cleanup 24 * 25 * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 26 * Copyright (C) 2003 - 2004 Tresys Technology, LLC 27 * Copyright (C) 2003 - 2004 Red Hat, Inc. 28 * 29 * This library is free software; you can redistribute it and/or 30 * modify it under the terms of the GNU Lesser General Public 31 * License as published by the Free Software Foundation; either 32 * version 2.1 of the License, or (at your option) any later version. 33 * 34 * This library is distributed in the hope that it will be useful, 35 * but WITHOUT ANY WARRANTY; without even the implied warranty of 36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 37 * Lesser General Public License for more details. 38 * 39 * You should have received a copy of the GNU Lesser General Public 40 * License along with this library; if not, write to the Free Software 41 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 42 */ 43 44 /* FLASK */ 45 46 /* 47 * A policy database (policydb) specifies the 48 * configuration data for the security policy. 49 */ 50 51 #ifndef _SEPOL_POLICYDB_POLICYDB_H_ 52 #define _SEPOL_POLICYDB_POLICYDB_H_ 53 54 #include <stdio.h> 55 #include <stddef.h> 56 57 #include <sepol/policydb.h> 58 59 #include <sepol/policydb/flask_types.h> 60 #include <sepol/policydb/symtab.h> 61 #include <sepol/policydb/avtab.h> 62 #include <sepol/policydb/context.h> 63 #include <sepol/policydb/constraint.h> 64 #include <sepol/policydb/sidtab.h> 65 66 #define ERRMSG_LEN 1024 67 68 #define POLICYDB_SUCCESS 0 69 #define POLICYDB_ERROR -1 70 #define POLICYDB_UNSUPPORTED -2 71 72 /* 73 * A datum type is defined for each kind of symbol 74 * in the configuration data: individual permissions, 75 * common prefixes for access vectors, classes, 76 * users, roles, types, sensitivities, categories, etc. 77 */ 78 79 /* type set preserves data needed by modules such as *, ~ and attributes */ 80 typedef struct type_set { 81 ebitmap_t types; 82 ebitmap_t negset; 83 #define TYPE_STAR 1 84 #define TYPE_COMP 2 85 uint32_t flags; 86 } type_set_t; 87 88 typedef struct role_set { 89 ebitmap_t roles; 90 #define ROLE_STAR 1 91 #define ROLE_COMP 2 92 uint32_t flags; 93 } role_set_t; 94 95 /* Permission attributes */ 96 typedef struct perm_datum { 97 symtab_datum_t s; 98 } perm_datum_t; 99 100 /* Attributes of a common prefix for access vectors */ 101 typedef struct common_datum { 102 symtab_datum_t s; 103 symtab_t permissions; /* common permissions */ 104 } common_datum_t; 105 106 /* Class attributes */ 107 typedef struct class_datum { 108 symtab_datum_t s; 109 char *comkey; /* common name */ 110 common_datum_t *comdatum; /* common datum */ 111 symtab_t permissions; /* class-specific permission symbol table */ 112 constraint_node_t *constraints; /* constraints on class permissions */ 113 constraint_node_t *validatetrans; /* special transition rules */ 114 } class_datum_t; 115 116 /* Role attributes */ 117 typedef struct role_datum { 118 symtab_datum_t s; 119 ebitmap_t dominates; /* set of roles dominated by this role */ 120 type_set_t types; /* set of authorized types for role */ 121 ebitmap_t cache; /* This is an expanded set used for context validation during parsing */ 122 uint32_t bounds; /* bounds role, if exist */ 123 #define ROLE_ROLE 0 /* regular role in kernel policies */ 124 #define ROLE_ATTRIB 1 /* attribute */ 125 uint32_t flavor; 126 ebitmap_t roles; /* roles with this attribute */ 127 } role_datum_t; 128 129 typedef struct role_trans { 130 uint32_t role; /* current role */ 131 uint32_t type; /* program executable type, or new object type */ 132 uint32_t tclass; /* process class, or new object class */ 133 uint32_t new_role; /* new role */ 134 struct role_trans *next; 135 } role_trans_t; 136 137 typedef struct role_allow { 138 uint32_t role; /* current role */ 139 uint32_t new_role; /* new role */ 140 struct role_allow *next; 141 } role_allow_t; 142 143 /* filename_trans rules */ 144 typedef struct filename_trans { 145 uint32_t stype; 146 uint32_t ttype; 147 uint32_t tclass; 148 char *name; 149 uint32_t otype; 150 struct filename_trans *next; 151 } filename_trans_t; 152 153 /* Type attributes */ 154 typedef struct type_datum { 155 symtab_datum_t s; 156 uint32_t primary; /* primary name? can be set to primary value if below is TYPE_ */ 157 #define TYPE_TYPE 0 /* regular type or alias in kernel policies */ 158 #define TYPE_ATTRIB 1 /* attribute */ 159 #define TYPE_ALIAS 2 /* alias in modular policy */ 160 uint32_t flavor; 161 ebitmap_t types; /* types with this attribute */ 162 #define TYPE_FLAGS_PERMISSIVE 0x01 163 uint32_t flags; 164 uint32_t bounds; /* bounds type, if exist */ 165 } type_datum_t; 166 167 /* 168 * Properties of type_datum 169 * available on the policy version >= (MOD_)POLICYDB_VERSION_BOUNDARY 170 */ 171 #define TYPEDATUM_PROPERTY_PRIMARY 0x0001 172 #define TYPEDATUM_PROPERTY_ATTRIBUTE 0x0002 173 #define TYPEDATUM_PROPERTY_ALIAS 0x0004 /* userspace only */ 174 #define TYPEDATUM_PROPERTY_PERMISSIVE 0x0008 /* userspace only */ 175 176 /* User attributes */ 177 typedef struct user_datum { 178 symtab_datum_t s; 179 role_set_t roles; /* set of authorized roles for user */ 180 mls_semantic_range_t range; /* MLS range (min. - max.) for user */ 181 mls_semantic_level_t dfltlevel; /* default login MLS level for user */ 182 ebitmap_t cache; /* This is an expanded set used for context validation during parsing */ 183 mls_range_t exp_range; /* expanded range used for validation */ 184 mls_level_t exp_dfltlevel; /* expanded range used for validation */ 185 uint32_t bounds; /* bounds user, if exist */ 186 } user_datum_t; 187 188 /* Sensitivity attributes */ 189 typedef struct level_datum { 190 mls_level_t *level; /* sensitivity and associated categories */ 191 unsigned char isalias; /* is this sensitivity an alias for another? */ 192 unsigned char defined; 193 } level_datum_t; 194 195 /* Category attributes */ 196 typedef struct cat_datum { 197 symtab_datum_t s; 198 unsigned char isalias; /* is this category an alias for another? */ 199 } cat_datum_t; 200 201 typedef struct range_trans { 202 uint32_t source_type; 203 uint32_t target_type; 204 uint32_t target_class; 205 mls_range_t target_range; 206 struct range_trans *next; 207 } range_trans_t; 208 209 /* Boolean data type */ 210 typedef struct cond_bool_datum { 211 symtab_datum_t s; 212 int state; 213 #define COND_BOOL_FLAGS_TUNABLE 0x01 /* is this a tunable? */ 214 uint32_t flags; 215 } cond_bool_datum_t; 216 217 struct cond_node; 218 219 typedef struct cond_node cond_list_t; 220 struct cond_av_list; 221 222 typedef struct class_perm_node { 223 uint32_t class; 224 uint32_t data; /* permissions or new type */ 225 struct class_perm_node *next; 226 } class_perm_node_t; 227 228 typedef struct avrule { 229 /* these typedefs are almost exactly the same as those in avtab.h - they are 230 * here because of the need to include neverallow and dontaudit messages */ 231 #define AVRULE_ALLOWED 1 232 #define AVRULE_AUDITALLOW 2 233 #define AVRULE_AUDITDENY 4 234 #define AVRULE_DONTAUDIT 8 235 #define AVRULE_NEVERALLOW 128 236 #define AVRULE_AV (AVRULE_ALLOWED | AVRULE_AUDITALLOW | AVRULE_AUDITDENY | AVRULE_DONTAUDIT | AVRULE_NEVERALLOW) 237 #define AVRULE_TRANSITION 16 238 #define AVRULE_MEMBER 32 239 #define AVRULE_CHANGE 64 240 #define AVRULE_TYPE (AVRULE_TRANSITION | AVRULE_MEMBER | AVRULE_CHANGE) 241 uint32_t specified; 242 #define RULE_SELF 1 243 uint32_t flags; 244 type_set_t stypes; 245 type_set_t ttypes; 246 class_perm_node_t *perms; 247 unsigned long line; /* line number from policy.conf where 248 * this rule originated */ 249 struct avrule *next; 250 } avrule_t; 251 252 typedef struct role_trans_rule { 253 role_set_t roles; /* current role */ 254 type_set_t types; /* program executable type, or new object type */ 255 ebitmap_t classes; /* process class, or new object class */ 256 uint32_t new_role; /* new role */ 257 struct role_trans_rule *next; 258 } role_trans_rule_t; 259 260 typedef struct role_allow_rule { 261 role_set_t roles; /* current role */ 262 role_set_t new_roles; /* new roles */ 263 struct role_allow_rule *next; 264 } role_allow_rule_t; 265 266 typedef struct filename_trans_rule { 267 type_set_t stypes; 268 type_set_t ttypes; 269 uint32_t tclass; 270 char *name; 271 uint32_t otype; /* new type */ 272 struct filename_trans_rule *next; 273 } filename_trans_rule_t; 274 275 typedef struct range_trans_rule { 276 type_set_t stypes; 277 type_set_t ttypes; 278 ebitmap_t tclasses; 279 mls_semantic_range_t trange; 280 struct range_trans_rule *next; 281 } range_trans_rule_t; 282 283 /* 284 * The configuration data includes security contexts for 285 * initial SIDs, unlabeled file systems, TCP and UDP port numbers, 286 * network interfaces, and nodes. This structure stores the 287 * relevant data for one such entry. Entries of the same kind 288 * (e.g. all initial SIDs) are linked together into a list. 289 */ 290 typedef struct ocontext { 291 union { 292 char *name; /* name of initial SID, fs, netif, fstype, path */ 293 struct { 294 uint8_t protocol; 295 uint16_t low_port; 296 uint16_t high_port; 297 } port; /* TCP or UDP port information */ 298 struct { 299 uint32_t addr; /* network order */ 300 uint32_t mask; /* network order */ 301 } node; /* node information */ 302 struct { 303 uint32_t addr[4]; /* network order */ 304 uint32_t mask[4]; /* network order */ 305 } node6; /* IPv6 node information */ 306 uint32_t device; 307 uint16_t pirq; 308 struct { 309 uint32_t low_iomem; 310 uint32_t high_iomem; 311 } iomem; 312 struct { 313 uint32_t low_ioport; 314 uint32_t high_ioport; 315 } ioport; 316 } u; 317 union { 318 uint32_t sclass; /* security class for genfs */ 319 uint32_t behavior; /* labeling behavior for fs_use */ 320 } v; 321 context_struct_t context[2]; /* security context(s) */ 322 sepol_security_id_t sid[2]; /* SID(s) */ 323 struct ocontext *next; 324 } ocontext_t; 325 326 typedef struct genfs { 327 char *fstype; 328 struct ocontext *head; 329 struct genfs *next; 330 } genfs_t; 331 332 /* symbol table array indices */ 333 #define SYM_COMMONS 0 334 #define SYM_CLASSES 1 335 #define SYM_ROLES 2 336 #define SYM_TYPES 3 337 #define SYM_USERS 4 338 #define SYM_BOOLS 5 339 #define SYM_LEVELS 6 340 #define SYM_CATS 7 341 #define SYM_NUM 8 342 343 /* object context array indices */ 344 #define OCON_ISID 0 /* initial SIDs */ 345 #define OCON_FS 1 /* unlabeled file systems */ 346 #define OCON_PORT 2 /* TCP and UDP port numbers */ 347 #define OCON_NETIF 3 /* network interfaces */ 348 #define OCON_NODE 4 /* nodes */ 349 #define OCON_FSUSE 5 /* fs_use */ 350 #define OCON_NODE6 6 /* IPv6 nodes */ 351 #define OCON_GENFS 7 /* needed for ocontext_supported */ 352 353 /* object context array indices for Xen */ 354 #define OCON_XEN_ISID 0 /* initial SIDs */ 355 #define OCON_XEN_PIRQ 1 /* physical irqs */ 356 #define OCON_XEN_IOPORT 2 /* io ports */ 357 #define OCON_XEN_IOMEM 3 /* io memory */ 358 #define OCON_XEN_PCIDEVICE 4 /* pci devices */ 359 360 /* OCON_NUM needs to be the largest index in any platform's ocontext array */ 361 #define OCON_NUM 7 362 363 /* section: module information */ 364 365 /* scope_index_t holds all of the symbols that are in scope in a 366 * particular situation. The bitmaps are indices (and thus must 367 * subtract one) into the global policydb->scope array. */ 368 typedef struct scope_index { 369 ebitmap_t scope[SYM_NUM]; 370 #define p_classes_scope scope[SYM_CLASSES] 371 #define p_roles_scope scope[SYM_ROLES] 372 #define p_types_scope scope[SYM_TYPES] 373 #define p_users_scope scope[SYM_USERS] 374 #define p_bools_scope scope[SYM_BOOLS] 375 #define p_sens_scope scope[SYM_LEVELS] 376 #define p_cat_scope scope[SYM_CATS] 377 378 /* this array maps from class->value to the permissions within 379 * scope. if bit (perm->value - 1) is set in map 380 * class_perms_map[class->value - 1] then that permission is 381 * enabled for this class within this decl. */ 382 ebitmap_t *class_perms_map; 383 /* total number of classes in class_perms_map array */ 384 uint32_t class_perms_len; 385 } scope_index_t; 386 387 /* a list of declarations for a particular avrule_decl */ 388 389 /* These two structs declare a block of policy that has TE and RBAC 390 * statements and declarations. The root block (the global policy) 391 * can never have an ELSE branch. */ 392 typedef struct avrule_decl { 393 uint32_t decl_id; 394 uint32_t enabled; /* whether this block is enabled */ 395 396 cond_list_t *cond_list; 397 avrule_t *avrules; 398 role_trans_rule_t *role_tr_rules; 399 role_allow_rule_t *role_allow_rules; 400 range_trans_rule_t *range_tr_rules; 401 scope_index_t required; /* symbols needed to activate this block */ 402 scope_index_t declared; /* symbols declared within this block */ 403 404 /* type transition rules with a 'name' component */ 405 filename_trans_rule_t *filename_trans_rules; 406 407 /* for additive statements (type attribute, roles, and users) */ 408 symtab_t symtab[SYM_NUM]; 409 410 /* In a linked module this will contain the name of the module 411 * from which this avrule_decl originated. */ 412 char *module_name; 413 414 struct avrule_decl *next; 415 } avrule_decl_t; 416 417 typedef struct avrule_block { 418 avrule_decl_t *branch_list; 419 avrule_decl_t *enabled; /* pointer to which branch is enabled. this is 420 used in linking and never written to disk */ 421 #define AVRULE_OPTIONAL 1 422 uint32_t flags; /* any flags for this block, currently just optional */ 423 struct avrule_block *next; 424 } avrule_block_t; 425 426 /* Every identifier has its own scope datum. The datum describes if 427 * the item is to be included into the final policy during 428 * expansion. */ 429 typedef struct scope_datum { 430 /* Required for this decl */ 431 #define SCOPE_REQ 1 432 /* Declared in this decl */ 433 #define SCOPE_DECL 2 434 uint32_t scope; 435 uint32_t *decl_ids; 436 uint32_t decl_ids_len; 437 /* decl_ids is a list of avrule_decl's that declare/require 438 * this symbol. If scope==SCOPE_DECL then this is a list of 439 * declarations. If the symbol may only be declared once 440 * (types, bools) then decl_ids_len will be exactly 1. For 441 * implicitly declared things (roles, users) then decl_ids_len 442 * will be at least 1. */ 443 } scope_datum_t; 444 445 /* The policy database */ 446 typedef struct policydb { 447 #define POLICY_KERN SEPOL_POLICY_KERN 448 #define POLICY_BASE SEPOL_POLICY_BASE 449 #define POLICY_MOD SEPOL_POLICY_MOD 450 uint32_t policy_type; 451 char *name; 452 char *version; 453 int target_platform; 454 455 /* Set when the policydb is modified such that writing is unsupported */ 456 int unsupported_format; 457 458 /* Whether this policydb is mls, should always be set */ 459 int mls; 460 461 /* symbol tables */ 462 symtab_t symtab[SYM_NUM]; 463 #define p_commons symtab[SYM_COMMONS] 464 #define p_classes symtab[SYM_CLASSES] 465 #define p_roles symtab[SYM_ROLES] 466 #define p_types symtab[SYM_TYPES] 467 #define p_users symtab[SYM_USERS] 468 #define p_bools symtab[SYM_BOOLS] 469 #define p_levels symtab[SYM_LEVELS] 470 #define p_cats symtab[SYM_CATS] 471 472 /* symbol names indexed by (value - 1) */ 473 char **sym_val_to_name[SYM_NUM]; 474 #define p_common_val_to_name sym_val_to_name[SYM_COMMONS] 475 #define p_class_val_to_name sym_val_to_name[SYM_CLASSES] 476 #define p_role_val_to_name sym_val_to_name[SYM_ROLES] 477 #define p_type_val_to_name sym_val_to_name[SYM_TYPES] 478 #define p_user_val_to_name sym_val_to_name[SYM_USERS] 479 #define p_bool_val_to_name sym_val_to_name[SYM_BOOLS] 480 #define p_sens_val_to_name sym_val_to_name[SYM_LEVELS] 481 #define p_cat_val_to_name sym_val_to_name[SYM_CATS] 482 483 /* class, role, and user attributes indexed by (value - 1) */ 484 class_datum_t **class_val_to_struct; 485 role_datum_t **role_val_to_struct; 486 user_datum_t **user_val_to_struct; 487 type_datum_t **type_val_to_struct; 488 489 /* module stuff section -- used in parsing and for modules */ 490 491 /* keep track of the scope for every identifier. these are 492 * hash tables, where the key is the identifier name and value 493 * a scope_datum_t. as a convenience, one may use the 494 * p_*_macros (cf. struct scope_index_t declaration). */ 495 symtab_t scope[SYM_NUM]; 496 497 /* module rule storage */ 498 avrule_block_t *global; 499 /* avrule_decl index used for link/expand */ 500 avrule_decl_t **decl_val_to_struct; 501 502 /* compiled storage of rules - use for the kernel policy */ 503 504 /* type enforcement access vectors and transitions */ 505 avtab_t te_avtab; 506 507 /* bools indexed by (value - 1) */ 508 cond_bool_datum_t **bool_val_to_struct; 509 /* type enforcement conditional access vectors and transitions */ 510 avtab_t te_cond_avtab; 511 /* linked list indexing te_cond_avtab by conditional */ 512 cond_list_t *cond_list; 513 514 /* role transitions */ 515 role_trans_t *role_tr; 516 517 /* type transition rules with a 'name' component */ 518 filename_trans_t *filename_trans; 519 520 /* role allows */ 521 role_allow_t *role_allow; 522 523 /* security contexts of initial SIDs, unlabeled file systems, 524 TCP or UDP port numbers, network interfaces and nodes */ 525 ocontext_t *ocontexts[OCON_NUM]; 526 527 /* security contexts for files in filesystems that cannot support 528 a persistent label mapping or use another 529 fixed labeling behavior. */ 530 genfs_t *genfs; 531 532 /* range transitions */ 533 range_trans_t *range_tr; 534 535 ebitmap_t *type_attr_map; 536 537 ebitmap_t *attr_type_map; /* not saved in the binary policy */ 538 539 ebitmap_t policycaps; 540 541 /* this bitmap is referenced by type NOT the typical type-1 used in other 542 bitmaps. Someday the 0 bit may be used for global permissive */ 543 ebitmap_t permissive_map; 544 545 unsigned policyvers; 546 547 unsigned handle_unknown; 548 } policydb_t; 549 550 struct sepol_policydb { 551 struct policydb p; 552 }; 553 554 extern int policydb_init(policydb_t * p); 555 556 extern int policydb_from_image(sepol_handle_t * handle, 557 void *data, size_t len, policydb_t * policydb); 558 559 extern int policydb_to_image(sepol_handle_t * handle, 560 policydb_t * policydb, void **newdata, 561 size_t * newlen); 562 563 extern int policydb_index_classes(policydb_t * p); 564 565 extern int policydb_index_bools(policydb_t * p); 566 567 extern int policydb_index_others(sepol_handle_t * handle, policydb_t * p, 568 unsigned int verbose); 569 570 extern int policydb_reindex_users(policydb_t * p); 571 572 extern void policydb_destroy(policydb_t * p); 573 574 extern int policydb_load_isids(policydb_t * p, sidtab_t * s); 575 576 /* Deprecated */ 577 extern int policydb_context_isvalid(const policydb_t * p, 578 const context_struct_t * c); 579 580 extern void symtabs_destroy(symtab_t * symtab); 581 extern int scope_destroy(hashtab_key_t key, hashtab_datum_t datum, void *p); 582 typedef void (*hashtab_destroy_func_t) (hashtab_key_t k, hashtab_datum_t d, 583 void *args); 584 extern hashtab_destroy_func_t get_symtab_destroy_func(int sym_num); 585 586 extern void class_perm_node_init(class_perm_node_t * x); 587 extern void type_set_init(type_set_t * x); 588 extern void type_set_destroy(type_set_t * x); 589 extern int type_set_cpy(type_set_t * dst, type_set_t * src); 590 extern int type_set_or_eq(type_set_t * dst, type_set_t * other); 591 extern void role_set_init(role_set_t * x); 592 extern void role_set_destroy(role_set_t * x); 593 extern void avrule_init(avrule_t * x); 594 extern void avrule_destroy(avrule_t * x); 595 extern void avrule_list_destroy(avrule_t * x); 596 extern void role_trans_rule_init(role_trans_rule_t * x); 597 extern void role_trans_rule_list_destroy(role_trans_rule_t * x); 598 extern void filename_trans_rule_init(filename_trans_rule_t * x); 599 extern void filename_trans_rule_list_destroy(filename_trans_rule_t * x); 600 601 extern void role_datum_init(role_datum_t * x); 602 extern void role_datum_destroy(role_datum_t * x); 603 extern void role_allow_rule_init(role_allow_rule_t * x); 604 extern void role_allow_rule_destroy(role_allow_rule_t * x); 605 extern void role_allow_rule_list_destroy(role_allow_rule_t * x); 606 extern void range_trans_rule_init(range_trans_rule_t *x); 607 extern void range_trans_rule_destroy(range_trans_rule_t *x); 608 extern void range_trans_rule_list_destroy(range_trans_rule_t *x); 609 extern void type_datum_init(type_datum_t * x); 610 extern void type_datum_destroy(type_datum_t * x); 611 extern void user_datum_init(user_datum_t * x); 612 extern void user_datum_destroy(user_datum_t * x); 613 extern void level_datum_init(level_datum_t * x); 614 extern void level_datum_destroy(level_datum_t * x); 615 extern void cat_datum_init(cat_datum_t * x); 616 extern void cat_datum_destroy(cat_datum_t * x); 617 618 extern int check_assertions(sepol_handle_t * handle, 619 policydb_t * p, avrule_t * avrules); 620 621 extern int symtab_insert(policydb_t * x, uint32_t sym, 622 hashtab_key_t key, hashtab_datum_t datum, 623 uint32_t scope, uint32_t avrule_decl_id, 624 uint32_t * value); 625 626 /* A policy "file" may be a memory region referenced by a (data, len) pair 627 or a file referenced by a FILE pointer. */ 628 typedef struct policy_file { 629 #define PF_USE_MEMORY 0 630 #define PF_USE_STDIO 1 631 #define PF_LEN 2 /* total up length in len field */ 632 unsigned type; 633 char *data; 634 size_t len; 635 size_t size; 636 FILE *fp; 637 struct sepol_handle *handle; 638 } policy_file_t; 639 640 struct sepol_policy_file { 641 struct policy_file pf; 642 }; 643 644 extern void policy_file_init(policy_file_t * x); 645 646 extern int policydb_read(policydb_t * p, struct policy_file *fp, 647 unsigned int verbose); 648 extern int avrule_read_list(policydb_t * p, avrule_t ** avrules, 649 struct policy_file *fp); 650 651 extern int policydb_write(struct policydb *p, struct policy_file *pf); 652 extern int policydb_set_target_platform(policydb_t *p, int platform); 653 654 #define PERM_SYMTAB_SIZE 32 655 656 /* Identify specific policy version changes */ 657 #define POLICYDB_VERSION_BASE 15 658 #define POLICYDB_VERSION_BOOL 16 659 #define POLICYDB_VERSION_IPV6 17 660 #define POLICYDB_VERSION_NLCLASS 18 661 #define POLICYDB_VERSION_VALIDATETRANS 19 662 #define POLICYDB_VERSION_MLS 19 663 #define POLICYDB_VERSION_AVTAB 20 664 #define POLICYDB_VERSION_RANGETRANS 21 665 #define POLICYDB_VERSION_POLCAP 22 666 #define POLICYDB_VERSION_PERMISSIVE 23 667 #define POLICYDB_VERSION_BOUNDARY 24 668 #define POLICYDB_VERSION_FILENAME_TRANS 25 669 #define POLICYDB_VERSION_ROLETRANS 26 670 671 /* Range of policy versions we understand*/ 672 #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE 673 #define POLICYDB_VERSION_MAX POLICYDB_VERSION_ROLETRANS 674 675 /* Module versions and specific changes*/ 676 #define MOD_POLICYDB_VERSION_BASE 4 677 #define MOD_POLICYDB_VERSION_VALIDATETRANS 5 678 #define MOD_POLICYDB_VERSION_MLS 5 679 #define MOD_POLICYDB_VERSION_RANGETRANS 6 680 #define MOD_POLICYDB_VERSION_MLS_USERS 6 681 #define MOD_POLICYDB_VERSION_POLCAP 7 682 #define MOD_POLICYDB_VERSION_PERMISSIVE 8 683 #define MOD_POLICYDB_VERSION_BOUNDARY 9 684 #define MOD_POLICYDB_VERSION_BOUNDARY_ALIAS 10 685 #define MOD_POLICYDB_VERSION_FILENAME_TRANS 11 686 #define MOD_POLICYDB_VERSION_ROLETRANS 12 687 #define MOD_POLICYDB_VERSION_ROLEATTRIB 13 688 #define MOD_POLICYDB_VERSION_TUNABLE_SEP 14 689 690 #define MOD_POLICYDB_VERSION_MIN MOD_POLICYDB_VERSION_BASE 691 #define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_TUNABLE_SEP 692 693 #define POLICYDB_CONFIG_MLS 1 694 695 /* macros to check policy feature */ 696 697 /* TODO: add other features here */ 698 699 #define policydb_has_boundary_feature(p) \ 700 (((p)->policy_type == POLICY_KERN \ 701 && p->policyvers >= POLICYDB_VERSION_BOUNDARY) || \ 702 ((p)->policy_type != POLICY_KERN \ 703 && p->policyvers >= MOD_POLICYDB_VERSION_BOUNDARY)) 704 705 /* the config flags related to unknown classes/perms are bits 2 and 3 */ 706 #define DENY_UNKNOWN SEPOL_DENY_UNKNOWN 707 #define REJECT_UNKNOWN SEPOL_REJECT_UNKNOWN 708 #define ALLOW_UNKNOWN SEPOL_ALLOW_UNKNOWN 709 710 #define POLICYDB_CONFIG_UNKNOWN_MASK (DENY_UNKNOWN | REJECT_UNKNOWN | ALLOW_UNKNOWN) 711 712 #define OBJECT_R "object_r" 713 #define OBJECT_R_VAL 1 714 715 #define POLICYDB_MAGIC SELINUX_MAGIC 716 #define POLICYDB_STRING "SE Linux" 717 #define POLICYDB_XEN_STRING "XenFlask" 718 #define POLICYDB_STRING_MAX_LENGTH 32 719 #define POLICYDB_MOD_MAGIC SELINUX_MOD_MAGIC 720 #define POLICYDB_MOD_STRING "SE Linux Module" 721 #define SEPOL_TARGET_SELINUX 0 722 #define SEPOL_TARGET_XEN 1 723 724 725 #endif /* _POLICYDB_H_ */ 726 727 /* FLASK */ 728