| 1 |
/* Author : Stephen Smalley, <[email protected]> */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Updated: Joshua Brindle <[email protected]> |
| 5 |
* Karl MacMillan <[email protected]> |
| 6 |
* Jason Tang <[email protected]> |
| 7 |
* |
| 8 |
* Module support |
| 9 |
* |
| 10 |
* Updated: Trusted Computer Solutions, Inc. <[email protected]> |
| 11 |
* |
| 12 |
* Support for enhanced MLS infrastructure. |
| 13 |
* |
| 14 |
* Updated: Frank Mayer <[email protected]> and Karl MacMillan <[email protected]> |
| 15 |
* |
| 16 |
* Added conditional policy language extensions |
| 17 |
* |
| 18 |
* Updated: Red Hat, Inc. James Morris <[email protected]> |
| 19 |
* |
| 20 |
* Fine-grained netlink support |
| 21 |
* IPv6 support |
| 22 |
* Code cleanup |
| 23 |
* |
| 24 |
* Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. |
| 25 |
* Copyright (C) 2003 - 2004 Tresys Technology, LLC |
| 26 |
* Copyright (C) 2003 - 2004 Red Hat, Inc. |
| 27 |
* Copyright (C) 2017 Mellanox Techonolgies 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 |
#ifdef __cplusplus |
| 73 |
extern "C" { |
| 74 |
#endif |
| 75 |
|
| 76 |
#define IB_DEVICE_NAME_MAX 64 |
| 77 |
|
| 78 |
/* |
| 79 |
* A datum type is defined for each kind of symbol |
| 80 |
* in the configuration data: individual permissions, |
| 81 |
* common prefixes for access vectors, classes, |
| 82 |
* users, roles, types, sensitivities, categories, etc. |
| 83 |
*/ |
| 84 |
|
| 85 |
/* type set preserves data needed by modules such as *, ~ and attributes */ |
| 86 |
typedef struct type_set { |
| 87 |
ebitmap_t types; |
| 88 |
ebitmap_t negset; |
| 89 |
#define TYPE_STAR 1 |
| 90 |
#define TYPE_COMP 2 |
| 91 |
uint32_t flags; |
| 92 |
} type_set_t; |
| 93 |
|
| 94 |
typedef struct role_set { |
| 95 |
ebitmap_t roles; |
| 96 |
#define ROLE_STAR 1 |
| 97 |
#define ROLE_COMP 2 |
| 98 |
uint32_t flags; |
| 99 |
} role_set_t; |
| 100 |
|
| 101 |
/* Permission attributes */ |
| 102 |
typedef struct perm_datum { |
| 103 |
symtab_datum_t s; |
| 104 |
} perm_datum_t; |
| 105 |
|
| 106 |
/* Attributes of a common prefix for access vectors */ |
| 107 |
typedef struct common_datum { |
| 108 |
symtab_datum_t s; |
| 109 |
symtab_t permissions; /* common permissions */ |
| 110 |
} common_datum_t; |
| 111 |
|
| 112 |
/* Class attributes */ |
| 113 |
typedef struct class_datum { |
| 114 |
symtab_datum_t s; |
| 115 |
char *comkey; /* common name */ |
| 116 |
common_datum_t *comdatum; /* common datum */ |
| 117 |
symtab_t permissions; /* class-specific permission symbol table */ |
| 118 |
constraint_node_t *constraints; /* constraints on class permissions */ |
| 119 |
constraint_node_t *validatetrans; /* special transition rules */ |
| 120 |
/* Options how a new object user and role should be decided */ |
| 121 |
#define DEFAULT_SOURCE 1 |
| 122 |
#define DEFAULT_TARGET 2 |
| 123 |
char default_user; |
| 124 |
char default_role; |
| 125 |
char default_type; |
| 126 |
/* Options how a new object range should be decided */ |
| 127 |
#define DEFAULT_SOURCE_LOW 1 |
| 128 |
#define DEFAULT_SOURCE_HIGH 2 |
| 129 |
#define DEFAULT_SOURCE_LOW_HIGH 3 |
| 130 |
#define DEFAULT_TARGET_LOW 4 |
| 131 |
#define DEFAULT_TARGET_HIGH 5 |
| 132 |
#define DEFAULT_TARGET_LOW_HIGH 6 |
| 133 |
#define DEFAULT_GLBLUB 7 |
| 134 |
char default_range; |
| 135 |
} class_datum_t; |
| 136 |
|
| 137 |
/* Role attributes */ |
| 138 |
typedef struct role_datum { |
| 139 |
symtab_datum_t s; |
| 140 |
ebitmap_t dominates; /* set of roles dominated by this role */ |
| 141 |
type_set_t types; /* set of authorized types for role */ |
| 142 |
ebitmap_t cache; /* This is an expanded set used for context validation during parsing */ |
| 143 |
uint32_t bounds; /* bounds role, if exist */ |
| 144 |
#define ROLE_ROLE 0 /* regular role in kernel policies */ |
| 145 |
#define ROLE_ATTRIB 1 /* attribute */ |
| 146 |
uint32_t flavor; |
| 147 |
ebitmap_t roles; /* roles with this attribute */ |
| 148 |
} role_datum_t; |
| 149 |
|
| 150 |
typedef struct role_trans { |
| 151 |
uint32_t role; /* current role */ |
| 152 |
uint32_t type; /* program executable type, or new object type */ |
| 153 |
uint32_t tclass; /* process class, or new object class */ |
| 154 |
uint32_t new_role; /* new role */ |
| 155 |
struct role_trans *next; |
| 156 |
} role_trans_t; |
| 157 |
|
| 158 |
typedef struct role_allow { |
| 159 |
uint32_t role; /* current role */ |
| 160 |
uint32_t new_role; /* new role */ |
| 161 |
struct role_allow *next; |
| 162 |
} role_allow_t; |
| 163 |
|
| 164 |
/* filename_trans rules */ |
| 165 |
typedef struct filename_trans_key { |
| 166 |
uint32_t ttype; |
| 167 |
uint32_t tclass; |
| 168 |
char *name; |
| 169 |
} filename_trans_key_t; |
| 170 |
|
| 171 |
typedef struct filename_trans_datum { |
| 172 |
ebitmap_t stypes; |
| 173 |
uint32_t otype; |
| 174 |
struct filename_trans_datum *next; |
| 175 |
} filename_trans_datum_t; |
| 176 |
|
| 177 |
/* Type attributes */ |
| 178 |
typedef struct type_datum { |
| 179 |
symtab_datum_t s; |
| 180 |
uint32_t primary; /* primary name? can be set to primary value if below is TYPE_ */ |
| 181 |
#define TYPE_TYPE 0 /* regular type or alias in kernel policies */ |
| 182 |
#define TYPE_ATTRIB 1 /* attribute */ |
| 183 |
#define TYPE_ALIAS 2 /* alias in modular policy */ |
| 184 |
uint32_t flavor; |
| 185 |
ebitmap_t types; /* types with this attribute */ |
| 186 |
#define TYPE_FLAGS_PERMISSIVE (1 << 0) |
| 187 |
#define TYPE_FLAGS_EXPAND_ATTR_TRUE (1 << 1) |
| 188 |
#define TYPE_FLAGS_EXPAND_ATTR_FALSE (1 << 2) |
| 189 |
#define TYPE_FLAGS_EXPAND_ATTR (TYPE_FLAGS_EXPAND_ATTR_TRUE | \ |
| 190 |
TYPE_FLAGS_EXPAND_ATTR_FALSE) |
| 191 |
#define TYPE_FLAGS_NEVERAUDIT (1 << 3) |
| 192 |
uint32_t flags; |
| 193 |
uint32_t bounds; /* bounds type, if exist */ |
| 194 |
} type_datum_t; |
| 195 |
|
| 196 |
/* |
| 197 |
* Properties of type_datum |
| 198 |
* available on the policy version >= (MOD_)POLICYDB_VERSION_BOUNDARY |
| 199 |
*/ |
| 200 |
#define TYPEDATUM_PROPERTY_PRIMARY 0x0001 |
| 201 |
#define TYPEDATUM_PROPERTY_ATTRIBUTE 0x0002 |
| 202 |
#define TYPEDATUM_PROPERTY_ALIAS 0x0004 /* userspace only */ |
| 203 |
#define TYPEDATUM_PROPERTY_PERMISSIVE 0x0008 /* userspace only */ |
| 204 |
#define TYPEDATUM_PROPERTY_NEVERAUDIT 0x0010 /* userspace only */ |
| 205 |
|
| 206 |
/* User attributes */ |
| 207 |
typedef struct user_datum { |
| 208 |
symtab_datum_t s; |
| 209 |
role_set_t roles; /* set of authorized roles for user */ |
| 210 |
mls_semantic_range_t range; /* MLS range (min. - max.) for user */ |
| 211 |
mls_semantic_level_t dfltlevel; /* default login MLS level for user */ |
| 212 |
ebitmap_t cache; /* This is an expanded set used for context validation during parsing */ |
| 213 |
mls_range_t exp_range; /* expanded range used for validation */ |
| 214 |
mls_level_t exp_dfltlevel; /* expanded range used for validation */ |
| 215 |
uint32_t bounds; /* bounds user, if exist */ |
| 216 |
} user_datum_t; |
| 217 |
|
| 218 |
/* Sensitivity attributes */ |
| 219 |
typedef struct level_datum { |
| 220 |
mls_level_t *level; /* sensitivity and associated categories */ |
| 221 |
unsigned char isalias; /* is this sensitivity an alias for another? */ |
| 222 |
unsigned char notdefined; /* Only set to non-zero in checkpolicy */ |
| 223 |
} level_datum_t; |
| 224 |
|
| 225 |
/* Category attributes */ |
| 226 |
typedef struct cat_datum { |
| 227 |
symtab_datum_t s; |
| 228 |
unsigned char isalias; /* is this category an alias for another? */ |
| 229 |
} cat_datum_t; |
| 230 |
|
| 231 |
typedef struct range_trans { |
| 232 |
uint32_t source_type; |
| 233 |
uint32_t target_type; |
| 234 |
uint32_t target_class; |
| 235 |
} range_trans_t; |
| 236 |
|
| 237 |
/* Boolean data type */ |
| 238 |
typedef struct cond_bool_datum { |
| 239 |
symtab_datum_t s; |
| 240 |
int state; |
| 241 |
#define COND_BOOL_FLAGS_TUNABLE 0x01 /* is this a tunable? */ |
| 242 |
uint32_t flags; |
| 243 |
} cond_bool_datum_t; |
| 244 |
|
| 245 |
struct cond_node; |
| 246 |
|
| 247 |
typedef struct cond_node cond_list_t; |
| 248 |
struct cond_av_list; |
| 249 |
|
| 250 |
typedef struct class_perm_node { |
| 251 |
uint32_t tclass; |
| 252 |
uint32_t data; /* permissions or new type */ |
| 253 |
struct class_perm_node *next; |
| 254 |
} class_perm_node_t; |
| 255 |
|
| 256 |
#define xperm_test(x, p) (UINT32_C(1) & ((p)[(x) >> 5] >> ((x) & 0x1f))) |
| 257 |
#define xperm_set(x, p) ((p)[(x) >> 5] |= (UINT32_C(1) << ((x) & 0x1f))) |
| 258 |
#define xperm_clear(x, p) ((p)[(x) >> 5] &= ~(UINT32_C(1) << ((x) & 0x1f))) |
| 259 |
#define EXTENDED_PERMS_LEN 8 |
| 260 |
|
| 261 |
typedef struct av_extended_perms { |
| 262 |
#define AVRULE_XPERMS_IOCTLFUNCTION 0x01 |
| 263 |
#define AVRULE_XPERMS_IOCTLDRIVER 0x02 |
| 264 |
#define AVRULE_XPERMS_NLMSG 0x03 |
| 265 |
uint8_t specified; |
| 266 |
uint8_t driver; |
| 267 |
/* 256 bits of permissions */ |
| 268 |
uint32_t perms[EXTENDED_PERMS_LEN]; |
| 269 |
} av_extended_perms_t; |
| 270 |
|
| 271 |
typedef struct avrule { |
| 272 |
/* these typedefs are almost exactly the same as those in avtab.h - they are |
| 273 |
* here because of the need to include neverallow and dontaudit messages */ |
| 274 |
#define AVRULE_ALLOWED AVTAB_ALLOWED |
| 275 |
#define AVRULE_AUDITALLOW AVTAB_AUDITALLOW |
| 276 |
#define AVRULE_AUDITDENY AVTAB_AUDITDENY |
| 277 |
#define AVRULE_DONTAUDIT 0x0008 |
| 278 |
#define AVRULE_NEVERALLOW AVTAB_NEVERALLOW |
| 279 |
#define AVRULE_AV (AVRULE_ALLOWED | AVRULE_AUDITALLOW | AVRULE_AUDITDENY | AVRULE_DONTAUDIT | AVRULE_NEVERALLOW) |
| 280 |
#define AVRULE_TRANSITION AVTAB_TRANSITION |
| 281 |
#define AVRULE_MEMBER AVTAB_MEMBER |
| 282 |
#define AVRULE_CHANGE AVTAB_CHANGE |
| 283 |
#define AVRULE_TYPE (AVRULE_TRANSITION | AVRULE_MEMBER | AVRULE_CHANGE) |
| 284 |
#define AVRULE_XPERMS_ALLOWED AVTAB_XPERMS_ALLOWED |
| 285 |
#define AVRULE_XPERMS_AUDITALLOW AVTAB_XPERMS_AUDITALLOW |
| 286 |
#define AVRULE_XPERMS_DONTAUDIT AVTAB_XPERMS_DONTAUDIT |
| 287 |
#define AVRULE_XPERMS_NEVERALLOW AVTAB_XPERMS_NEVERALLOW |
| 288 |
#define AVRULE_XPERMS (AVRULE_XPERMS_ALLOWED | AVRULE_XPERMS_AUDITALLOW | \ |
| 289 |
AVRULE_XPERMS_DONTAUDIT | AVRULE_XPERMS_NEVERALLOW) |
| 290 |
uint32_t specified; |
| 291 |
#define RULE_SELF (1U << 0) |
| 292 |
#define RULE_NOTSELF (1U << 1) |
| 293 |
uint32_t flags; |
| 294 |
type_set_t stypes; |
| 295 |
type_set_t ttypes; |
| 296 |
class_perm_node_t *perms; |
| 297 |
av_extended_perms_t *xperms; |
| 298 |
unsigned long line; /* line number from policy.conf where |
| 299 |
* this rule originated */ |
| 300 |
/* source file name and line number (e.g. .te file) */ |
| 301 |
char *source_filename; |
| 302 |
unsigned long source_line; |
| 303 |
struct avrule *next; |
| 304 |
} avrule_t; |
| 305 |
|
| 306 |
typedef struct role_trans_rule { |
| 307 |
role_set_t roles; /* current role */ |
| 308 |
type_set_t types; /* program executable type, or new object type */ |
| 309 |
ebitmap_t classes; /* process class, or new object class */ |
| 310 |
uint32_t new_role; /* new role */ |
| 311 |
struct role_trans_rule *next; |
| 312 |
} role_trans_rule_t; |
| 313 |
|
| 314 |
typedef struct role_allow_rule { |
| 315 |
role_set_t roles; /* current role */ |
| 316 |
role_set_t new_roles; /* new roles */ |
| 317 |
struct role_allow_rule *next; |
| 318 |
} role_allow_rule_t; |
| 319 |
|
| 320 |
typedef struct filename_trans_rule { |
| 321 |
uint32_t flags; /* may have RULE_SELF set */ |
| 322 |
type_set_t stypes; |
| 323 |
type_set_t ttypes; |
| 324 |
uint32_t tclass; |
| 325 |
char *name; |
| 326 |
uint32_t otype; /* new type */ |
| 327 |
struct filename_trans_rule *next; |
| 328 |
} filename_trans_rule_t; |
| 329 |
|
| 330 |
typedef struct range_trans_rule { |
| 331 |
type_set_t stypes; |
| 332 |
type_set_t ttypes; |
| 333 |
ebitmap_t tclasses; |
| 334 |
mls_semantic_range_t trange; |
| 335 |
struct range_trans_rule *next; |
| 336 |
} range_trans_rule_t; |
| 337 |
|
| 338 |
/* |
| 339 |
* The configuration data includes security contexts for |
| 340 |
* initial SIDs, unlabeled file systems, TCP and UDP port numbers, |
| 341 |
* network interfaces, and nodes. This structure stores the |
| 342 |
* relevant data for one such entry. Entries of the same kind |
| 343 |
* (e.g. all initial SIDs) are linked together into a list. |
| 344 |
*/ |
| 345 |
typedef struct ocontext { |
| 346 |
union { |
| 347 |
char *name; /* name of initial SID, fs, netif, fstype, path */ |
| 348 |
struct { |
| 349 |
uint8_t protocol; |
| 350 |
uint16_t low_port; |
| 351 |
uint16_t high_port; |
| 352 |
} port; /* TCP or UDP port information */ |
| 353 |
struct { |
| 354 |
uint32_t addr; /* network order */ |
| 355 |
uint32_t mask; /* network order */ |
| 356 |
} node; /* node information */ |
| 357 |
struct { |
| 358 |
uint32_t addr[4]; /* network order */ |
| 359 |
uint32_t mask[4]; /* network order */ |
| 360 |
} node6; /* IPv6 node information */ |
| 361 |
uint32_t device; |
| 362 |
uint16_t pirq; |
| 363 |
struct { |
| 364 |
uint64_t low_iomem; |
| 365 |
uint64_t high_iomem; |
| 366 |
} iomem; |
| 367 |
struct { |
| 368 |
uint32_t low_ioport; |
| 369 |
uint32_t high_ioport; |
| 370 |
} ioport; |
| 371 |
struct { |
| 372 |
uint64_t subnet_prefix; |
| 373 |
uint16_t low_pkey; |
| 374 |
uint16_t high_pkey; |
| 375 |
} ibpkey; |
| 376 |
struct { |
| 377 |
char *dev_name; |
| 378 |
uint8_t port; |
| 379 |
} ibendport; |
| 380 |
} u; |
| 381 |
union { |
| 382 |
uint32_t sclass; /* security class for genfs */ |
| 383 |
uint32_t behavior; /* labeling behavior for fs_use */ |
| 384 |
} v; |
| 385 |
context_struct_t context[2]; /* security context(s) */ |
| 386 |
sepol_security_id_t sid[2]; /* SID(s) */ |
| 387 |
struct ocontext *next; |
| 388 |
} ocontext_t; |
| 389 |
|
| 390 |
typedef struct genfs { |
| 391 |
char *fstype; |
| 392 |
struct ocontext *head; |
| 393 |
struct genfs *next; |
| 394 |
} genfs_t; |
| 395 |
|
| 396 |
/* symbol table array indices */ |
| 397 |
#define SYM_COMMONS 0 |
| 398 |
#define SYM_CLASSES 1 |
| 399 |
#define SYM_ROLES 2 |
| 400 |
#define SYM_TYPES 3 |
| 401 |
#define SYM_USERS 4 |
| 402 |
#define SYM_BOOLS 5 |
| 403 |
#define SYM_LEVELS 6 |
| 404 |
#define SYM_CATS 7 |
| 405 |
#define SYM_NUM 8 |
| 406 |
|
| 407 |
/* object context array indices */ |
| 408 |
#define OCON_ISID 0 /* initial SIDs */ |
| 409 |
#define OCON_FS 1 /* unlabeled file systems */ |
| 410 |
#define OCON_PORT 2 /* TCP and UDP port numbers */ |
| 411 |
#define OCON_NETIF 3 /* network interfaces */ |
| 412 |
#define OCON_NODE 4 /* nodes */ |
| 413 |
#define OCON_FSUSE 5 /* fs_use */ |
| 414 |
#define OCON_NODE6 6 /* IPv6 nodes */ |
| 415 |
#define OCON_IBPKEY 7 /* Infiniband PKEY */ |
| 416 |
#define OCON_IBENDPORT 8 /* Infiniband End Port */ |
| 417 |
|
| 418 |
/* object context array indices for Xen */ |
| 419 |
#define OCON_XEN_ISID 0 /* initial SIDs */ |
| 420 |
#define OCON_XEN_PIRQ 1 /* physical irqs */ |
| 421 |
#define OCON_XEN_IOPORT 2 /* io ports */ |
| 422 |
#define OCON_XEN_IOMEM 3 /* io memory */ |
| 423 |
#define OCON_XEN_PCIDEVICE 4 /* pci devices */ |
| 424 |
#define OCON_XEN_DEVICETREE 5 /* device tree node */ |
| 425 |
|
| 426 |
/* OCON_NUM needs to be the largest index in any platform's ocontext array */ |
| 427 |
#define OCON_NUM 9 |
| 428 |
|
| 429 |
/* section: module information */ |
| 430 |
|
| 431 |
/* scope_index_t holds all of the symbols that are in scope in a |
| 432 |
* particular situation. The bitmaps are indices (and thus must |
| 433 |
* subtract one) into the global policydb->scope array. */ |
| 434 |
typedef struct scope_index { |
| 435 |
ebitmap_t scope[SYM_NUM]; |
| 436 |
#define p_classes_scope scope[SYM_CLASSES] |
| 437 |
#define p_roles_scope scope[SYM_ROLES] |
| 438 |
#define p_types_scope scope[SYM_TYPES] |
| 439 |
#define p_users_scope scope[SYM_USERS] |
| 440 |
#define p_bools_scope scope[SYM_BOOLS] |
| 441 |
#define p_sens_scope scope[SYM_LEVELS] |
| 442 |
#define p_cat_scope scope[SYM_CATS] |
| 443 |
|
| 444 |
/* this array maps from class->value to the permissions within |
| 445 |
* scope. if bit (perm->value - 1) is set in map |
| 446 |
* class_perms_map[class->value - 1] then that permission is |
| 447 |
* enabled for this class within this decl. */ |
| 448 |
ebitmap_t *class_perms_map; |
| 449 |
/* total number of classes in class_perms_map array */ |
| 450 |
uint32_t class_perms_len; |
| 451 |
} scope_index_t; |
| 452 |
|
| 453 |
/* a list of declarations for a particular avrule_decl */ |
| 454 |
|
| 455 |
/* These two structs declare a block of policy that has TE and RBAC |
| 456 |
* statements and declarations. The root block (the global policy) |
| 457 |
* can never have an ELSE branch. */ |
| 458 |
typedef struct avrule_decl { |
| 459 |
uint32_t decl_id; |
| 460 |
uint32_t enabled; /* whether this block is enabled */ |
| 461 |
|
| 462 |
cond_list_t *cond_list; |
| 463 |
avrule_t *avrules; |
| 464 |
role_trans_rule_t *role_tr_rules; |
| 465 |
role_allow_rule_t *role_allow_rules; |
| 466 |
range_trans_rule_t *range_tr_rules; |
| 467 |
scope_index_t required; /* symbols needed to activate this block */ |
| 468 |
scope_index_t declared; /* symbols declared within this block */ |
| 469 |
|
| 470 |
/* type transition rules with a 'name' component */ |
| 471 |
filename_trans_rule_t *filename_trans_rules; |
| 472 |
|
| 473 |
/* for additive statements (type attribute, roles, and users) */ |
| 474 |
symtab_t symtab[SYM_NUM]; |
| 475 |
|
| 476 |
/* In a linked module this will contain the name of the module |
| 477 |
* from which this avrule_decl originated. */ |
| 478 |
char *module_name; |
| 479 |
|
| 480 |
struct avrule_decl *next; |
| 481 |
} avrule_decl_t; |
| 482 |
|
| 483 |
typedef struct avrule_block { |
| 484 |
avrule_decl_t *branch_list; |
| 485 |
avrule_decl_t *enabled; /* pointer to which branch is enabled. this is |
| 486 |
used in linking and never written to disk */ |
| 487 |
#define AVRULE_OPTIONAL 1 |
| 488 |
uint32_t flags; /* any flags for this block, currently just optional */ |
| 489 |
struct avrule_block *next; |
| 490 |
} avrule_block_t; |
| 491 |
|
| 492 |
/* Every identifier has its own scope datum. The datum describes if |
| 493 |
* the item is to be included into the final policy during |
| 494 |
* expansion. */ |
| 495 |
typedef struct scope_datum { |
| 496 |
/* Required for this decl */ |
| 497 |
#define SCOPE_REQ 1 |
| 498 |
/* Declared in this decl */ |
| 499 |
#define SCOPE_DECL 2 |
| 500 |
uint32_t scope; |
| 501 |
uint32_t *decl_ids; |
| 502 |
uint32_t decl_ids_len; |
| 503 |
/* decl_ids is a list of avrule_decl's that declare/require |
| 504 |
* this symbol. If scope==SCOPE_DECL then this is a list of |
| 505 |
* declarations. If the symbol may only be declared once |
| 506 |
* (types, bools) then decl_ids_len will be exactly 1. For |
| 507 |
* implicitly declared things (roles, users) then decl_ids_len |
| 508 |
* will be at least 1. */ |
| 509 |
} scope_datum_t; |
| 510 |
|
| 511 |
/* The policy database */ |
| 512 |
typedef struct policydb { |
| 513 |
#define POLICY_KERN SEPOL_POLICY_KERN |
| 514 |
#define POLICY_BASE SEPOL_POLICY_BASE |
| 515 |
#define POLICY_MOD SEPOL_POLICY_MOD |
| 516 |
uint32_t policy_type; |
| 517 |
char *name; |
| 518 |
char *version; |
| 519 |
int target_platform; |
| 520 |
|
| 521 |
/* Set when the policydb is modified such that writing is unsupported */ |
| 522 |
int unsupported_format; |
| 523 |
|
| 524 |
/* Whether this policydb is mls, should always be set */ |
| 525 |
int mls; |
| 526 |
|
| 527 |
/* symbol tables */ |
| 528 |
symtab_t symtab[SYM_NUM]; |
| 529 |
#define p_commons symtab[SYM_COMMONS] |
| 530 |
#define p_classes symtab[SYM_CLASSES] |
| 531 |
#define p_roles symtab[SYM_ROLES] |
| 532 |
#define p_types symtab[SYM_TYPES] |
| 533 |
#define p_users symtab[SYM_USERS] |
| 534 |
#define p_bools symtab[SYM_BOOLS] |
| 535 |
#define p_levels symtab[SYM_LEVELS] |
| 536 |
#define p_cats symtab[SYM_CATS] |
| 537 |
|
| 538 |
/* symbol names indexed by (value - 1) */ |
| 539 |
char **sym_val_to_name[SYM_NUM]; |
| 540 |
#define p_common_val_to_name sym_val_to_name[SYM_COMMONS] |
| 541 |
#define p_class_val_to_name sym_val_to_name[SYM_CLASSES] |
| 542 |
#define p_role_val_to_name sym_val_to_name[SYM_ROLES] |
| 543 |
#define p_type_val_to_name sym_val_to_name[SYM_TYPES] |
| 544 |
#define p_user_val_to_name sym_val_to_name[SYM_USERS] |
| 545 |
#define p_bool_val_to_name sym_val_to_name[SYM_BOOLS] |
| 546 |
#define p_sens_val_to_name sym_val_to_name[SYM_LEVELS] |
| 547 |
#define p_cat_val_to_name sym_val_to_name[SYM_CATS] |
| 548 |
|
| 549 |
/* class, role, and user attributes indexed by (value - 1) */ |
| 550 |
class_datum_t **class_val_to_struct; |
| 551 |
role_datum_t **role_val_to_struct; |
| 552 |
user_datum_t **user_val_to_struct; |
| 553 |
type_datum_t **type_val_to_struct; |
| 554 |
|
| 555 |
/* module stuff section -- used in parsing and for modules */ |
| 556 |
|
| 557 |
/* keep track of the scope for every identifier. these are |
| 558 |
* hash tables, where the key is the identifier name and value |
| 559 |
* a scope_datum_t. as a convenience, one may use the |
| 560 |
* p_*_macros (cf. struct scope_index_t declaration). */ |
| 561 |
symtab_t scope[SYM_NUM]; |
| 562 |
|
| 563 |
/* module rule storage */ |
| 564 |
avrule_block_t *global; |
| 565 |
/* avrule_decl index used for link/expand */ |
| 566 |
avrule_decl_t **decl_val_to_struct; |
| 567 |
|
| 568 |
/* compiled storage of rules - use for the kernel policy */ |
| 569 |
|
| 570 |
/* type enforcement access vectors and transitions */ |
| 571 |
avtab_t te_avtab; |
| 572 |
|
| 573 |
/* bools indexed by (value - 1) */ |
| 574 |
cond_bool_datum_t **bool_val_to_struct; |
| 575 |
/* type enforcement conditional access vectors and transitions */ |
| 576 |
avtab_t te_cond_avtab; |
| 577 |
/* linked list indexing te_cond_avtab by conditional */ |
| 578 |
cond_list_t *cond_list; |
| 579 |
|
| 580 |
/* role transitions */ |
| 581 |
role_trans_t *role_tr; |
| 582 |
|
| 583 |
/* role allows */ |
| 584 |
role_allow_t *role_allow; |
| 585 |
|
| 586 |
/* security contexts of initial SIDs, unlabeled file systems, |
| 587 |
TCP or UDP port numbers, network interfaces and nodes */ |
| 588 |
ocontext_t *ocontexts[OCON_NUM]; |
| 589 |
|
| 590 |
/* security contexts for files in filesystems that cannot support |
| 591 |
a persistent label mapping or use another |
| 592 |
fixed labeling behavior. */ |
| 593 |
genfs_t *genfs; |
| 594 |
|
| 595 |
/* range transitions table (range_trans_key -> mls_range) */ |
| 596 |
hashtab_t range_tr; |
| 597 |
|
| 598 |
/* file transitions with the last path component */ |
| 599 |
hashtab_t filename_trans; |
| 600 |
uint32_t filename_trans_count; |
| 601 |
|
| 602 |
ebitmap_t *type_attr_map; |
| 603 |
|
| 604 |
ebitmap_t *attr_type_map; /* not saved in the binary policy */ |
| 605 |
|
| 606 |
ebitmap_t policycaps; |
| 607 |
|
| 608 |
/* this bitmap is referenced by type NOT the typical type-1 used in other |
| 609 |
bitmaps. Someday the 0 bit may be used for global permissive */ |
| 610 |
ebitmap_t permissive_map; |
| 611 |
|
| 612 |
/* |
| 613 |
* This bitmap is referenced by type NOT the typical type-1 used in |
| 614 |
* other bitmaps. Someday the 0 bit may be used for global |
| 615 |
* neveraudit. |
| 616 |
*/ |
| 617 |
ebitmap_t neveraudit_map; |
| 618 |
|
| 619 |
unsigned policyvers; |
| 620 |
|
| 621 |
unsigned handle_unknown; |
| 622 |
|
| 623 |
sepol_security_class_t process_class; |
| 624 |
sepol_security_class_t dir_class; |
| 625 |
sepol_access_vector_t process_trans; |
| 626 |
sepol_access_vector_t process_trans_dyntrans; |
| 627 |
|
| 628 |
/* avrules whose line markes will be printed. Defaults to neverallow and |
| 629 |
neverallowxperm */ |
| 630 |
uint32_t line_marker_avrules; |
| 631 |
} policydb_t; |
| 632 |
|
| 633 |
struct sepol_policydb { |
| 634 |
struct policydb p; |
| 635 |
}; |
| 636 |
|
| 637 |
extern int policydb_init(policydb_t * p); |
| 638 |
|
| 639 |
extern int policydb_from_image(sepol_handle_t * handle, |
| 640 |
void *data, size_t len, policydb_t * policydb); |
| 641 |
|
| 642 |
extern int policydb_to_image(sepol_handle_t * handle, |
| 643 |
policydb_t * policydb, void **newdata, |
| 644 |
size_t * newlen); |
| 645 |
|
| 646 |
extern int policydb_index_classes(policydb_t * p); |
| 647 |
|
| 648 |
extern int policydb_index_bools(policydb_t * p); |
| 649 |
|
| 650 |
extern int policydb_index_others(sepol_handle_t * handle, policydb_t * p, |
| 651 |
unsigned int verbose); |
| 652 |
|
| 653 |
extern int policydb_role_cache(hashtab_key_t key, |
| 654 |
hashtab_datum_t datum, |
| 655 |
void *arg); |
| 656 |
|
| 657 |
extern int policydb_user_cache(hashtab_key_t key, |
| 658 |
hashtab_datum_t datum, |
| 659 |
void *arg); |
| 660 |
|
| 661 |
extern int policydb_reindex_users(policydb_t * p); |
| 662 |
|
| 663 |
extern int policydb_optimize(policydb_t * p); |
| 664 |
|
| 665 |
extern void policydb_destroy(policydb_t * p); |
| 666 |
|
| 667 |
extern int policydb_load_isids(policydb_t * p, sidtab_t * s); |
| 668 |
|
| 669 |
extern int policydb_sort_ocontexts(policydb_t *p); |
| 670 |
|
| 671 |
extern int policydb_filetrans_insert(policydb_t *p, uint32_t stype, |
| 672 |
uint32_t ttype, uint32_t tclass, |
| 673 |
const char *name, char **name_alloc, |
| 674 |
uint32_t otype, uint32_t *present_otype); |
| 675 |
|
| 676 |
/* Deprecated */ |
| 677 |
extern int policydb_context_isvalid(const policydb_t * p, |
| 678 |
const context_struct_t * c); |
| 679 |
|
| 680 |
extern void symtabs_destroy(symtab_t * symtab); |
| 681 |
extern int scope_destroy(hashtab_key_t key, hashtab_datum_t datum, void *p); |
| 682 |
|
| 683 |
extern void class_perm_node_init(class_perm_node_t * x); |
| 684 |
extern void type_set_init(type_set_t * x); |
| 685 |
extern void type_set_destroy(type_set_t * x); |
| 686 |
extern int type_set_cpy(type_set_t * dst, const type_set_t * src); |
| 687 |
extern int type_set_or_eq(type_set_t * dst, const type_set_t * other); |
| 688 |
extern void role_set_init(role_set_t * x); |
| 689 |
extern void role_set_destroy(role_set_t * x); |
| 690 |
extern void avrule_init(avrule_t * x); |
| 691 |
extern void avrule_destroy(avrule_t * x); |
| 692 |
extern void avrule_list_destroy(avrule_t * x); |
| 693 |
extern void role_trans_rule_init(role_trans_rule_t * x); |
| 694 |
extern void role_trans_rule_list_destroy(role_trans_rule_t * x); |
| 695 |
extern void filename_trans_rule_init(filename_trans_rule_t * x); |
| 696 |
extern void filename_trans_rule_list_destroy(filename_trans_rule_t * x); |
| 697 |
|
| 698 |
extern void role_datum_init(role_datum_t * x); |
| 699 |
extern void role_datum_destroy(role_datum_t * x); |
| 700 |
extern void role_allow_rule_init(role_allow_rule_t * x); |
| 701 |
extern void role_allow_rule_destroy(role_allow_rule_t * x); |
| 702 |
extern void role_allow_rule_list_destroy(role_allow_rule_t * x); |
| 703 |
extern void range_trans_rule_init(range_trans_rule_t *x); |
| 704 |
extern void range_trans_rule_destroy(range_trans_rule_t *x); |
| 705 |
extern void range_trans_rule_list_destroy(range_trans_rule_t *x); |
| 706 |
extern void type_datum_init(type_datum_t * x); |
| 707 |
extern void type_datum_destroy(type_datum_t * x); |
| 708 |
extern void user_datum_init(user_datum_t * x); |
| 709 |
extern void user_datum_destroy(user_datum_t * x); |
| 710 |
extern void level_datum_init(level_datum_t * x); |
| 711 |
extern void level_datum_destroy(level_datum_t * x); |
| 712 |
extern void cat_datum_init(cat_datum_t * x); |
| 713 |
extern void cat_datum_destroy(cat_datum_t * x); |
| 714 |
extern int check_assertion(policydb_t *p, const avrule_t *avrule); |
| 715 |
extern int check_assertions(sepol_handle_t * handle, |
| 716 |
policydb_t * p, const avrule_t * avrules); |
| 717 |
|
| 718 |
extern int symtab_insert(policydb_t * x, uint32_t sym, |
| 719 |
hashtab_key_t key, hashtab_datum_t datum, |
| 720 |
uint32_t scope, uint32_t avrule_decl_id, |
| 721 |
uint32_t * value); |
| 722 |
|
| 723 |
/* A policy "file" may be a memory region referenced by a (data, len) pair |
| 724 |
or a file referenced by a FILE pointer. */ |
| 725 |
typedef struct policy_file { |
| 726 |
#define PF_USE_MEMORY 0 |
| 727 |
#define PF_USE_STDIO 1 |
| 728 |
#define PF_LEN 2 /* total up length in len field */ |
| 729 |
unsigned type; |
| 730 |
char *data; |
| 731 |
size_t len; |
| 732 |
size_t size; |
| 733 |
FILE *fp; |
| 734 |
struct sepol_handle *handle; |
| 735 |
} policy_file_t; |
| 736 |
|
| 737 |
struct sepol_policy_file { |
| 738 |
struct policy_file pf; |
| 739 |
}; |
| 740 |
|
| 741 |
extern void policy_file_init(policy_file_t * x); |
| 742 |
|
| 743 |
extern int policydb_read(policydb_t * p, struct policy_file *fp, |
| 744 |
unsigned int verbose); |
| 745 |
extern int avrule_read_list(policydb_t * p, avrule_t ** avrules, |
| 746 |
struct policy_file *fp); |
| 747 |
|
| 748 |
extern int policydb_write(struct policydb *p, struct policy_file *pf); |
| 749 |
extern int policydb_set_target_platform(policydb_t *p, int platform); |
| 750 |
|
| 751 |
#define PERM_SYMTAB_SIZE 32 |
| 752 |
|
| 753 |
/* Identify specific policy version changes */ |
| 754 |
#define POLICYDB_VERSION_BASE 15 |
| 755 |
#define POLICYDB_VERSION_BOOL 16 |
| 756 |
#define POLICYDB_VERSION_IPV6 17 |
| 757 |
#define POLICYDB_VERSION_NLCLASS 18 |
| 758 |
#define POLICYDB_VERSION_VALIDATETRANS 19 |
| 759 |
#define POLICYDB_VERSION_MLS 19 |
| 760 |
#define POLICYDB_VERSION_AVTAB 20 |
| 761 |
#define POLICYDB_VERSION_RANGETRANS 21 |
| 762 |
#define POLICYDB_VERSION_POLCAP 22 |
| 763 |
#define POLICYDB_VERSION_PERMISSIVE 23 |
| 764 |
#define POLICYDB_VERSION_BOUNDARY 24 |
| 765 |
#define POLICYDB_VERSION_FILENAME_TRANS 25 |
| 766 |
#define POLICYDB_VERSION_ROLETRANS 26 |
| 767 |
#define POLICYDB_VERSION_NEW_OBJECT_DEFAULTS 27 |
| 768 |
#define POLICYDB_VERSION_DEFAULT_TYPE 28 |
| 769 |
#define POLICYDB_VERSION_CONSTRAINT_NAMES 29 |
| 770 |
#define POLICYDB_VERSION_XEN_DEVICETREE 30 /* Xen-specific */ |
| 771 |
#define POLICYDB_VERSION_XPERMS_IOCTL 30 /* Linux-specific */ |
| 772 |
#define POLICYDB_VERSION_INFINIBAND 31 /* Linux-specific */ |
| 773 |
#define POLICYDB_VERSION_GLBLUB 32 |
| 774 |
#define POLICYDB_VERSION_COMP_FTRANS 33 /* compressed filename transitions */ |
| 775 |
#define POLICYDB_VERSION_COND_XPERMS 34 /* extended permissions in conditional policies */ |
| 776 |
#define POLICYDB_VERSION_NEVERAUDIT 35 /* neveraudit domains */ |
| 777 |
|
| 778 |
/* Range of policy versions we understand*/ |
| 779 |
#define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE |
| 780 |
#define POLICYDB_VERSION_MAX POLICYDB_VERSION_NEVERAUDIT |
| 781 |
|
| 782 |
/* Module versions and specific changes*/ |
| 783 |
#define MOD_POLICYDB_VERSION_BASE 4 |
| 784 |
#define MOD_POLICYDB_VERSION_VALIDATETRANS 5 |
| 785 |
#define MOD_POLICYDB_VERSION_MLS 5 |
| 786 |
#define MOD_POLICYDB_VERSION_RANGETRANS 6 |
| 787 |
#define MOD_POLICYDB_VERSION_MLS_USERS 6 |
| 788 |
#define MOD_POLICYDB_VERSION_POLCAP 7 |
| 789 |
#define MOD_POLICYDB_VERSION_PERMISSIVE 8 |
| 790 |
#define MOD_POLICYDB_VERSION_BOUNDARY 9 |
| 791 |
#define MOD_POLICYDB_VERSION_BOUNDARY_ALIAS 10 |
| 792 |
#define MOD_POLICYDB_VERSION_FILENAME_TRANS 11 |
| 793 |
#define MOD_POLICYDB_VERSION_ROLETRANS 12 |
| 794 |
#define MOD_POLICYDB_VERSION_ROLEATTRIB 13 |
| 795 |
#define MOD_POLICYDB_VERSION_TUNABLE_SEP 14 |
| 796 |
#define MOD_POLICYDB_VERSION_NEW_OBJECT_DEFAULTS 15 |
| 797 |
#define MOD_POLICYDB_VERSION_DEFAULT_TYPE 16 |
| 798 |
#define MOD_POLICYDB_VERSION_CONSTRAINT_NAMES 17 |
| 799 |
#define MOD_POLICYDB_VERSION_XPERMS_IOCTL 18 |
| 800 |
#define MOD_POLICYDB_VERSION_INFINIBAND 19 |
| 801 |
#define MOD_POLICYDB_VERSION_GLBLUB 20 |
| 802 |
#define MOD_POLICYDB_VERSION_SELF_TYPETRANS 21 |
| 803 |
#define MOD_POLICYDB_VERSION_COND_XPERMS 22 |
| 804 |
#define MOD_POLICYDB_VERSION_NEVERAUDIT 23 |
| 805 |
#define MOD_POLICYDB_VERSION_TYPE_ATTR_ATTRS 24 |
| 806 |
|
| 807 |
#define MOD_POLICYDB_VERSION_MIN MOD_POLICYDB_VERSION_BASE |
| 808 |
#define MOD_POLICYDB_VERSION_MAX MOD_POLICYDB_VERSION_TYPE_ATTR_ATTRS |
| 809 |
|
| 810 |
#define POLICYDB_CONFIG_MLS 1 |
| 811 |
|
| 812 |
/* macros to check policy feature */ |
| 813 |
|
| 814 |
/* TODO: add other features here */ |
| 815 |
|
| 816 |
#define policydb_has_boundary_feature(p) \ |
| 817 |
(((p)->policy_type == POLICY_KERN \ |
| 818 |
&& (p)->policyvers >= POLICYDB_VERSION_BOUNDARY) || \ |
| 819 |
((p)->policy_type != POLICY_KERN \ |
| 820 |
&& (p)->policyvers >= MOD_POLICYDB_VERSION_BOUNDARY)) |
| 821 |
|
| 822 |
#define policydb_has_cond_xperms_feature(p) \ |
| 823 |
(((p)->policy_type == POLICY_KERN \ |
| 824 |
&& (p)->policyvers >= POLICYDB_VERSION_COND_XPERMS) || \ |
| 825 |
((p)->policy_type != POLICY_KERN \ |
| 826 |
&& (p)->policyvers >= MOD_POLICYDB_VERSION_COND_XPERMS)) |
| 827 |
|
| 828 |
/* the config flags related to unknown classes/perms are bits 2 and 3 */ |
| 829 |
#define DENY_UNKNOWN SEPOL_DENY_UNKNOWN |
| 830 |
#define REJECT_UNKNOWN SEPOL_REJECT_UNKNOWN |
| 831 |
#define ALLOW_UNKNOWN SEPOL_ALLOW_UNKNOWN |
| 832 |
|
| 833 |
#define POLICYDB_CONFIG_UNKNOWN_MASK (DENY_UNKNOWN | REJECT_UNKNOWN | ALLOW_UNKNOWN) |
| 834 |
|
| 835 |
#define OBJECT_R "object_r" |
| 836 |
#define OBJECT_R_VAL 1 |
| 837 |
|
| 838 |
#define POLICYDB_MAGIC SELINUX_MAGIC |
| 839 |
#define POLICYDB_STRING "SE Linux" |
| 840 |
#define POLICYDB_XEN_STRING "XenFlask" |
| 841 |
#define POLICYDB_STRING_MAX_LENGTH 32 |
| 842 |
#define POLICYDB_MOD_MAGIC SELINUX_MOD_MAGIC |
| 843 |
#define POLICYDB_MOD_STRING "SE Linux Module" |
| 844 |
|
| 845 |
#ifdef __cplusplus |
| 846 |
} |
| 847 |
#endif |
| 848 |
|
| 849 |
#endif /* _POLICYDB_H_ */ |
| 850 |
|
| 851 |
/* FLASK */ |