Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Implementation of the security services. |
| 3 | * |
| 4 | * Authors : Stephen Smalley, <sds@epoch.ncsc.mil> |
| 5 | * James Morris <jmorris@redhat.com> |
| 6 | * |
| 7 | * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> |
| 8 | * |
| 9 | * Support for enhanced MLS infrastructure. |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 10 | * Support for context based audit filters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com> |
| 13 | * |
| 14 | * Added conditional policy language extensions |
| 15 | * |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 16 | * Updated: Hewlett-Packard <paul.moore@hp.com> |
| 17 | * |
| 18 | * Added support for NetLabel |
| 19 | * |
Chad Sellers | b94c7e6 | 2006-11-06 12:38:18 -0500 | [diff] [blame] | 20 | * Updated: Chad Sellers <csellers@tresys.com> |
| 21 | * |
| 22 | * Added validation of kernel classes and permissions |
| 23 | * |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 24 | * Copyright (C) 2006 Hewlett-Packard Development Company, L.P. |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 25 | * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. |
Chad Sellers | b94c7e6 | 2006-11-06 12:38:18 -0500 | [diff] [blame] | 26 | * Copyright (C) 2003 - 2004, 2006 Tresys Technology, LLC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com> |
| 28 | * This program is free software; you can redistribute it and/or modify |
| 29 | * it under the terms of the GNU General Public License as published by |
| 30 | * the Free Software Foundation, version 2. |
| 31 | */ |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/spinlock.h> |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 36 | #include <linux/rcupdate.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/errno.h> |
| 38 | #include <linux/in.h> |
| 39 | #include <linux/sched.h> |
| 40 | #include <linux/audit.h> |
Ingo Molnar | bb003079 | 2006-03-22 00:09:14 -0800 | [diff] [blame] | 41 | #include <linux/mutex.h> |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 42 | #include <net/sock.h> |
| 43 | #include <net/netlabel.h> |
Ingo Molnar | bb003079 | 2006-03-22 00:09:14 -0800 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include "flask.h" |
| 46 | #include "avc.h" |
| 47 | #include "avc_ss.h" |
| 48 | #include "security.h" |
| 49 | #include "context.h" |
| 50 | #include "policydb.h" |
| 51 | #include "sidtab.h" |
| 52 | #include "services.h" |
| 53 | #include "conditional.h" |
| 54 | #include "mls.h" |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 55 | #include "objsec.h" |
| 56 | #include "selinux_netlabel.h" |
Paul Moore | 3de4bab | 2006-11-17 17:38:54 -0500 | [diff] [blame^] | 57 | #include "xfrm.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | extern void selnl_notify_policyload(u32 seqno); |
| 60 | unsigned int policydb_loaded_version; |
| 61 | |
Chad Sellers | b94c7e6 | 2006-11-06 12:38:18 -0500 | [diff] [blame] | 62 | /* |
| 63 | * This is declared in avc.c |
| 64 | */ |
| 65 | extern const struct selinux_class_perm selinux_class_perm; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static DEFINE_RWLOCK(policy_rwlock); |
| 68 | #define POLICY_RDLOCK read_lock(&policy_rwlock) |
| 69 | #define POLICY_WRLOCK write_lock_irq(&policy_rwlock) |
| 70 | #define POLICY_RDUNLOCK read_unlock(&policy_rwlock) |
| 71 | #define POLICY_WRUNLOCK write_unlock_irq(&policy_rwlock) |
| 72 | |
Ingo Molnar | bb003079 | 2006-03-22 00:09:14 -0800 | [diff] [blame] | 73 | static DEFINE_MUTEX(load_mutex); |
| 74 | #define LOAD_LOCK mutex_lock(&load_mutex) |
| 75 | #define LOAD_UNLOCK mutex_unlock(&load_mutex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | static struct sidtab sidtab; |
| 78 | struct policydb policydb; |
| 79 | int ss_initialized = 0; |
| 80 | |
| 81 | /* |
| 82 | * The largest sequence number that has been used when |
| 83 | * providing an access decision to the access vector cache. |
| 84 | * The sequence number only changes when a policy change |
| 85 | * occurs. |
| 86 | */ |
| 87 | static u32 latest_granting = 0; |
| 88 | |
| 89 | /* Forward declaration. */ |
| 90 | static int context_struct_to_string(struct context *context, char **scontext, |
| 91 | u32 *scontext_len); |
| 92 | |
| 93 | /* |
| 94 | * Return the boolean value of a constraint expression |
| 95 | * when it is applied to the specified source and target |
| 96 | * security contexts. |
| 97 | * |
| 98 | * xcontext is a special beast... It is used by the validatetrans rules |
| 99 | * only. For these rules, scontext is the context before the transition, |
| 100 | * tcontext is the context after the transition, and xcontext is the context |
| 101 | * of the process performing the transition. All other callers of |
| 102 | * constraint_expr_eval should pass in NULL for xcontext. |
| 103 | */ |
| 104 | static int constraint_expr_eval(struct context *scontext, |
| 105 | struct context *tcontext, |
| 106 | struct context *xcontext, |
| 107 | struct constraint_expr *cexpr) |
| 108 | { |
| 109 | u32 val1, val2; |
| 110 | struct context *c; |
| 111 | struct role_datum *r1, *r2; |
| 112 | struct mls_level *l1, *l2; |
| 113 | struct constraint_expr *e; |
| 114 | int s[CEXPR_MAXDEPTH]; |
| 115 | int sp = -1; |
| 116 | |
| 117 | for (e = cexpr; e; e = e->next) { |
| 118 | switch (e->expr_type) { |
| 119 | case CEXPR_NOT: |
| 120 | BUG_ON(sp < 0); |
| 121 | s[sp] = !s[sp]; |
| 122 | break; |
| 123 | case CEXPR_AND: |
| 124 | BUG_ON(sp < 1); |
| 125 | sp--; |
| 126 | s[sp] &= s[sp+1]; |
| 127 | break; |
| 128 | case CEXPR_OR: |
| 129 | BUG_ON(sp < 1); |
| 130 | sp--; |
| 131 | s[sp] |= s[sp+1]; |
| 132 | break; |
| 133 | case CEXPR_ATTR: |
| 134 | if (sp == (CEXPR_MAXDEPTH-1)) |
| 135 | return 0; |
| 136 | switch (e->attr) { |
| 137 | case CEXPR_USER: |
| 138 | val1 = scontext->user; |
| 139 | val2 = tcontext->user; |
| 140 | break; |
| 141 | case CEXPR_TYPE: |
| 142 | val1 = scontext->type; |
| 143 | val2 = tcontext->type; |
| 144 | break; |
| 145 | case CEXPR_ROLE: |
| 146 | val1 = scontext->role; |
| 147 | val2 = tcontext->role; |
| 148 | r1 = policydb.role_val_to_struct[val1 - 1]; |
| 149 | r2 = policydb.role_val_to_struct[val2 - 1]; |
| 150 | switch (e->op) { |
| 151 | case CEXPR_DOM: |
| 152 | s[++sp] = ebitmap_get_bit(&r1->dominates, |
| 153 | val2 - 1); |
| 154 | continue; |
| 155 | case CEXPR_DOMBY: |
| 156 | s[++sp] = ebitmap_get_bit(&r2->dominates, |
| 157 | val1 - 1); |
| 158 | continue; |
| 159 | case CEXPR_INCOMP: |
| 160 | s[++sp] = ( !ebitmap_get_bit(&r1->dominates, |
| 161 | val2 - 1) && |
| 162 | !ebitmap_get_bit(&r2->dominates, |
| 163 | val1 - 1) ); |
| 164 | continue; |
| 165 | default: |
| 166 | break; |
| 167 | } |
| 168 | break; |
| 169 | case CEXPR_L1L2: |
| 170 | l1 = &(scontext->range.level[0]); |
| 171 | l2 = &(tcontext->range.level[0]); |
| 172 | goto mls_ops; |
| 173 | case CEXPR_L1H2: |
| 174 | l1 = &(scontext->range.level[0]); |
| 175 | l2 = &(tcontext->range.level[1]); |
| 176 | goto mls_ops; |
| 177 | case CEXPR_H1L2: |
| 178 | l1 = &(scontext->range.level[1]); |
| 179 | l2 = &(tcontext->range.level[0]); |
| 180 | goto mls_ops; |
| 181 | case CEXPR_H1H2: |
| 182 | l1 = &(scontext->range.level[1]); |
| 183 | l2 = &(tcontext->range.level[1]); |
| 184 | goto mls_ops; |
| 185 | case CEXPR_L1H1: |
| 186 | l1 = &(scontext->range.level[0]); |
| 187 | l2 = &(scontext->range.level[1]); |
| 188 | goto mls_ops; |
| 189 | case CEXPR_L2H2: |
| 190 | l1 = &(tcontext->range.level[0]); |
| 191 | l2 = &(tcontext->range.level[1]); |
| 192 | goto mls_ops; |
| 193 | mls_ops: |
| 194 | switch (e->op) { |
| 195 | case CEXPR_EQ: |
| 196 | s[++sp] = mls_level_eq(l1, l2); |
| 197 | continue; |
| 198 | case CEXPR_NEQ: |
| 199 | s[++sp] = !mls_level_eq(l1, l2); |
| 200 | continue; |
| 201 | case CEXPR_DOM: |
| 202 | s[++sp] = mls_level_dom(l1, l2); |
| 203 | continue; |
| 204 | case CEXPR_DOMBY: |
| 205 | s[++sp] = mls_level_dom(l2, l1); |
| 206 | continue; |
| 207 | case CEXPR_INCOMP: |
| 208 | s[++sp] = mls_level_incomp(l2, l1); |
| 209 | continue; |
| 210 | default: |
| 211 | BUG(); |
| 212 | return 0; |
| 213 | } |
| 214 | break; |
| 215 | default: |
| 216 | BUG(); |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | switch (e->op) { |
| 221 | case CEXPR_EQ: |
| 222 | s[++sp] = (val1 == val2); |
| 223 | break; |
| 224 | case CEXPR_NEQ: |
| 225 | s[++sp] = (val1 != val2); |
| 226 | break; |
| 227 | default: |
| 228 | BUG(); |
| 229 | return 0; |
| 230 | } |
| 231 | break; |
| 232 | case CEXPR_NAMES: |
| 233 | if (sp == (CEXPR_MAXDEPTH-1)) |
| 234 | return 0; |
| 235 | c = scontext; |
| 236 | if (e->attr & CEXPR_TARGET) |
| 237 | c = tcontext; |
| 238 | else if (e->attr & CEXPR_XTARGET) { |
| 239 | c = xcontext; |
| 240 | if (!c) { |
| 241 | BUG(); |
| 242 | return 0; |
| 243 | } |
| 244 | } |
| 245 | if (e->attr & CEXPR_USER) |
| 246 | val1 = c->user; |
| 247 | else if (e->attr & CEXPR_ROLE) |
| 248 | val1 = c->role; |
| 249 | else if (e->attr & CEXPR_TYPE) |
| 250 | val1 = c->type; |
| 251 | else { |
| 252 | BUG(); |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | switch (e->op) { |
| 257 | case CEXPR_EQ: |
| 258 | s[++sp] = ebitmap_get_bit(&e->names, val1 - 1); |
| 259 | break; |
| 260 | case CEXPR_NEQ: |
| 261 | s[++sp] = !ebitmap_get_bit(&e->names, val1 - 1); |
| 262 | break; |
| 263 | default: |
| 264 | BUG(); |
| 265 | return 0; |
| 266 | } |
| 267 | break; |
| 268 | default: |
| 269 | BUG(); |
| 270 | return 0; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | BUG_ON(sp != 0); |
| 275 | return s[0]; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * Compute access vectors based on a context structure pair for |
| 280 | * the permissions in a particular class. |
| 281 | */ |
| 282 | static int context_struct_compute_av(struct context *scontext, |
| 283 | struct context *tcontext, |
| 284 | u16 tclass, |
| 285 | u32 requested, |
| 286 | struct av_decision *avd) |
| 287 | { |
| 288 | struct constraint_node *constraint; |
| 289 | struct role_allow *ra; |
| 290 | struct avtab_key avkey; |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 291 | struct avtab_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | struct class_datum *tclass_datum; |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 293 | struct ebitmap *sattr, *tattr; |
| 294 | struct ebitmap_node *snode, *tnode; |
| 295 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | /* |
| 298 | * Remap extended Netlink classes for old policy versions. |
| 299 | * Do this here rather than socket_type_to_security_class() |
| 300 | * in case a newer policy version is loaded, allowing sockets |
| 301 | * to remain in the correct class. |
| 302 | */ |
| 303 | if (policydb_loaded_version < POLICYDB_VERSION_NLCLASS) |
| 304 | if (tclass >= SECCLASS_NETLINK_ROUTE_SOCKET && |
| 305 | tclass <= SECCLASS_NETLINK_DNRT_SOCKET) |
| 306 | tclass = SECCLASS_NETLINK_SOCKET; |
| 307 | |
| 308 | if (!tclass || tclass > policydb.p_classes.nprim) { |
| 309 | printk(KERN_ERR "security_compute_av: unrecognized class %d\n", |
| 310 | tclass); |
| 311 | return -EINVAL; |
| 312 | } |
| 313 | tclass_datum = policydb.class_val_to_struct[tclass - 1]; |
| 314 | |
| 315 | /* |
| 316 | * Initialize the access vectors to the default values. |
| 317 | */ |
| 318 | avd->allowed = 0; |
| 319 | avd->decided = 0xffffffff; |
| 320 | avd->auditallow = 0; |
| 321 | avd->auditdeny = 0xffffffff; |
| 322 | avd->seqno = latest_granting; |
| 323 | |
| 324 | /* |
| 325 | * If a specific type enforcement rule was defined for |
| 326 | * this permission check, then use it. |
| 327 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | avkey.target_class = tclass; |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 329 | avkey.specified = AVTAB_AV; |
| 330 | sattr = &policydb.type_attr_map[scontext->type - 1]; |
| 331 | tattr = &policydb.type_attr_map[tcontext->type - 1]; |
| 332 | ebitmap_for_each_bit(sattr, snode, i) { |
| 333 | if (!ebitmap_node_get_bit(snode, i)) |
| 334 | continue; |
| 335 | ebitmap_for_each_bit(tattr, tnode, j) { |
| 336 | if (!ebitmap_node_get_bit(tnode, j)) |
| 337 | continue; |
| 338 | avkey.source_type = i + 1; |
| 339 | avkey.target_type = j + 1; |
| 340 | for (node = avtab_search_node(&policydb.te_avtab, &avkey); |
| 341 | node != NULL; |
| 342 | node = avtab_search_node_next(node, avkey.specified)) { |
| 343 | if (node->key.specified == AVTAB_ALLOWED) |
| 344 | avd->allowed |= node->datum.data; |
| 345 | else if (node->key.specified == AVTAB_AUDITALLOW) |
| 346 | avd->auditallow |= node->datum.data; |
| 347 | else if (node->key.specified == AVTAB_AUDITDENY) |
| 348 | avd->auditdeny &= node->datum.data; |
| 349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 351 | /* Check conditional av table for additional permissions */ |
| 352 | cond_compute_av(&policydb.te_cond_avtab, &avkey, avd); |
| 353 | |
| 354 | } |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * Remove any permissions prohibited by a constraint (this includes |
| 359 | * the MLS policy). |
| 360 | */ |
| 361 | constraint = tclass_datum->constraints; |
| 362 | while (constraint) { |
| 363 | if ((constraint->permissions & (avd->allowed)) && |
| 364 | !constraint_expr_eval(scontext, tcontext, NULL, |
| 365 | constraint->expr)) { |
| 366 | avd->allowed = (avd->allowed) & ~(constraint->permissions); |
| 367 | } |
| 368 | constraint = constraint->next; |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | * If checking process transition permission and the |
| 373 | * role is changing, then check the (current_role, new_role) |
| 374 | * pair. |
| 375 | */ |
| 376 | if (tclass == SECCLASS_PROCESS && |
| 377 | (avd->allowed & (PROCESS__TRANSITION | PROCESS__DYNTRANSITION)) && |
| 378 | scontext->role != tcontext->role) { |
| 379 | for (ra = policydb.role_allow; ra; ra = ra->next) { |
| 380 | if (scontext->role == ra->role && |
| 381 | tcontext->role == ra->new_role) |
| 382 | break; |
| 383 | } |
| 384 | if (!ra) |
| 385 | avd->allowed = (avd->allowed) & ~(PROCESS__TRANSITION | |
| 386 | PROCESS__DYNTRANSITION); |
| 387 | } |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int security_validtrans_handle_fail(struct context *ocontext, |
| 393 | struct context *ncontext, |
| 394 | struct context *tcontext, |
| 395 | u16 tclass) |
| 396 | { |
| 397 | char *o = NULL, *n = NULL, *t = NULL; |
| 398 | u32 olen, nlen, tlen; |
| 399 | |
| 400 | if (context_struct_to_string(ocontext, &o, &olen) < 0) |
| 401 | goto out; |
| 402 | if (context_struct_to_string(ncontext, &n, &nlen) < 0) |
| 403 | goto out; |
| 404 | if (context_struct_to_string(tcontext, &t, &tlen) < 0) |
| 405 | goto out; |
David Woodhouse | 9ad9ad3 | 2005-06-22 15:04:33 +0100 | [diff] [blame] | 406 | audit_log(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | "security_validate_transition: denied for" |
| 408 | " oldcontext=%s newcontext=%s taskcontext=%s tclass=%s", |
| 409 | o, n, t, policydb.p_class_val_to_name[tclass-1]); |
| 410 | out: |
| 411 | kfree(o); |
| 412 | kfree(n); |
| 413 | kfree(t); |
| 414 | |
| 415 | if (!selinux_enforcing) |
| 416 | return 0; |
| 417 | return -EPERM; |
| 418 | } |
| 419 | |
| 420 | int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid, |
| 421 | u16 tclass) |
| 422 | { |
| 423 | struct context *ocontext; |
| 424 | struct context *ncontext; |
| 425 | struct context *tcontext; |
| 426 | struct class_datum *tclass_datum; |
| 427 | struct constraint_node *constraint; |
| 428 | int rc = 0; |
| 429 | |
| 430 | if (!ss_initialized) |
| 431 | return 0; |
| 432 | |
| 433 | POLICY_RDLOCK; |
| 434 | |
| 435 | /* |
| 436 | * Remap extended Netlink classes for old policy versions. |
| 437 | * Do this here rather than socket_type_to_security_class() |
| 438 | * in case a newer policy version is loaded, allowing sockets |
| 439 | * to remain in the correct class. |
| 440 | */ |
| 441 | if (policydb_loaded_version < POLICYDB_VERSION_NLCLASS) |
| 442 | if (tclass >= SECCLASS_NETLINK_ROUTE_SOCKET && |
| 443 | tclass <= SECCLASS_NETLINK_DNRT_SOCKET) |
| 444 | tclass = SECCLASS_NETLINK_SOCKET; |
| 445 | |
| 446 | if (!tclass || tclass > policydb.p_classes.nprim) { |
| 447 | printk(KERN_ERR "security_validate_transition: " |
| 448 | "unrecognized class %d\n", tclass); |
| 449 | rc = -EINVAL; |
| 450 | goto out; |
| 451 | } |
| 452 | tclass_datum = policydb.class_val_to_struct[tclass - 1]; |
| 453 | |
| 454 | ocontext = sidtab_search(&sidtab, oldsid); |
| 455 | if (!ocontext) { |
| 456 | printk(KERN_ERR "security_validate_transition: " |
| 457 | " unrecognized SID %d\n", oldsid); |
| 458 | rc = -EINVAL; |
| 459 | goto out; |
| 460 | } |
| 461 | |
| 462 | ncontext = sidtab_search(&sidtab, newsid); |
| 463 | if (!ncontext) { |
| 464 | printk(KERN_ERR "security_validate_transition: " |
| 465 | " unrecognized SID %d\n", newsid); |
| 466 | rc = -EINVAL; |
| 467 | goto out; |
| 468 | } |
| 469 | |
| 470 | tcontext = sidtab_search(&sidtab, tasksid); |
| 471 | if (!tcontext) { |
| 472 | printk(KERN_ERR "security_validate_transition: " |
| 473 | " unrecognized SID %d\n", tasksid); |
| 474 | rc = -EINVAL; |
| 475 | goto out; |
| 476 | } |
| 477 | |
| 478 | constraint = tclass_datum->validatetrans; |
| 479 | while (constraint) { |
| 480 | if (!constraint_expr_eval(ocontext, ncontext, tcontext, |
| 481 | constraint->expr)) { |
| 482 | rc = security_validtrans_handle_fail(ocontext, ncontext, |
| 483 | tcontext, tclass); |
| 484 | goto out; |
| 485 | } |
| 486 | constraint = constraint->next; |
| 487 | } |
| 488 | |
| 489 | out: |
| 490 | POLICY_RDUNLOCK; |
| 491 | return rc; |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * security_compute_av - Compute access vector decisions. |
| 496 | * @ssid: source security identifier |
| 497 | * @tsid: target security identifier |
| 498 | * @tclass: target security class |
| 499 | * @requested: requested permissions |
| 500 | * @avd: access vector decisions |
| 501 | * |
| 502 | * Compute a set of access vector decisions based on the |
| 503 | * SID pair (@ssid, @tsid) for the permissions in @tclass. |
| 504 | * Return -%EINVAL if any of the parameters are invalid or %0 |
| 505 | * if the access vector decisions were computed successfully. |
| 506 | */ |
| 507 | int security_compute_av(u32 ssid, |
| 508 | u32 tsid, |
| 509 | u16 tclass, |
| 510 | u32 requested, |
| 511 | struct av_decision *avd) |
| 512 | { |
| 513 | struct context *scontext = NULL, *tcontext = NULL; |
| 514 | int rc = 0; |
| 515 | |
| 516 | if (!ss_initialized) { |
Stephen Smalley | 4c443d1 | 2005-05-16 21:53:52 -0700 | [diff] [blame] | 517 | avd->allowed = 0xffffffff; |
| 518 | avd->decided = 0xffffffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | avd->auditallow = 0; |
| 520 | avd->auditdeny = 0xffffffff; |
| 521 | avd->seqno = latest_granting; |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | POLICY_RDLOCK; |
| 526 | |
| 527 | scontext = sidtab_search(&sidtab, ssid); |
| 528 | if (!scontext) { |
| 529 | printk(KERN_ERR "security_compute_av: unrecognized SID %d\n", |
| 530 | ssid); |
| 531 | rc = -EINVAL; |
| 532 | goto out; |
| 533 | } |
| 534 | tcontext = sidtab_search(&sidtab, tsid); |
| 535 | if (!tcontext) { |
| 536 | printk(KERN_ERR "security_compute_av: unrecognized SID %d\n", |
| 537 | tsid); |
| 538 | rc = -EINVAL; |
| 539 | goto out; |
| 540 | } |
| 541 | |
| 542 | rc = context_struct_compute_av(scontext, tcontext, tclass, |
| 543 | requested, avd); |
| 544 | out: |
| 545 | POLICY_RDUNLOCK; |
| 546 | return rc; |
| 547 | } |
| 548 | |
| 549 | /* |
| 550 | * Write the security context string representation of |
| 551 | * the context structure `context' into a dynamically |
| 552 | * allocated string of the correct size. Set `*scontext' |
| 553 | * to point to this string and set `*scontext_len' to |
| 554 | * the length of the string. |
| 555 | */ |
| 556 | static int context_struct_to_string(struct context *context, char **scontext, u32 *scontext_len) |
| 557 | { |
| 558 | char *scontextp; |
| 559 | |
| 560 | *scontext = NULL; |
| 561 | *scontext_len = 0; |
| 562 | |
| 563 | /* Compute the size of the context. */ |
| 564 | *scontext_len += strlen(policydb.p_user_val_to_name[context->user - 1]) + 1; |
| 565 | *scontext_len += strlen(policydb.p_role_val_to_name[context->role - 1]) + 1; |
| 566 | *scontext_len += strlen(policydb.p_type_val_to_name[context->type - 1]) + 1; |
| 567 | *scontext_len += mls_compute_context_len(context); |
| 568 | |
| 569 | /* Allocate space for the context; caller must free this space. */ |
| 570 | scontextp = kmalloc(*scontext_len, GFP_ATOMIC); |
| 571 | if (!scontextp) { |
| 572 | return -ENOMEM; |
| 573 | } |
| 574 | *scontext = scontextp; |
| 575 | |
| 576 | /* |
| 577 | * Copy the user name, role name and type name into the context. |
| 578 | */ |
| 579 | sprintf(scontextp, "%s:%s:%s", |
| 580 | policydb.p_user_val_to_name[context->user - 1], |
| 581 | policydb.p_role_val_to_name[context->role - 1], |
| 582 | policydb.p_type_val_to_name[context->type - 1]); |
| 583 | scontextp += strlen(policydb.p_user_val_to_name[context->user - 1]) + |
| 584 | 1 + strlen(policydb.p_role_val_to_name[context->role - 1]) + |
| 585 | 1 + strlen(policydb.p_type_val_to_name[context->type - 1]); |
| 586 | |
| 587 | mls_sid_to_context(context, &scontextp); |
| 588 | |
| 589 | *scontextp = 0; |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | #include "initial_sid_to_string.h" |
| 595 | |
| 596 | /** |
| 597 | * security_sid_to_context - Obtain a context for a given SID. |
| 598 | * @sid: security identifier, SID |
| 599 | * @scontext: security context |
| 600 | * @scontext_len: length in bytes |
| 601 | * |
| 602 | * Write the string representation of the context associated with @sid |
| 603 | * into a dynamically allocated string of the correct size. Set @scontext |
| 604 | * to point to this string and set @scontext_len to the length of the string. |
| 605 | */ |
| 606 | int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len) |
| 607 | { |
| 608 | struct context *context; |
| 609 | int rc = 0; |
| 610 | |
| 611 | if (!ss_initialized) { |
| 612 | if (sid <= SECINITSID_NUM) { |
| 613 | char *scontextp; |
| 614 | |
| 615 | *scontext_len = strlen(initial_sid_to_string[sid]) + 1; |
| 616 | scontextp = kmalloc(*scontext_len,GFP_ATOMIC); |
Serge E. Hallyn | 0cccca06 | 2006-05-15 09:43:48 -0700 | [diff] [blame] | 617 | if (!scontextp) { |
| 618 | rc = -ENOMEM; |
| 619 | goto out; |
| 620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | strcpy(scontextp, initial_sid_to_string[sid]); |
| 622 | *scontext = scontextp; |
| 623 | goto out; |
| 624 | } |
| 625 | printk(KERN_ERR "security_sid_to_context: called before initial " |
| 626 | "load_policy on unknown SID %d\n", sid); |
| 627 | rc = -EINVAL; |
| 628 | goto out; |
| 629 | } |
| 630 | POLICY_RDLOCK; |
| 631 | context = sidtab_search(&sidtab, sid); |
| 632 | if (!context) { |
| 633 | printk(KERN_ERR "security_sid_to_context: unrecognized SID " |
| 634 | "%d\n", sid); |
| 635 | rc = -EINVAL; |
| 636 | goto out_unlock; |
| 637 | } |
| 638 | rc = context_struct_to_string(context, scontext, scontext_len); |
| 639 | out_unlock: |
| 640 | POLICY_RDUNLOCK; |
| 641 | out: |
| 642 | return rc; |
| 643 | |
| 644 | } |
| 645 | |
James Morris | f5c1d5b | 2005-07-28 01:07:37 -0700 | [diff] [blame] | 646 | static int security_context_to_sid_core(char *scontext, u32 scontext_len, u32 *sid, u32 def_sid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
| 648 | char *scontext2; |
| 649 | struct context context; |
| 650 | struct role_datum *role; |
| 651 | struct type_datum *typdatum; |
| 652 | struct user_datum *usrdatum; |
| 653 | char *scontextp, *p, oldc; |
| 654 | int rc = 0; |
| 655 | |
| 656 | if (!ss_initialized) { |
| 657 | int i; |
| 658 | |
| 659 | for (i = 1; i < SECINITSID_NUM; i++) { |
| 660 | if (!strcmp(initial_sid_to_string[i], scontext)) { |
| 661 | *sid = i; |
| 662 | goto out; |
| 663 | } |
| 664 | } |
| 665 | *sid = SECINITSID_KERNEL; |
| 666 | goto out; |
| 667 | } |
| 668 | *sid = SECSID_NULL; |
| 669 | |
| 670 | /* Copy the string so that we can modify the copy as we parse it. |
| 671 | The string should already by null terminated, but we append a |
| 672 | null suffix to the copy to avoid problems with the existing |
| 673 | attr package, which doesn't view the null terminator as part |
| 674 | of the attribute value. */ |
| 675 | scontext2 = kmalloc(scontext_len+1,GFP_KERNEL); |
| 676 | if (!scontext2) { |
| 677 | rc = -ENOMEM; |
| 678 | goto out; |
| 679 | } |
| 680 | memcpy(scontext2, scontext, scontext_len); |
| 681 | scontext2[scontext_len] = 0; |
| 682 | |
| 683 | context_init(&context); |
| 684 | *sid = SECSID_NULL; |
| 685 | |
| 686 | POLICY_RDLOCK; |
| 687 | |
| 688 | /* Parse the security context. */ |
| 689 | |
| 690 | rc = -EINVAL; |
| 691 | scontextp = (char *) scontext2; |
| 692 | |
| 693 | /* Extract the user. */ |
| 694 | p = scontextp; |
| 695 | while (*p && *p != ':') |
| 696 | p++; |
| 697 | |
| 698 | if (*p == 0) |
| 699 | goto out_unlock; |
| 700 | |
| 701 | *p++ = 0; |
| 702 | |
| 703 | usrdatum = hashtab_search(policydb.p_users.table, scontextp); |
| 704 | if (!usrdatum) |
| 705 | goto out_unlock; |
| 706 | |
| 707 | context.user = usrdatum->value; |
| 708 | |
| 709 | /* Extract role. */ |
| 710 | scontextp = p; |
| 711 | while (*p && *p != ':') |
| 712 | p++; |
| 713 | |
| 714 | if (*p == 0) |
| 715 | goto out_unlock; |
| 716 | |
| 717 | *p++ = 0; |
| 718 | |
| 719 | role = hashtab_search(policydb.p_roles.table, scontextp); |
| 720 | if (!role) |
| 721 | goto out_unlock; |
| 722 | context.role = role->value; |
| 723 | |
| 724 | /* Extract type. */ |
| 725 | scontextp = p; |
| 726 | while (*p && *p != ':') |
| 727 | p++; |
| 728 | oldc = *p; |
| 729 | *p++ = 0; |
| 730 | |
| 731 | typdatum = hashtab_search(policydb.p_types.table, scontextp); |
| 732 | if (!typdatum) |
| 733 | goto out_unlock; |
| 734 | |
| 735 | context.type = typdatum->value; |
| 736 | |
James Morris | f5c1d5b | 2005-07-28 01:07:37 -0700 | [diff] [blame] | 737 | rc = mls_context_to_sid(oldc, &p, &context, &sidtab, def_sid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | if (rc) |
| 739 | goto out_unlock; |
| 740 | |
| 741 | if ((p - scontext2) < scontext_len) { |
| 742 | rc = -EINVAL; |
| 743 | goto out_unlock; |
| 744 | } |
| 745 | |
| 746 | /* Check the validity of the new context. */ |
| 747 | if (!policydb_context_isvalid(&policydb, &context)) { |
| 748 | rc = -EINVAL; |
| 749 | goto out_unlock; |
| 750 | } |
| 751 | /* Obtain the new sid. */ |
| 752 | rc = sidtab_context_to_sid(&sidtab, &context, sid); |
| 753 | out_unlock: |
| 754 | POLICY_RDUNLOCK; |
| 755 | context_destroy(&context); |
| 756 | kfree(scontext2); |
| 757 | out: |
| 758 | return rc; |
| 759 | } |
| 760 | |
James Morris | f5c1d5b | 2005-07-28 01:07:37 -0700 | [diff] [blame] | 761 | /** |
| 762 | * security_context_to_sid - Obtain a SID for a given security context. |
| 763 | * @scontext: security context |
| 764 | * @scontext_len: length in bytes |
| 765 | * @sid: security identifier, SID |
| 766 | * |
| 767 | * Obtains a SID associated with the security context that |
| 768 | * has the string representation specified by @scontext. |
| 769 | * Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient |
| 770 | * memory is available, or 0 on success. |
| 771 | */ |
| 772 | int security_context_to_sid(char *scontext, u32 scontext_len, u32 *sid) |
| 773 | { |
| 774 | return security_context_to_sid_core(scontext, scontext_len, |
| 775 | sid, SECSID_NULL); |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * security_context_to_sid_default - Obtain a SID for a given security context, |
| 780 | * falling back to specified default if needed. |
| 781 | * |
| 782 | * @scontext: security context |
| 783 | * @scontext_len: length in bytes |
| 784 | * @sid: security identifier, SID |
| 785 | * @def_sid: default SID to assign on errror |
| 786 | * |
| 787 | * Obtains a SID associated with the security context that |
| 788 | * has the string representation specified by @scontext. |
| 789 | * The default SID is passed to the MLS layer to be used to allow |
| 790 | * kernel labeling of the MLS field if the MLS field is not present |
| 791 | * (for upgrading to MLS without full relabel). |
| 792 | * Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient |
| 793 | * memory is available, or 0 on success. |
| 794 | */ |
| 795 | int security_context_to_sid_default(char *scontext, u32 scontext_len, u32 *sid, u32 def_sid) |
| 796 | { |
| 797 | return security_context_to_sid_core(scontext, scontext_len, |
| 798 | sid, def_sid); |
| 799 | } |
| 800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | static int compute_sid_handle_invalid_context( |
| 802 | struct context *scontext, |
| 803 | struct context *tcontext, |
| 804 | u16 tclass, |
| 805 | struct context *newcontext) |
| 806 | { |
| 807 | char *s = NULL, *t = NULL, *n = NULL; |
| 808 | u32 slen, tlen, nlen; |
| 809 | |
| 810 | if (context_struct_to_string(scontext, &s, &slen) < 0) |
| 811 | goto out; |
| 812 | if (context_struct_to_string(tcontext, &t, &tlen) < 0) |
| 813 | goto out; |
| 814 | if (context_struct_to_string(newcontext, &n, &nlen) < 0) |
| 815 | goto out; |
David Woodhouse | 9ad9ad3 | 2005-06-22 15:04:33 +0100 | [diff] [blame] | 816 | audit_log(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | "security_compute_sid: invalid context %s" |
| 818 | " for scontext=%s" |
| 819 | " tcontext=%s" |
| 820 | " tclass=%s", |
| 821 | n, s, t, policydb.p_class_val_to_name[tclass-1]); |
| 822 | out: |
| 823 | kfree(s); |
| 824 | kfree(t); |
| 825 | kfree(n); |
| 826 | if (!selinux_enforcing) |
| 827 | return 0; |
| 828 | return -EACCES; |
| 829 | } |
| 830 | |
| 831 | static int security_compute_sid(u32 ssid, |
| 832 | u32 tsid, |
| 833 | u16 tclass, |
| 834 | u32 specified, |
| 835 | u32 *out_sid) |
| 836 | { |
| 837 | struct context *scontext = NULL, *tcontext = NULL, newcontext; |
| 838 | struct role_trans *roletr = NULL; |
| 839 | struct avtab_key avkey; |
| 840 | struct avtab_datum *avdatum; |
| 841 | struct avtab_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | int rc = 0; |
| 843 | |
| 844 | if (!ss_initialized) { |
| 845 | switch (tclass) { |
| 846 | case SECCLASS_PROCESS: |
| 847 | *out_sid = ssid; |
| 848 | break; |
| 849 | default: |
| 850 | *out_sid = tsid; |
| 851 | break; |
| 852 | } |
| 853 | goto out; |
| 854 | } |
| 855 | |
Venkat Yekkirala | 851f8a6 | 2006-07-30 03:03:18 -0700 | [diff] [blame] | 856 | context_init(&newcontext); |
| 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | POLICY_RDLOCK; |
| 859 | |
| 860 | scontext = sidtab_search(&sidtab, ssid); |
| 861 | if (!scontext) { |
| 862 | printk(KERN_ERR "security_compute_sid: unrecognized SID %d\n", |
| 863 | ssid); |
| 864 | rc = -EINVAL; |
| 865 | goto out_unlock; |
| 866 | } |
| 867 | tcontext = sidtab_search(&sidtab, tsid); |
| 868 | if (!tcontext) { |
| 869 | printk(KERN_ERR "security_compute_sid: unrecognized SID %d\n", |
| 870 | tsid); |
| 871 | rc = -EINVAL; |
| 872 | goto out_unlock; |
| 873 | } |
| 874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | /* Set the user identity. */ |
| 876 | switch (specified) { |
| 877 | case AVTAB_TRANSITION: |
| 878 | case AVTAB_CHANGE: |
| 879 | /* Use the process user identity. */ |
| 880 | newcontext.user = scontext->user; |
| 881 | break; |
| 882 | case AVTAB_MEMBER: |
| 883 | /* Use the related object owner. */ |
| 884 | newcontext.user = tcontext->user; |
| 885 | break; |
| 886 | } |
| 887 | |
| 888 | /* Set the role and type to default values. */ |
| 889 | switch (tclass) { |
| 890 | case SECCLASS_PROCESS: |
| 891 | /* Use the current role and type of process. */ |
| 892 | newcontext.role = scontext->role; |
| 893 | newcontext.type = scontext->type; |
| 894 | break; |
| 895 | default: |
| 896 | /* Use the well-defined object role. */ |
| 897 | newcontext.role = OBJECT_R_VAL; |
| 898 | /* Use the type of the related object. */ |
| 899 | newcontext.type = tcontext->type; |
| 900 | } |
| 901 | |
| 902 | /* Look for a type transition/member/change rule. */ |
| 903 | avkey.source_type = scontext->type; |
| 904 | avkey.target_type = tcontext->type; |
| 905 | avkey.target_class = tclass; |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 906 | avkey.specified = specified; |
| 907 | avdatum = avtab_search(&policydb.te_avtab, &avkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
| 909 | /* If no permanent rule, also check for enabled conditional rules */ |
| 910 | if(!avdatum) { |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 911 | node = avtab_search_node(&policydb.te_cond_avtab, &avkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | for (; node != NULL; node = avtab_search_node_next(node, specified)) { |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 913 | if (node->key.specified & AVTAB_ENABLED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | avdatum = &node->datum; |
| 915 | break; |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 920 | if (avdatum) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | /* Use the type from the type transition/member/change rule. */ |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 922 | newcontext.type = avdatum->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | /* Check for class-specific changes. */ |
| 926 | switch (tclass) { |
| 927 | case SECCLASS_PROCESS: |
| 928 | if (specified & AVTAB_TRANSITION) { |
| 929 | /* Look for a role transition rule. */ |
| 930 | for (roletr = policydb.role_tr; roletr; |
| 931 | roletr = roletr->next) { |
| 932 | if (roletr->role == scontext->role && |
| 933 | roletr->type == tcontext->type) { |
| 934 | /* Use the role transition rule. */ |
| 935 | newcontext.role = roletr->new_role; |
| 936 | break; |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | break; |
| 941 | default: |
| 942 | break; |
| 943 | } |
| 944 | |
| 945 | /* Set the MLS attributes. |
| 946 | This is done last because it may allocate memory. */ |
| 947 | rc = mls_compute_sid(scontext, tcontext, tclass, specified, &newcontext); |
| 948 | if (rc) |
| 949 | goto out_unlock; |
| 950 | |
| 951 | /* Check the validity of the context. */ |
| 952 | if (!policydb_context_isvalid(&policydb, &newcontext)) { |
| 953 | rc = compute_sid_handle_invalid_context(scontext, |
| 954 | tcontext, |
| 955 | tclass, |
| 956 | &newcontext); |
| 957 | if (rc) |
| 958 | goto out_unlock; |
| 959 | } |
| 960 | /* Obtain the sid for the context. */ |
| 961 | rc = sidtab_context_to_sid(&sidtab, &newcontext, out_sid); |
| 962 | out_unlock: |
| 963 | POLICY_RDUNLOCK; |
| 964 | context_destroy(&newcontext); |
| 965 | out: |
| 966 | return rc; |
| 967 | } |
| 968 | |
| 969 | /** |
| 970 | * security_transition_sid - Compute the SID for a new subject/object. |
| 971 | * @ssid: source security identifier |
| 972 | * @tsid: target security identifier |
| 973 | * @tclass: target security class |
| 974 | * @out_sid: security identifier for new subject/object |
| 975 | * |
| 976 | * Compute a SID to use for labeling a new subject or object in the |
| 977 | * class @tclass based on a SID pair (@ssid, @tsid). |
| 978 | * Return -%EINVAL if any of the parameters are invalid, -%ENOMEM |
| 979 | * if insufficient memory is available, or %0 if the new SID was |
| 980 | * computed successfully. |
| 981 | */ |
| 982 | int security_transition_sid(u32 ssid, |
| 983 | u32 tsid, |
| 984 | u16 tclass, |
| 985 | u32 *out_sid) |
| 986 | { |
| 987 | return security_compute_sid(ssid, tsid, tclass, AVTAB_TRANSITION, out_sid); |
| 988 | } |
| 989 | |
| 990 | /** |
| 991 | * security_member_sid - Compute the SID for member selection. |
| 992 | * @ssid: source security identifier |
| 993 | * @tsid: target security identifier |
| 994 | * @tclass: target security class |
| 995 | * @out_sid: security identifier for selected member |
| 996 | * |
| 997 | * Compute a SID to use when selecting a member of a polyinstantiated |
| 998 | * object of class @tclass based on a SID pair (@ssid, @tsid). |
| 999 | * Return -%EINVAL if any of the parameters are invalid, -%ENOMEM |
| 1000 | * if insufficient memory is available, or %0 if the SID was |
| 1001 | * computed successfully. |
| 1002 | */ |
| 1003 | int security_member_sid(u32 ssid, |
| 1004 | u32 tsid, |
| 1005 | u16 tclass, |
| 1006 | u32 *out_sid) |
| 1007 | { |
| 1008 | return security_compute_sid(ssid, tsid, tclass, AVTAB_MEMBER, out_sid); |
| 1009 | } |
| 1010 | |
| 1011 | /** |
| 1012 | * security_change_sid - Compute the SID for object relabeling. |
| 1013 | * @ssid: source security identifier |
| 1014 | * @tsid: target security identifier |
| 1015 | * @tclass: target security class |
| 1016 | * @out_sid: security identifier for selected member |
| 1017 | * |
| 1018 | * Compute a SID to use for relabeling an object of class @tclass |
| 1019 | * based on a SID pair (@ssid, @tsid). |
| 1020 | * Return -%EINVAL if any of the parameters are invalid, -%ENOMEM |
| 1021 | * if insufficient memory is available, or %0 if the SID was |
| 1022 | * computed successfully. |
| 1023 | */ |
| 1024 | int security_change_sid(u32 ssid, |
| 1025 | u32 tsid, |
| 1026 | u16 tclass, |
| 1027 | u32 *out_sid) |
| 1028 | { |
| 1029 | return security_compute_sid(ssid, tsid, tclass, AVTAB_CHANGE, out_sid); |
| 1030 | } |
| 1031 | |
Chad Sellers | b94c7e6 | 2006-11-06 12:38:18 -0500 | [diff] [blame] | 1032 | /* |
| 1033 | * Verify that each kernel class that is defined in the |
| 1034 | * policy is correct |
| 1035 | */ |
| 1036 | static int validate_classes(struct policydb *p) |
| 1037 | { |
| 1038 | int i, j; |
| 1039 | struct class_datum *cladatum; |
| 1040 | struct perm_datum *perdatum; |
| 1041 | u32 nprim, tmp, common_pts_len, perm_val, pol_val; |
| 1042 | u16 class_val; |
| 1043 | const struct selinux_class_perm *kdefs = &selinux_class_perm; |
| 1044 | const char *def_class, *def_perm, *pol_class; |
| 1045 | struct symtab *perms; |
| 1046 | |
| 1047 | for (i = 1; i < kdefs->cts_len; i++) { |
| 1048 | def_class = kdefs->class_to_string[i]; |
| 1049 | if (i > p->p_classes.nprim) { |
| 1050 | printk(KERN_INFO |
| 1051 | "security: class %s not defined in policy\n", |
| 1052 | def_class); |
| 1053 | continue; |
| 1054 | } |
| 1055 | pol_class = p->p_class_val_to_name[i-1]; |
| 1056 | if (strcmp(pol_class, def_class)) { |
| 1057 | printk(KERN_ERR |
| 1058 | "security: class %d is incorrect, found %s but should be %s\n", |
| 1059 | i, pol_class, def_class); |
| 1060 | return -EINVAL; |
| 1061 | } |
| 1062 | } |
| 1063 | for (i = 0; i < kdefs->av_pts_len; i++) { |
| 1064 | class_val = kdefs->av_perm_to_string[i].tclass; |
| 1065 | perm_val = kdefs->av_perm_to_string[i].value; |
| 1066 | def_perm = kdefs->av_perm_to_string[i].name; |
| 1067 | if (class_val > p->p_classes.nprim) |
| 1068 | continue; |
| 1069 | pol_class = p->p_class_val_to_name[class_val-1]; |
| 1070 | cladatum = hashtab_search(p->p_classes.table, pol_class); |
| 1071 | BUG_ON(!cladatum); |
| 1072 | perms = &cladatum->permissions; |
| 1073 | nprim = 1 << (perms->nprim - 1); |
| 1074 | if (perm_val > nprim) { |
| 1075 | printk(KERN_INFO |
| 1076 | "security: permission %s in class %s not defined in policy\n", |
| 1077 | def_perm, pol_class); |
| 1078 | continue; |
| 1079 | } |
| 1080 | perdatum = hashtab_search(perms->table, def_perm); |
| 1081 | if (perdatum == NULL) { |
| 1082 | printk(KERN_ERR |
| 1083 | "security: permission %s in class %s not found in policy\n", |
| 1084 | def_perm, pol_class); |
| 1085 | return -EINVAL; |
| 1086 | } |
| 1087 | pol_val = 1 << (perdatum->value - 1); |
| 1088 | if (pol_val != perm_val) { |
| 1089 | printk(KERN_ERR |
| 1090 | "security: permission %s in class %s has incorrect value\n", |
| 1091 | def_perm, pol_class); |
| 1092 | return -EINVAL; |
| 1093 | } |
| 1094 | } |
| 1095 | for (i = 0; i < kdefs->av_inherit_len; i++) { |
| 1096 | class_val = kdefs->av_inherit[i].tclass; |
| 1097 | if (class_val > p->p_classes.nprim) |
| 1098 | continue; |
| 1099 | pol_class = p->p_class_val_to_name[class_val-1]; |
| 1100 | cladatum = hashtab_search(p->p_classes.table, pol_class); |
| 1101 | BUG_ON(!cladatum); |
| 1102 | if (!cladatum->comdatum) { |
| 1103 | printk(KERN_ERR |
| 1104 | "security: class %s should have an inherits clause but does not\n", |
| 1105 | pol_class); |
| 1106 | return -EINVAL; |
| 1107 | } |
| 1108 | tmp = kdefs->av_inherit[i].common_base; |
| 1109 | common_pts_len = 0; |
| 1110 | while (!(tmp & 0x01)) { |
| 1111 | common_pts_len++; |
| 1112 | tmp >>= 1; |
| 1113 | } |
| 1114 | perms = &cladatum->comdatum->permissions; |
| 1115 | for (j = 0; j < common_pts_len; j++) { |
| 1116 | def_perm = kdefs->av_inherit[i].common_pts[j]; |
| 1117 | if (j >= perms->nprim) { |
| 1118 | printk(KERN_INFO |
| 1119 | "security: permission %s in class %s not defined in policy\n", |
| 1120 | def_perm, pol_class); |
| 1121 | continue; |
| 1122 | } |
| 1123 | perdatum = hashtab_search(perms->table, def_perm); |
| 1124 | if (perdatum == NULL) { |
| 1125 | printk(KERN_ERR |
| 1126 | "security: permission %s in class %s not found in policy\n", |
| 1127 | def_perm, pol_class); |
| 1128 | return -EINVAL; |
| 1129 | } |
| 1130 | if (perdatum->value != j + 1) { |
| 1131 | printk(KERN_ERR |
| 1132 | "security: permission %s in class %s has incorrect value\n", |
| 1133 | def_perm, pol_class); |
| 1134 | return -EINVAL; |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | /* Clone the SID into the new SID table. */ |
| 1142 | static int clone_sid(u32 sid, |
| 1143 | struct context *context, |
| 1144 | void *arg) |
| 1145 | { |
| 1146 | struct sidtab *s = arg; |
| 1147 | |
| 1148 | return sidtab_insert(s, sid, context); |
| 1149 | } |
| 1150 | |
| 1151 | static inline int convert_context_handle_invalid_context(struct context *context) |
| 1152 | { |
| 1153 | int rc = 0; |
| 1154 | |
| 1155 | if (selinux_enforcing) { |
| 1156 | rc = -EINVAL; |
| 1157 | } else { |
| 1158 | char *s; |
| 1159 | u32 len; |
| 1160 | |
| 1161 | context_struct_to_string(context, &s, &len); |
| 1162 | printk(KERN_ERR "security: context %s is invalid\n", s); |
| 1163 | kfree(s); |
| 1164 | } |
| 1165 | return rc; |
| 1166 | } |
| 1167 | |
| 1168 | struct convert_context_args { |
| 1169 | struct policydb *oldp; |
| 1170 | struct policydb *newp; |
| 1171 | }; |
| 1172 | |
| 1173 | /* |
| 1174 | * Convert the values in the security context |
| 1175 | * structure `c' from the values specified |
| 1176 | * in the policy `p->oldp' to the values specified |
| 1177 | * in the policy `p->newp'. Verify that the |
| 1178 | * context is valid under the new policy. |
| 1179 | */ |
| 1180 | static int convert_context(u32 key, |
| 1181 | struct context *c, |
| 1182 | void *p) |
| 1183 | { |
| 1184 | struct convert_context_args *args; |
| 1185 | struct context oldc; |
| 1186 | struct role_datum *role; |
| 1187 | struct type_datum *typdatum; |
| 1188 | struct user_datum *usrdatum; |
| 1189 | char *s; |
| 1190 | u32 len; |
| 1191 | int rc; |
| 1192 | |
| 1193 | args = p; |
| 1194 | |
| 1195 | rc = context_cpy(&oldc, c); |
| 1196 | if (rc) |
| 1197 | goto out; |
| 1198 | |
| 1199 | rc = -EINVAL; |
| 1200 | |
| 1201 | /* Convert the user. */ |
| 1202 | usrdatum = hashtab_search(args->newp->p_users.table, |
| 1203 | args->oldp->p_user_val_to_name[c->user - 1]); |
| 1204 | if (!usrdatum) { |
| 1205 | goto bad; |
| 1206 | } |
| 1207 | c->user = usrdatum->value; |
| 1208 | |
| 1209 | /* Convert the role. */ |
| 1210 | role = hashtab_search(args->newp->p_roles.table, |
| 1211 | args->oldp->p_role_val_to_name[c->role - 1]); |
| 1212 | if (!role) { |
| 1213 | goto bad; |
| 1214 | } |
| 1215 | c->role = role->value; |
| 1216 | |
| 1217 | /* Convert the type. */ |
| 1218 | typdatum = hashtab_search(args->newp->p_types.table, |
| 1219 | args->oldp->p_type_val_to_name[c->type - 1]); |
| 1220 | if (!typdatum) { |
| 1221 | goto bad; |
| 1222 | } |
| 1223 | c->type = typdatum->value; |
| 1224 | |
| 1225 | rc = mls_convert_context(args->oldp, args->newp, c); |
| 1226 | if (rc) |
| 1227 | goto bad; |
| 1228 | |
| 1229 | /* Check the validity of the new context. */ |
| 1230 | if (!policydb_context_isvalid(args->newp, c)) { |
| 1231 | rc = convert_context_handle_invalid_context(&oldc); |
| 1232 | if (rc) |
| 1233 | goto bad; |
| 1234 | } |
| 1235 | |
| 1236 | context_destroy(&oldc); |
| 1237 | out: |
| 1238 | return rc; |
| 1239 | bad: |
| 1240 | context_struct_to_string(&oldc, &s, &len); |
| 1241 | context_destroy(&oldc); |
| 1242 | printk(KERN_ERR "security: invalidating context %s\n", s); |
| 1243 | kfree(s); |
| 1244 | goto out; |
| 1245 | } |
| 1246 | |
| 1247 | extern void selinux_complete_init(void); |
| 1248 | |
| 1249 | /** |
| 1250 | * security_load_policy - Load a security policy configuration. |
| 1251 | * @data: binary policy data |
| 1252 | * @len: length of data in bytes |
| 1253 | * |
| 1254 | * Load a new set of security policy configuration data, |
| 1255 | * validate it and convert the SID table as necessary. |
| 1256 | * This function will flush the access vector cache after |
| 1257 | * loading the new policy. |
| 1258 | */ |
| 1259 | int security_load_policy(void *data, size_t len) |
| 1260 | { |
| 1261 | struct policydb oldpolicydb, newpolicydb; |
| 1262 | struct sidtab oldsidtab, newsidtab; |
| 1263 | struct convert_context_args args; |
| 1264 | u32 seqno; |
| 1265 | int rc = 0; |
| 1266 | struct policy_file file = { data, len }, *fp = &file; |
| 1267 | |
| 1268 | LOAD_LOCK; |
| 1269 | |
| 1270 | if (!ss_initialized) { |
| 1271 | avtab_cache_init(); |
| 1272 | if (policydb_read(&policydb, fp)) { |
| 1273 | LOAD_UNLOCK; |
| 1274 | avtab_cache_destroy(); |
| 1275 | return -EINVAL; |
| 1276 | } |
| 1277 | if (policydb_load_isids(&policydb, &sidtab)) { |
| 1278 | LOAD_UNLOCK; |
| 1279 | policydb_destroy(&policydb); |
| 1280 | avtab_cache_destroy(); |
| 1281 | return -EINVAL; |
| 1282 | } |
Chad Sellers | b94c7e6 | 2006-11-06 12:38:18 -0500 | [diff] [blame] | 1283 | /* Verify that the kernel defined classes are correct. */ |
| 1284 | if (validate_classes(&policydb)) { |
| 1285 | printk(KERN_ERR |
| 1286 | "security: the definition of a class is incorrect\n"); |
| 1287 | LOAD_UNLOCK; |
| 1288 | sidtab_destroy(&sidtab); |
| 1289 | policydb_destroy(&policydb); |
| 1290 | avtab_cache_destroy(); |
| 1291 | return -EINVAL; |
| 1292 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | policydb_loaded_version = policydb.policyvers; |
| 1294 | ss_initialized = 1; |
Stephen Smalley | 4c443d1 | 2005-05-16 21:53:52 -0700 | [diff] [blame] | 1295 | seqno = ++latest_granting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | LOAD_UNLOCK; |
| 1297 | selinux_complete_init(); |
Stephen Smalley | 4c443d1 | 2005-05-16 21:53:52 -0700 | [diff] [blame] | 1298 | avc_ss_reset(seqno); |
| 1299 | selnl_notify_policyload(seqno); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 1300 | selinux_netlbl_cache_invalidate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | return 0; |
| 1302 | } |
| 1303 | |
| 1304 | #if 0 |
| 1305 | sidtab_hash_eval(&sidtab, "sids"); |
| 1306 | #endif |
| 1307 | |
| 1308 | if (policydb_read(&newpolicydb, fp)) { |
| 1309 | LOAD_UNLOCK; |
| 1310 | return -EINVAL; |
| 1311 | } |
| 1312 | |
| 1313 | sidtab_init(&newsidtab); |
| 1314 | |
Chad Sellers | b94c7e6 | 2006-11-06 12:38:18 -0500 | [diff] [blame] | 1315 | /* Verify that the kernel defined classes are correct. */ |
| 1316 | if (validate_classes(&newpolicydb)) { |
| 1317 | printk(KERN_ERR |
| 1318 | "security: the definition of a class is incorrect\n"); |
| 1319 | rc = -EINVAL; |
| 1320 | goto err; |
| 1321 | } |
| 1322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | /* Clone the SID table. */ |
| 1324 | sidtab_shutdown(&sidtab); |
| 1325 | if (sidtab_map(&sidtab, clone_sid, &newsidtab)) { |
| 1326 | rc = -ENOMEM; |
| 1327 | goto err; |
| 1328 | } |
| 1329 | |
| 1330 | /* Convert the internal representations of contexts |
| 1331 | in the new SID table and remove invalid SIDs. */ |
| 1332 | args.oldp = &policydb; |
| 1333 | args.newp = &newpolicydb; |
| 1334 | sidtab_map_remove_on_error(&newsidtab, convert_context, &args); |
| 1335 | |
| 1336 | /* Save the old policydb and SID table to free later. */ |
| 1337 | memcpy(&oldpolicydb, &policydb, sizeof policydb); |
| 1338 | sidtab_set(&oldsidtab, &sidtab); |
| 1339 | |
| 1340 | /* Install the new policydb and SID table. */ |
| 1341 | POLICY_WRLOCK; |
| 1342 | memcpy(&policydb, &newpolicydb, sizeof policydb); |
| 1343 | sidtab_set(&sidtab, &newsidtab); |
| 1344 | seqno = ++latest_granting; |
| 1345 | policydb_loaded_version = policydb.policyvers; |
| 1346 | POLICY_WRUNLOCK; |
| 1347 | LOAD_UNLOCK; |
| 1348 | |
| 1349 | /* Free the old policydb and SID table. */ |
| 1350 | policydb_destroy(&oldpolicydb); |
| 1351 | sidtab_destroy(&oldsidtab); |
| 1352 | |
| 1353 | avc_ss_reset(seqno); |
| 1354 | selnl_notify_policyload(seqno); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 1355 | selinux_netlbl_cache_invalidate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
| 1357 | return 0; |
| 1358 | |
| 1359 | err: |
| 1360 | LOAD_UNLOCK; |
| 1361 | sidtab_destroy(&newsidtab); |
| 1362 | policydb_destroy(&newpolicydb); |
| 1363 | return rc; |
| 1364 | |
| 1365 | } |
| 1366 | |
| 1367 | /** |
| 1368 | * security_port_sid - Obtain the SID for a port. |
| 1369 | * @domain: communication domain aka address family |
| 1370 | * @type: socket type |
| 1371 | * @protocol: protocol number |
| 1372 | * @port: port number |
| 1373 | * @out_sid: security identifier |
| 1374 | */ |
| 1375 | int security_port_sid(u16 domain, |
| 1376 | u16 type, |
| 1377 | u8 protocol, |
| 1378 | u16 port, |
| 1379 | u32 *out_sid) |
| 1380 | { |
| 1381 | struct ocontext *c; |
| 1382 | int rc = 0; |
| 1383 | |
| 1384 | POLICY_RDLOCK; |
| 1385 | |
| 1386 | c = policydb.ocontexts[OCON_PORT]; |
| 1387 | while (c) { |
| 1388 | if (c->u.port.protocol == protocol && |
| 1389 | c->u.port.low_port <= port && |
| 1390 | c->u.port.high_port >= port) |
| 1391 | break; |
| 1392 | c = c->next; |
| 1393 | } |
| 1394 | |
| 1395 | if (c) { |
| 1396 | if (!c->sid[0]) { |
| 1397 | rc = sidtab_context_to_sid(&sidtab, |
| 1398 | &c->context[0], |
| 1399 | &c->sid[0]); |
| 1400 | if (rc) |
| 1401 | goto out; |
| 1402 | } |
| 1403 | *out_sid = c->sid[0]; |
| 1404 | } else { |
| 1405 | *out_sid = SECINITSID_PORT; |
| 1406 | } |
| 1407 | |
| 1408 | out: |
| 1409 | POLICY_RDUNLOCK; |
| 1410 | return rc; |
| 1411 | } |
| 1412 | |
| 1413 | /** |
| 1414 | * security_netif_sid - Obtain the SID for a network interface. |
| 1415 | * @name: interface name |
| 1416 | * @if_sid: interface SID |
| 1417 | * @msg_sid: default SID for received packets |
| 1418 | */ |
| 1419 | int security_netif_sid(char *name, |
| 1420 | u32 *if_sid, |
| 1421 | u32 *msg_sid) |
| 1422 | { |
| 1423 | int rc = 0; |
| 1424 | struct ocontext *c; |
| 1425 | |
| 1426 | POLICY_RDLOCK; |
| 1427 | |
| 1428 | c = policydb.ocontexts[OCON_NETIF]; |
| 1429 | while (c) { |
| 1430 | if (strcmp(name, c->u.name) == 0) |
| 1431 | break; |
| 1432 | c = c->next; |
| 1433 | } |
| 1434 | |
| 1435 | if (c) { |
| 1436 | if (!c->sid[0] || !c->sid[1]) { |
| 1437 | rc = sidtab_context_to_sid(&sidtab, |
| 1438 | &c->context[0], |
| 1439 | &c->sid[0]); |
| 1440 | if (rc) |
| 1441 | goto out; |
| 1442 | rc = sidtab_context_to_sid(&sidtab, |
| 1443 | &c->context[1], |
| 1444 | &c->sid[1]); |
| 1445 | if (rc) |
| 1446 | goto out; |
| 1447 | } |
| 1448 | *if_sid = c->sid[0]; |
| 1449 | *msg_sid = c->sid[1]; |
| 1450 | } else { |
| 1451 | *if_sid = SECINITSID_NETIF; |
| 1452 | *msg_sid = SECINITSID_NETMSG; |
| 1453 | } |
| 1454 | |
| 1455 | out: |
| 1456 | POLICY_RDUNLOCK; |
| 1457 | return rc; |
| 1458 | } |
| 1459 | |
| 1460 | static int match_ipv6_addrmask(u32 *input, u32 *addr, u32 *mask) |
| 1461 | { |
| 1462 | int i, fail = 0; |
| 1463 | |
| 1464 | for(i = 0; i < 4; i++) |
| 1465 | if(addr[i] != (input[i] & mask[i])) { |
| 1466 | fail = 1; |
| 1467 | break; |
| 1468 | } |
| 1469 | |
| 1470 | return !fail; |
| 1471 | } |
| 1472 | |
| 1473 | /** |
| 1474 | * security_node_sid - Obtain the SID for a node (host). |
| 1475 | * @domain: communication domain aka address family |
| 1476 | * @addrp: address |
| 1477 | * @addrlen: address length in bytes |
| 1478 | * @out_sid: security identifier |
| 1479 | */ |
| 1480 | int security_node_sid(u16 domain, |
| 1481 | void *addrp, |
| 1482 | u32 addrlen, |
| 1483 | u32 *out_sid) |
| 1484 | { |
| 1485 | int rc = 0; |
| 1486 | struct ocontext *c; |
| 1487 | |
| 1488 | POLICY_RDLOCK; |
| 1489 | |
| 1490 | switch (domain) { |
| 1491 | case AF_INET: { |
| 1492 | u32 addr; |
| 1493 | |
| 1494 | if (addrlen != sizeof(u32)) { |
| 1495 | rc = -EINVAL; |
| 1496 | goto out; |
| 1497 | } |
| 1498 | |
| 1499 | addr = *((u32 *)addrp); |
| 1500 | |
| 1501 | c = policydb.ocontexts[OCON_NODE]; |
| 1502 | while (c) { |
| 1503 | if (c->u.node.addr == (addr & c->u.node.mask)) |
| 1504 | break; |
| 1505 | c = c->next; |
| 1506 | } |
| 1507 | break; |
| 1508 | } |
| 1509 | |
| 1510 | case AF_INET6: |
| 1511 | if (addrlen != sizeof(u64) * 2) { |
| 1512 | rc = -EINVAL; |
| 1513 | goto out; |
| 1514 | } |
| 1515 | c = policydb.ocontexts[OCON_NODE6]; |
| 1516 | while (c) { |
| 1517 | if (match_ipv6_addrmask(addrp, c->u.node6.addr, |
| 1518 | c->u.node6.mask)) |
| 1519 | break; |
| 1520 | c = c->next; |
| 1521 | } |
| 1522 | break; |
| 1523 | |
| 1524 | default: |
| 1525 | *out_sid = SECINITSID_NODE; |
| 1526 | goto out; |
| 1527 | } |
| 1528 | |
| 1529 | if (c) { |
| 1530 | if (!c->sid[0]) { |
| 1531 | rc = sidtab_context_to_sid(&sidtab, |
| 1532 | &c->context[0], |
| 1533 | &c->sid[0]); |
| 1534 | if (rc) |
| 1535 | goto out; |
| 1536 | } |
| 1537 | *out_sid = c->sid[0]; |
| 1538 | } else { |
| 1539 | *out_sid = SECINITSID_NODE; |
| 1540 | } |
| 1541 | |
| 1542 | out: |
| 1543 | POLICY_RDUNLOCK; |
| 1544 | return rc; |
| 1545 | } |
| 1546 | |
| 1547 | #define SIDS_NEL 25 |
| 1548 | |
| 1549 | /** |
| 1550 | * security_get_user_sids - Obtain reachable SIDs for a user. |
| 1551 | * @fromsid: starting SID |
| 1552 | * @username: username |
| 1553 | * @sids: array of reachable SIDs for user |
| 1554 | * @nel: number of elements in @sids |
| 1555 | * |
| 1556 | * Generate the set of SIDs for legal security contexts |
| 1557 | * for a given user that can be reached by @fromsid. |
| 1558 | * Set *@sids to point to a dynamically allocated |
| 1559 | * array containing the set of SIDs. Set *@nel to the |
| 1560 | * number of elements in the array. |
| 1561 | */ |
| 1562 | |
| 1563 | int security_get_user_sids(u32 fromsid, |
| 1564 | char *username, |
| 1565 | u32 **sids, |
| 1566 | u32 *nel) |
| 1567 | { |
| 1568 | struct context *fromcon, usercon; |
| 1569 | u32 *mysids, *mysids2, sid; |
| 1570 | u32 mynel = 0, maxnel = SIDS_NEL; |
| 1571 | struct user_datum *user; |
| 1572 | struct role_datum *role; |
| 1573 | struct av_decision avd; |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 1574 | struct ebitmap_node *rnode, *tnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | int rc = 0, i, j; |
| 1576 | |
| 1577 | if (!ss_initialized) { |
| 1578 | *sids = NULL; |
| 1579 | *nel = 0; |
| 1580 | goto out; |
| 1581 | } |
| 1582 | |
| 1583 | POLICY_RDLOCK; |
| 1584 | |
| 1585 | fromcon = sidtab_search(&sidtab, fromsid); |
| 1586 | if (!fromcon) { |
| 1587 | rc = -EINVAL; |
| 1588 | goto out_unlock; |
| 1589 | } |
| 1590 | |
| 1591 | user = hashtab_search(policydb.p_users.table, username); |
| 1592 | if (!user) { |
| 1593 | rc = -EINVAL; |
| 1594 | goto out_unlock; |
| 1595 | } |
| 1596 | usercon.user = user->value; |
| 1597 | |
James Morris | 89d155e | 2005-10-30 14:59:21 -0800 | [diff] [blame] | 1598 | mysids = kcalloc(maxnel, sizeof(*mysids), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | if (!mysids) { |
| 1600 | rc = -ENOMEM; |
| 1601 | goto out_unlock; |
| 1602 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 1604 | ebitmap_for_each_bit(&user->roles, rnode, i) { |
| 1605 | if (!ebitmap_node_get_bit(rnode, i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | continue; |
| 1607 | role = policydb.role_val_to_struct[i]; |
| 1608 | usercon.role = i+1; |
Stephen Smalley | 782ebb9 | 2005-09-03 15:55:16 -0700 | [diff] [blame] | 1609 | ebitmap_for_each_bit(&role->types, tnode, j) { |
| 1610 | if (!ebitmap_node_get_bit(tnode, j)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | continue; |
| 1612 | usercon.type = j+1; |
| 1613 | |
| 1614 | if (mls_setup_user_range(fromcon, user, &usercon)) |
| 1615 | continue; |
| 1616 | |
| 1617 | rc = context_struct_compute_av(fromcon, &usercon, |
| 1618 | SECCLASS_PROCESS, |
| 1619 | PROCESS__TRANSITION, |
| 1620 | &avd); |
| 1621 | if (rc || !(avd.allowed & PROCESS__TRANSITION)) |
| 1622 | continue; |
| 1623 | rc = sidtab_context_to_sid(&sidtab, &usercon, &sid); |
| 1624 | if (rc) { |
| 1625 | kfree(mysids); |
| 1626 | goto out_unlock; |
| 1627 | } |
| 1628 | if (mynel < maxnel) { |
| 1629 | mysids[mynel++] = sid; |
| 1630 | } else { |
| 1631 | maxnel += SIDS_NEL; |
James Morris | 89d155e | 2005-10-30 14:59:21 -0800 | [diff] [blame] | 1632 | mysids2 = kcalloc(maxnel, sizeof(*mysids2), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | if (!mysids2) { |
| 1634 | rc = -ENOMEM; |
| 1635 | kfree(mysids); |
| 1636 | goto out_unlock; |
| 1637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | memcpy(mysids2, mysids, mynel * sizeof(*mysids2)); |
| 1639 | kfree(mysids); |
| 1640 | mysids = mysids2; |
| 1641 | mysids[mynel++] = sid; |
| 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | *sids = mysids; |
| 1647 | *nel = mynel; |
| 1648 | |
| 1649 | out_unlock: |
| 1650 | POLICY_RDUNLOCK; |
| 1651 | out: |
| 1652 | return rc; |
| 1653 | } |
| 1654 | |
| 1655 | /** |
| 1656 | * security_genfs_sid - Obtain a SID for a file in a filesystem |
| 1657 | * @fstype: filesystem type |
| 1658 | * @path: path from root of mount |
| 1659 | * @sclass: file security class |
| 1660 | * @sid: SID for path |
| 1661 | * |
| 1662 | * Obtain a SID to use for a file in a filesystem that |
| 1663 | * cannot support xattr or use a fixed labeling behavior like |
| 1664 | * transition SIDs or task SIDs. |
| 1665 | */ |
| 1666 | int security_genfs_sid(const char *fstype, |
| 1667 | char *path, |
| 1668 | u16 sclass, |
| 1669 | u32 *sid) |
| 1670 | { |
| 1671 | int len; |
| 1672 | struct genfs *genfs; |
| 1673 | struct ocontext *c; |
| 1674 | int rc = 0, cmp = 0; |
| 1675 | |
| 1676 | POLICY_RDLOCK; |
| 1677 | |
| 1678 | for (genfs = policydb.genfs; genfs; genfs = genfs->next) { |
| 1679 | cmp = strcmp(fstype, genfs->fstype); |
| 1680 | if (cmp <= 0) |
| 1681 | break; |
| 1682 | } |
| 1683 | |
| 1684 | if (!genfs || cmp) { |
| 1685 | *sid = SECINITSID_UNLABELED; |
| 1686 | rc = -ENOENT; |
| 1687 | goto out; |
| 1688 | } |
| 1689 | |
| 1690 | for (c = genfs->head; c; c = c->next) { |
| 1691 | len = strlen(c->u.name); |
| 1692 | if ((!c->v.sclass || sclass == c->v.sclass) && |
| 1693 | (strncmp(c->u.name, path, len) == 0)) |
| 1694 | break; |
| 1695 | } |
| 1696 | |
| 1697 | if (!c) { |
| 1698 | *sid = SECINITSID_UNLABELED; |
| 1699 | rc = -ENOENT; |
| 1700 | goto out; |
| 1701 | } |
| 1702 | |
| 1703 | if (!c->sid[0]) { |
| 1704 | rc = sidtab_context_to_sid(&sidtab, |
| 1705 | &c->context[0], |
| 1706 | &c->sid[0]); |
| 1707 | if (rc) |
| 1708 | goto out; |
| 1709 | } |
| 1710 | |
| 1711 | *sid = c->sid[0]; |
| 1712 | out: |
| 1713 | POLICY_RDUNLOCK; |
| 1714 | return rc; |
| 1715 | } |
| 1716 | |
| 1717 | /** |
| 1718 | * security_fs_use - Determine how to handle labeling for a filesystem. |
| 1719 | * @fstype: filesystem type |
| 1720 | * @behavior: labeling behavior |
| 1721 | * @sid: SID for filesystem (superblock) |
| 1722 | */ |
| 1723 | int security_fs_use( |
| 1724 | const char *fstype, |
| 1725 | unsigned int *behavior, |
| 1726 | u32 *sid) |
| 1727 | { |
| 1728 | int rc = 0; |
| 1729 | struct ocontext *c; |
| 1730 | |
| 1731 | POLICY_RDLOCK; |
| 1732 | |
| 1733 | c = policydb.ocontexts[OCON_FSUSE]; |
| 1734 | while (c) { |
| 1735 | if (strcmp(fstype, c->u.name) == 0) |
| 1736 | break; |
| 1737 | c = c->next; |
| 1738 | } |
| 1739 | |
| 1740 | if (c) { |
| 1741 | *behavior = c->v.behavior; |
| 1742 | if (!c->sid[0]) { |
| 1743 | rc = sidtab_context_to_sid(&sidtab, |
| 1744 | &c->context[0], |
| 1745 | &c->sid[0]); |
| 1746 | if (rc) |
| 1747 | goto out; |
| 1748 | } |
| 1749 | *sid = c->sid[0]; |
| 1750 | } else { |
| 1751 | rc = security_genfs_sid(fstype, "/", SECCLASS_DIR, sid); |
| 1752 | if (rc) { |
| 1753 | *behavior = SECURITY_FS_USE_NONE; |
| 1754 | rc = 0; |
| 1755 | } else { |
| 1756 | *behavior = SECURITY_FS_USE_GENFS; |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | out: |
| 1761 | POLICY_RDUNLOCK; |
| 1762 | return rc; |
| 1763 | } |
| 1764 | |
| 1765 | int security_get_bools(int *len, char ***names, int **values) |
| 1766 | { |
| 1767 | int i, rc = -ENOMEM; |
| 1768 | |
| 1769 | POLICY_RDLOCK; |
| 1770 | *names = NULL; |
| 1771 | *values = NULL; |
| 1772 | |
| 1773 | *len = policydb.p_bools.nprim; |
| 1774 | if (!*len) { |
| 1775 | rc = 0; |
| 1776 | goto out; |
| 1777 | } |
| 1778 | |
Jesper Juhl | e0795cf | 2006-01-09 20:54:46 -0800 | [diff] [blame] | 1779 | *names = kcalloc(*len, sizeof(char*), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | if (!*names) |
| 1781 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | |
Jesper Juhl | e0795cf | 2006-01-09 20:54:46 -0800 | [diff] [blame] | 1783 | *values = kcalloc(*len, sizeof(int), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | if (!*values) |
| 1785 | goto err; |
| 1786 | |
| 1787 | for (i = 0; i < *len; i++) { |
| 1788 | size_t name_len; |
| 1789 | (*values)[i] = policydb.bool_val_to_struct[i]->state; |
| 1790 | name_len = strlen(policydb.p_bool_val_to_name[i]) + 1; |
Jesper Juhl | e0795cf | 2006-01-09 20:54:46 -0800 | [diff] [blame] | 1791 | (*names)[i] = kmalloc(sizeof(char) * name_len, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | if (!(*names)[i]) |
| 1793 | goto err; |
| 1794 | strncpy((*names)[i], policydb.p_bool_val_to_name[i], name_len); |
| 1795 | (*names)[i][name_len - 1] = 0; |
| 1796 | } |
| 1797 | rc = 0; |
| 1798 | out: |
| 1799 | POLICY_RDUNLOCK; |
| 1800 | return rc; |
| 1801 | err: |
| 1802 | if (*names) { |
| 1803 | for (i = 0; i < *len; i++) |
Jesper Juhl | 9a5f04b | 2005-06-25 14:58:51 -0700 | [diff] [blame] | 1804 | kfree((*names)[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | } |
Jesper Juhl | 9a5f04b | 2005-06-25 14:58:51 -0700 | [diff] [blame] | 1806 | kfree(*values); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | goto out; |
| 1808 | } |
| 1809 | |
| 1810 | |
| 1811 | int security_set_bools(int len, int *values) |
| 1812 | { |
| 1813 | int i, rc = 0; |
| 1814 | int lenp, seqno = 0; |
| 1815 | struct cond_node *cur; |
| 1816 | |
| 1817 | POLICY_WRLOCK; |
| 1818 | |
| 1819 | lenp = policydb.p_bools.nprim; |
| 1820 | if (len != lenp) { |
| 1821 | rc = -EFAULT; |
| 1822 | goto out; |
| 1823 | } |
| 1824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | for (i = 0; i < len; i++) { |
Steve Grubb | af601e4 | 2006-01-04 14:08:39 +0000 | [diff] [blame] | 1826 | if (!!values[i] != policydb.bool_val_to_struct[i]->state) { |
| 1827 | audit_log(current->audit_context, GFP_ATOMIC, |
| 1828 | AUDIT_MAC_CONFIG_CHANGE, |
| 1829 | "bool=%s val=%d old_val=%d auid=%u", |
| 1830 | policydb.p_bool_val_to_name[i], |
| 1831 | !!values[i], |
| 1832 | policydb.bool_val_to_struct[i]->state, |
| 1833 | audit_get_loginuid(current->audit_context)); |
| 1834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | if (values[i]) { |
| 1836 | policydb.bool_val_to_struct[i]->state = 1; |
| 1837 | } else { |
| 1838 | policydb.bool_val_to_struct[i]->state = 0; |
| 1839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | |
| 1842 | for (cur = policydb.cond_list; cur != NULL; cur = cur->next) { |
| 1843 | rc = evaluate_cond_node(&policydb, cur); |
| 1844 | if (rc) |
| 1845 | goto out; |
| 1846 | } |
| 1847 | |
| 1848 | seqno = ++latest_granting; |
| 1849 | |
| 1850 | out: |
| 1851 | POLICY_WRUNLOCK; |
| 1852 | if (!rc) { |
| 1853 | avc_ss_reset(seqno); |
| 1854 | selnl_notify_policyload(seqno); |
| 1855 | } |
| 1856 | return rc; |
| 1857 | } |
| 1858 | |
| 1859 | int security_get_bool_value(int bool) |
| 1860 | { |
| 1861 | int rc = 0; |
| 1862 | int len; |
| 1863 | |
| 1864 | POLICY_RDLOCK; |
| 1865 | |
| 1866 | len = policydb.p_bools.nprim; |
| 1867 | if (bool >= len) { |
| 1868 | rc = -EFAULT; |
| 1869 | goto out; |
| 1870 | } |
| 1871 | |
| 1872 | rc = policydb.bool_val_to_struct[bool]->state; |
| 1873 | out: |
| 1874 | POLICY_RDUNLOCK; |
| 1875 | return rc; |
| 1876 | } |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 1877 | |
Venkat Yekkirala | 08554d6 | 2006-07-24 23:27:16 -0700 | [diff] [blame] | 1878 | /* |
| 1879 | * security_sid_mls_copy() - computes a new sid based on the given |
| 1880 | * sid and the mls portion of mls_sid. |
| 1881 | */ |
| 1882 | int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid) |
| 1883 | { |
| 1884 | struct context *context1; |
| 1885 | struct context *context2; |
| 1886 | struct context newcon; |
| 1887 | char *s; |
| 1888 | u32 len; |
| 1889 | int rc = 0; |
| 1890 | |
Venkat Yekkirala | 4eb327b | 2006-09-19 10:24:19 -0700 | [diff] [blame] | 1891 | if (!ss_initialized || !selinux_mls_enabled) { |
Venkat Yekkirala | 08554d6 | 2006-07-24 23:27:16 -0700 | [diff] [blame] | 1892 | *new_sid = sid; |
| 1893 | goto out; |
| 1894 | } |
| 1895 | |
| 1896 | context_init(&newcon); |
| 1897 | |
| 1898 | POLICY_RDLOCK; |
| 1899 | context1 = sidtab_search(&sidtab, sid); |
| 1900 | if (!context1) { |
| 1901 | printk(KERN_ERR "security_sid_mls_copy: unrecognized SID " |
| 1902 | "%d\n", sid); |
| 1903 | rc = -EINVAL; |
| 1904 | goto out_unlock; |
| 1905 | } |
| 1906 | |
| 1907 | context2 = sidtab_search(&sidtab, mls_sid); |
| 1908 | if (!context2) { |
| 1909 | printk(KERN_ERR "security_sid_mls_copy: unrecognized SID " |
| 1910 | "%d\n", mls_sid); |
| 1911 | rc = -EINVAL; |
| 1912 | goto out_unlock; |
| 1913 | } |
| 1914 | |
| 1915 | newcon.user = context1->user; |
| 1916 | newcon.role = context1->role; |
| 1917 | newcon.type = context1->type; |
| 1918 | rc = mls_copy_context(&newcon, context2); |
| 1919 | if (rc) |
| 1920 | goto out_unlock; |
| 1921 | |
| 1922 | |
| 1923 | /* Check the validity of the new context. */ |
| 1924 | if (!policydb_context_isvalid(&policydb, &newcon)) { |
| 1925 | rc = convert_context_handle_invalid_context(&newcon); |
| 1926 | if (rc) |
| 1927 | goto bad; |
| 1928 | } |
| 1929 | |
| 1930 | rc = sidtab_context_to_sid(&sidtab, &newcon, new_sid); |
| 1931 | goto out_unlock; |
| 1932 | |
| 1933 | bad: |
| 1934 | if (!context_struct_to_string(&newcon, &s, &len)) { |
| 1935 | audit_log(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR, |
| 1936 | "security_sid_mls_copy: invalid context %s", s); |
| 1937 | kfree(s); |
| 1938 | } |
| 1939 | |
| 1940 | out_unlock: |
| 1941 | POLICY_RDUNLOCK; |
| 1942 | context_destroy(&newcon); |
| 1943 | out: |
| 1944 | return rc; |
| 1945 | } |
| 1946 | |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 1947 | struct selinux_audit_rule { |
| 1948 | u32 au_seqno; |
| 1949 | struct context au_ctxt; |
| 1950 | }; |
| 1951 | |
| 1952 | void selinux_audit_rule_free(struct selinux_audit_rule *rule) |
| 1953 | { |
| 1954 | if (rule) { |
| 1955 | context_destroy(&rule->au_ctxt); |
| 1956 | kfree(rule); |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, |
| 1961 | struct selinux_audit_rule **rule) |
| 1962 | { |
| 1963 | struct selinux_audit_rule *tmprule; |
| 1964 | struct role_datum *roledatum; |
| 1965 | struct type_datum *typedatum; |
| 1966 | struct user_datum *userdatum; |
| 1967 | int rc = 0; |
| 1968 | |
| 1969 | *rule = NULL; |
| 1970 | |
| 1971 | if (!ss_initialized) |
| 1972 | return -ENOTSUPP; |
| 1973 | |
| 1974 | switch (field) { |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 1975 | case AUDIT_SUBJ_USER: |
| 1976 | case AUDIT_SUBJ_ROLE: |
| 1977 | case AUDIT_SUBJ_TYPE: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 1978 | case AUDIT_OBJ_USER: |
| 1979 | case AUDIT_OBJ_ROLE: |
| 1980 | case AUDIT_OBJ_TYPE: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 1981 | /* only 'equals' and 'not equals' fit user, role, and type */ |
| 1982 | if (op != AUDIT_EQUAL && op != AUDIT_NOT_EQUAL) |
| 1983 | return -EINVAL; |
| 1984 | break; |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 1985 | case AUDIT_SUBJ_SEN: |
| 1986 | case AUDIT_SUBJ_CLR: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 1987 | case AUDIT_OBJ_LEV_LOW: |
| 1988 | case AUDIT_OBJ_LEV_HIGH: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 1989 | /* we do not allow a range, indicated by the presense of '-' */ |
| 1990 | if (strchr(rulestr, '-')) |
| 1991 | return -EINVAL; |
| 1992 | break; |
| 1993 | default: |
| 1994 | /* only the above fields are valid */ |
| 1995 | return -EINVAL; |
| 1996 | } |
| 1997 | |
| 1998 | tmprule = kzalloc(sizeof(struct selinux_audit_rule), GFP_KERNEL); |
| 1999 | if (!tmprule) |
| 2000 | return -ENOMEM; |
| 2001 | |
| 2002 | context_init(&tmprule->au_ctxt); |
| 2003 | |
| 2004 | POLICY_RDLOCK; |
| 2005 | |
| 2006 | tmprule->au_seqno = latest_granting; |
| 2007 | |
| 2008 | switch (field) { |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 2009 | case AUDIT_SUBJ_USER: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 2010 | case AUDIT_OBJ_USER: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2011 | userdatum = hashtab_search(policydb.p_users.table, rulestr); |
| 2012 | if (!userdatum) |
| 2013 | rc = -EINVAL; |
| 2014 | else |
| 2015 | tmprule->au_ctxt.user = userdatum->value; |
| 2016 | break; |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 2017 | case AUDIT_SUBJ_ROLE: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 2018 | case AUDIT_OBJ_ROLE: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2019 | roledatum = hashtab_search(policydb.p_roles.table, rulestr); |
| 2020 | if (!roledatum) |
| 2021 | rc = -EINVAL; |
| 2022 | else |
| 2023 | tmprule->au_ctxt.role = roledatum->value; |
| 2024 | break; |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 2025 | case AUDIT_SUBJ_TYPE: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 2026 | case AUDIT_OBJ_TYPE: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2027 | typedatum = hashtab_search(policydb.p_types.table, rulestr); |
| 2028 | if (!typedatum) |
| 2029 | rc = -EINVAL; |
| 2030 | else |
| 2031 | tmprule->au_ctxt.type = typedatum->value; |
| 2032 | break; |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 2033 | case AUDIT_SUBJ_SEN: |
| 2034 | case AUDIT_SUBJ_CLR: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 2035 | case AUDIT_OBJ_LEV_LOW: |
| 2036 | case AUDIT_OBJ_LEV_HIGH: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2037 | rc = mls_from_string(rulestr, &tmprule->au_ctxt, GFP_ATOMIC); |
| 2038 | break; |
| 2039 | } |
| 2040 | |
| 2041 | POLICY_RDUNLOCK; |
| 2042 | |
| 2043 | if (rc) { |
| 2044 | selinux_audit_rule_free(tmprule); |
| 2045 | tmprule = NULL; |
| 2046 | } |
| 2047 | |
| 2048 | *rule = tmprule; |
| 2049 | |
| 2050 | return rc; |
| 2051 | } |
| 2052 | |
Stephen Smalley | 9a2f44f | 2006-09-25 23:31:58 -0700 | [diff] [blame] | 2053 | int selinux_audit_rule_match(u32 sid, u32 field, u32 op, |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2054 | struct selinux_audit_rule *rule, |
| 2055 | struct audit_context *actx) |
| 2056 | { |
| 2057 | struct context *ctxt; |
| 2058 | struct mls_level *level; |
| 2059 | int match = 0; |
| 2060 | |
| 2061 | if (!rule) { |
| 2062 | audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR, |
| 2063 | "selinux_audit_rule_match: missing rule\n"); |
| 2064 | return -ENOENT; |
| 2065 | } |
| 2066 | |
| 2067 | POLICY_RDLOCK; |
| 2068 | |
| 2069 | if (rule->au_seqno < latest_granting) { |
| 2070 | audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR, |
| 2071 | "selinux_audit_rule_match: stale rule\n"); |
| 2072 | match = -ESTALE; |
| 2073 | goto out; |
| 2074 | } |
| 2075 | |
Stephen Smalley | 9a2f44f | 2006-09-25 23:31:58 -0700 | [diff] [blame] | 2076 | ctxt = sidtab_search(&sidtab, sid); |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2077 | if (!ctxt) { |
| 2078 | audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR, |
| 2079 | "selinux_audit_rule_match: unrecognized SID %d\n", |
Stephen Smalley | 9a2f44f | 2006-09-25 23:31:58 -0700 | [diff] [blame] | 2080 | sid); |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2081 | match = -ENOENT; |
| 2082 | goto out; |
| 2083 | } |
| 2084 | |
| 2085 | /* a field/op pair that is not caught here will simply fall through |
| 2086 | without a match */ |
| 2087 | switch (field) { |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 2088 | case AUDIT_SUBJ_USER: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 2089 | case AUDIT_OBJ_USER: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2090 | switch (op) { |
| 2091 | case AUDIT_EQUAL: |
| 2092 | match = (ctxt->user == rule->au_ctxt.user); |
| 2093 | break; |
| 2094 | case AUDIT_NOT_EQUAL: |
| 2095 | match = (ctxt->user != rule->au_ctxt.user); |
| 2096 | break; |
| 2097 | } |
| 2098 | break; |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 2099 | case AUDIT_SUBJ_ROLE: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 2100 | case AUDIT_OBJ_ROLE: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2101 | switch (op) { |
| 2102 | case AUDIT_EQUAL: |
| 2103 | match = (ctxt->role == rule->au_ctxt.role); |
| 2104 | break; |
| 2105 | case AUDIT_NOT_EQUAL: |
| 2106 | match = (ctxt->role != rule->au_ctxt.role); |
| 2107 | break; |
| 2108 | } |
| 2109 | break; |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 2110 | case AUDIT_SUBJ_TYPE: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 2111 | case AUDIT_OBJ_TYPE: |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2112 | switch (op) { |
| 2113 | case AUDIT_EQUAL: |
| 2114 | match = (ctxt->type == rule->au_ctxt.type); |
| 2115 | break; |
| 2116 | case AUDIT_NOT_EQUAL: |
| 2117 | match = (ctxt->type != rule->au_ctxt.type); |
| 2118 | break; |
| 2119 | } |
| 2120 | break; |
Darrel Goeddel | 3a6b9f8 | 2006-06-29 16:56:39 -0500 | [diff] [blame] | 2121 | case AUDIT_SUBJ_SEN: |
| 2122 | case AUDIT_SUBJ_CLR: |
Darrel Goeddel | 6e5a2d1 | 2006-06-29 16:57:08 -0500 | [diff] [blame] | 2123 | case AUDIT_OBJ_LEV_LOW: |
| 2124 | case AUDIT_OBJ_LEV_HIGH: |
| 2125 | level = ((field == AUDIT_SUBJ_SEN || |
| 2126 | field == AUDIT_OBJ_LEV_LOW) ? |
Darrel Goeddel | 376bd9c | 2006-02-24 15:44:05 -0600 | [diff] [blame] | 2127 | &ctxt->range.level[0] : &ctxt->range.level[1]); |
| 2128 | switch (op) { |
| 2129 | case AUDIT_EQUAL: |
| 2130 | match = mls_level_eq(&rule->au_ctxt.range.level[0], |
| 2131 | level); |
| 2132 | break; |
| 2133 | case AUDIT_NOT_EQUAL: |
| 2134 | match = !mls_level_eq(&rule->au_ctxt.range.level[0], |
| 2135 | level); |
| 2136 | break; |
| 2137 | case AUDIT_LESS_THAN: |
| 2138 | match = (mls_level_dom(&rule->au_ctxt.range.level[0], |
| 2139 | level) && |
| 2140 | !mls_level_eq(&rule->au_ctxt.range.level[0], |
| 2141 | level)); |
| 2142 | break; |
| 2143 | case AUDIT_LESS_THAN_OR_EQUAL: |
| 2144 | match = mls_level_dom(&rule->au_ctxt.range.level[0], |
| 2145 | level); |
| 2146 | break; |
| 2147 | case AUDIT_GREATER_THAN: |
| 2148 | match = (mls_level_dom(level, |
| 2149 | &rule->au_ctxt.range.level[0]) && |
| 2150 | !mls_level_eq(level, |
| 2151 | &rule->au_ctxt.range.level[0])); |
| 2152 | break; |
| 2153 | case AUDIT_GREATER_THAN_OR_EQUAL: |
| 2154 | match = mls_level_dom(level, |
| 2155 | &rule->au_ctxt.range.level[0]); |
| 2156 | break; |
| 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | out: |
| 2161 | POLICY_RDUNLOCK; |
| 2162 | return match; |
| 2163 | } |
| 2164 | |
| 2165 | static int (*aurule_callback)(void) = NULL; |
| 2166 | |
| 2167 | static int aurule_avc_callback(u32 event, u32 ssid, u32 tsid, |
| 2168 | u16 class, u32 perms, u32 *retained) |
| 2169 | { |
| 2170 | int err = 0; |
| 2171 | |
| 2172 | if (event == AVC_CALLBACK_RESET && aurule_callback) |
| 2173 | err = aurule_callback(); |
| 2174 | return err; |
| 2175 | } |
| 2176 | |
| 2177 | static int __init aurule_init(void) |
| 2178 | { |
| 2179 | int err; |
| 2180 | |
| 2181 | err = avc_add_callback(aurule_avc_callback, AVC_CALLBACK_RESET, |
| 2182 | SECSID_NULL, SECSID_NULL, SECCLASS_NULL, 0); |
| 2183 | if (err) |
| 2184 | panic("avc_add_callback() failed, error %d\n", err); |
| 2185 | |
| 2186 | return err; |
| 2187 | } |
| 2188 | __initcall(aurule_init); |
| 2189 | |
| 2190 | void selinux_audit_set_callback(int (*callback)(void)) |
| 2191 | { |
| 2192 | aurule_callback = callback; |
| 2193 | } |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2194 | |
Paul Moore | 3de4bab | 2006-11-17 17:38:54 -0500 | [diff] [blame^] | 2195 | /** |
| 2196 | * security_skb_extlbl_sid - Determine the external label of a packet |
| 2197 | * @skb: the packet |
| 2198 | * @base_sid: the SELinux SID to use as a context for MLS only external labels |
| 2199 | * @sid: the packet's SID |
| 2200 | * |
| 2201 | * Description: |
| 2202 | * Check the various different forms of external packet labeling and determine |
| 2203 | * the external SID for the packet. |
| 2204 | * |
| 2205 | */ |
| 2206 | void security_skb_extlbl_sid(struct sk_buff *skb, u32 base_sid, u32 *sid) |
| 2207 | { |
| 2208 | u32 xfrm_sid; |
| 2209 | u32 nlbl_sid; |
| 2210 | |
| 2211 | selinux_skb_xfrm_sid(skb, &xfrm_sid); |
| 2212 | if (selinux_netlbl_skbuff_getsid(skb, |
| 2213 | (xfrm_sid == SECSID_NULL ? |
| 2214 | base_sid : xfrm_sid), |
| 2215 | &nlbl_sid) != 0) |
| 2216 | nlbl_sid = SECSID_NULL; |
| 2217 | |
| 2218 | *sid = (nlbl_sid == SECSID_NULL ? xfrm_sid : nlbl_sid); |
| 2219 | } |
| 2220 | |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2221 | #ifdef CONFIG_NETLABEL |
| 2222 | /* |
| 2223 | * This is the structure we store inside the NetLabel cache block. |
| 2224 | */ |
| 2225 | #define NETLBL_CACHE(x) ((struct netlbl_cache *)(x)) |
| 2226 | #define NETLBL_CACHE_T_NONE 0 |
| 2227 | #define NETLBL_CACHE_T_SID 1 |
| 2228 | #define NETLBL_CACHE_T_MLS 2 |
| 2229 | struct netlbl_cache { |
| 2230 | u32 type; |
| 2231 | union { |
| 2232 | u32 sid; |
| 2233 | struct mls_range mls_label; |
| 2234 | } data; |
| 2235 | }; |
| 2236 | |
| 2237 | /** |
| 2238 | * selinux_netlbl_cache_free - Free the NetLabel cached data |
| 2239 | * @data: the data to free |
| 2240 | * |
| 2241 | * Description: |
| 2242 | * This function is intended to be used as the free() callback inside the |
| 2243 | * netlbl_lsm_cache structure. |
| 2244 | * |
| 2245 | */ |
| 2246 | static void selinux_netlbl_cache_free(const void *data) |
| 2247 | { |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2248 | struct netlbl_cache *cache; |
| 2249 | |
| 2250 | if (data == NULL) |
| 2251 | return; |
| 2252 | |
| 2253 | cache = NETLBL_CACHE(data); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2254 | switch (cache->type) { |
| 2255 | case NETLBL_CACHE_T_MLS: |
| 2256 | ebitmap_destroy(&cache->data.mls_label.level[0].cat); |
| 2257 | break; |
| 2258 | } |
| 2259 | kfree(data); |
| 2260 | } |
| 2261 | |
| 2262 | /** |
| 2263 | * selinux_netlbl_cache_add - Add an entry to the NetLabel cache |
| 2264 | * @skb: the packet |
| 2265 | * @ctx: the SELinux context |
| 2266 | * |
| 2267 | * Description: |
| 2268 | * Attempt to cache the context in @ctx, which was derived from the packet in |
| 2269 | * @skb, in the NetLabel subsystem cache. |
| 2270 | * |
| 2271 | */ |
| 2272 | static void selinux_netlbl_cache_add(struct sk_buff *skb, struct context *ctx) |
| 2273 | { |
| 2274 | struct netlbl_cache *cache = NULL; |
| 2275 | struct netlbl_lsm_secattr secattr; |
| 2276 | |
| 2277 | netlbl_secattr_init(&secattr); |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2278 | secattr.cache = netlbl_secattr_cache_alloc(GFP_ATOMIC); |
| 2279 | if (secattr.cache == NULL) |
| 2280 | goto netlbl_cache_add_return; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2281 | |
| 2282 | cache = kzalloc(sizeof(*cache), GFP_ATOMIC); |
| 2283 | if (cache == NULL) |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2284 | goto netlbl_cache_add_return; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2285 | |
| 2286 | cache->type = NETLBL_CACHE_T_MLS; |
| 2287 | if (ebitmap_cpy(&cache->data.mls_label.level[0].cat, |
| 2288 | &ctx->range.level[0].cat) != 0) |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2289 | goto netlbl_cache_add_return; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2290 | cache->data.mls_label.level[1].cat.highbit = |
| 2291 | cache->data.mls_label.level[0].cat.highbit; |
| 2292 | cache->data.mls_label.level[1].cat.node = |
| 2293 | cache->data.mls_label.level[0].cat.node; |
| 2294 | cache->data.mls_label.level[0].sens = ctx->range.level[0].sens; |
| 2295 | cache->data.mls_label.level[1].sens = ctx->range.level[0].sens; |
| 2296 | |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2297 | secattr.cache->free = selinux_netlbl_cache_free; |
| 2298 | secattr.cache->data = (void *)cache; |
| 2299 | secattr.flags = NETLBL_SECATTR_CACHE; |
| 2300 | |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2301 | netlbl_cache_add(skb, &secattr); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2302 | |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2303 | netlbl_cache_add_return: |
| 2304 | netlbl_secattr_destroy(&secattr); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | /** |
| 2308 | * selinux_netlbl_cache_invalidate - Invalidate the NetLabel cache |
| 2309 | * |
| 2310 | * Description: |
| 2311 | * Invalidate the NetLabel security attribute mapping cache. |
| 2312 | * |
| 2313 | */ |
| 2314 | void selinux_netlbl_cache_invalidate(void) |
| 2315 | { |
| 2316 | netlbl_cache_invalidate(); |
| 2317 | } |
| 2318 | |
| 2319 | /** |
| 2320 | * selinux_netlbl_secattr_to_sid - Convert a NetLabel secattr to a SELinux SID |
| 2321 | * @skb: the network packet |
| 2322 | * @secattr: the NetLabel packet security attributes |
| 2323 | * @base_sid: the SELinux SID to use as a context for MLS only attributes |
| 2324 | * @sid: the SELinux SID |
| 2325 | * |
| 2326 | * Description: |
| 2327 | * Convert the given NetLabel packet security attributes in @secattr into a |
| 2328 | * SELinux SID. If the @secattr field does not contain a full SELinux |
| 2329 | * SID/context then use the context in @base_sid as the foundation. If @skb |
| 2330 | * is not NULL attempt to cache as much data as possibile. Returns zero on |
| 2331 | * success, negative values on failure. |
| 2332 | * |
| 2333 | */ |
| 2334 | static int selinux_netlbl_secattr_to_sid(struct sk_buff *skb, |
| 2335 | struct netlbl_lsm_secattr *secattr, |
| 2336 | u32 base_sid, |
| 2337 | u32 *sid) |
| 2338 | { |
| 2339 | int rc = -EIDRM; |
| 2340 | struct context *ctx; |
| 2341 | struct context ctx_new; |
| 2342 | struct netlbl_cache *cache; |
| 2343 | |
| 2344 | POLICY_RDLOCK; |
| 2345 | |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2346 | if (secattr->flags & NETLBL_SECATTR_CACHE) { |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2347 | cache = NETLBL_CACHE(secattr->cache->data); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2348 | switch (cache->type) { |
| 2349 | case NETLBL_CACHE_T_SID: |
| 2350 | *sid = cache->data.sid; |
| 2351 | rc = 0; |
| 2352 | break; |
| 2353 | case NETLBL_CACHE_T_MLS: |
| 2354 | ctx = sidtab_search(&sidtab, base_sid); |
| 2355 | if (ctx == NULL) |
| 2356 | goto netlbl_secattr_to_sid_return; |
| 2357 | |
| 2358 | ctx_new.user = ctx->user; |
| 2359 | ctx_new.role = ctx->role; |
| 2360 | ctx_new.type = ctx->type; |
| 2361 | ctx_new.range.level[0].sens = |
| 2362 | cache->data.mls_label.level[0].sens; |
| 2363 | ctx_new.range.level[0].cat.highbit = |
| 2364 | cache->data.mls_label.level[0].cat.highbit; |
| 2365 | ctx_new.range.level[0].cat.node = |
| 2366 | cache->data.mls_label.level[0].cat.node; |
| 2367 | ctx_new.range.level[1].sens = |
| 2368 | cache->data.mls_label.level[1].sens; |
| 2369 | ctx_new.range.level[1].cat.highbit = |
| 2370 | cache->data.mls_label.level[1].cat.highbit; |
| 2371 | ctx_new.range.level[1].cat.node = |
| 2372 | cache->data.mls_label.level[1].cat.node; |
| 2373 | |
| 2374 | rc = sidtab_context_to_sid(&sidtab, &ctx_new, sid); |
| 2375 | break; |
| 2376 | default: |
| 2377 | goto netlbl_secattr_to_sid_return; |
| 2378 | } |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2379 | } else if (secattr->flags & NETLBL_SECATTR_MLS_LVL) { |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2380 | ctx = sidtab_search(&sidtab, base_sid); |
| 2381 | if (ctx == NULL) |
| 2382 | goto netlbl_secattr_to_sid_return; |
| 2383 | |
| 2384 | ctx_new.user = ctx->user; |
| 2385 | ctx_new.role = ctx->role; |
| 2386 | ctx_new.type = ctx->type; |
| 2387 | mls_import_lvl(&ctx_new, secattr->mls_lvl, secattr->mls_lvl); |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2388 | if (secattr->flags & NETLBL_SECATTR_MLS_CAT) { |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2389 | if (mls_import_cat(&ctx_new, |
| 2390 | secattr->mls_cat, |
| 2391 | secattr->mls_cat_len, |
| 2392 | NULL, |
| 2393 | 0) != 0) |
| 2394 | goto netlbl_secattr_to_sid_return; |
| 2395 | ctx_new.range.level[1].cat.highbit = |
| 2396 | ctx_new.range.level[0].cat.highbit; |
| 2397 | ctx_new.range.level[1].cat.node = |
| 2398 | ctx_new.range.level[0].cat.node; |
| 2399 | } else { |
| 2400 | ebitmap_init(&ctx_new.range.level[0].cat); |
| 2401 | ebitmap_init(&ctx_new.range.level[1].cat); |
| 2402 | } |
| 2403 | if (mls_context_isvalid(&policydb, &ctx_new) != 1) |
| 2404 | goto netlbl_secattr_to_sid_return_cleanup; |
| 2405 | |
| 2406 | rc = sidtab_context_to_sid(&sidtab, &ctx_new, sid); |
| 2407 | if (rc != 0) |
| 2408 | goto netlbl_secattr_to_sid_return_cleanup; |
| 2409 | |
| 2410 | if (skb != NULL) |
| 2411 | selinux_netlbl_cache_add(skb, &ctx_new); |
| 2412 | ebitmap_destroy(&ctx_new.range.level[0].cat); |
| 2413 | } else { |
paul.moore@hp.com | 388b240 | 2006-10-05 18:28:24 -0400 | [diff] [blame] | 2414 | *sid = SECSID_NULL; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2415 | rc = 0; |
| 2416 | } |
| 2417 | |
| 2418 | netlbl_secattr_to_sid_return: |
| 2419 | POLICY_RDUNLOCK; |
| 2420 | return rc; |
| 2421 | netlbl_secattr_to_sid_return_cleanup: |
| 2422 | ebitmap_destroy(&ctx_new.range.level[0].cat); |
| 2423 | goto netlbl_secattr_to_sid_return; |
| 2424 | } |
| 2425 | |
| 2426 | /** |
| 2427 | * selinux_netlbl_skbuff_getsid - Get the sid of a packet using NetLabel |
| 2428 | * @skb: the packet |
| 2429 | * @base_sid: the SELinux SID to use as a context for MLS only attributes |
| 2430 | * @sid: the SID |
| 2431 | * |
| 2432 | * Description: |
| 2433 | * Call the NetLabel mechanism to get the security attributes of the given |
| 2434 | * packet and use those attributes to determine the correct context/SID to |
| 2435 | * assign to the packet. Returns zero on success, negative values on failure. |
| 2436 | * |
| 2437 | */ |
Paul Moore | 3de4bab | 2006-11-17 17:38:54 -0500 | [diff] [blame^] | 2438 | int selinux_netlbl_skbuff_getsid(struct sk_buff *skb, u32 base_sid, u32 *sid) |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2439 | { |
| 2440 | int rc; |
| 2441 | struct netlbl_lsm_secattr secattr; |
| 2442 | |
| 2443 | netlbl_secattr_init(&secattr); |
| 2444 | rc = netlbl_skbuff_getattr(skb, &secattr); |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2445 | if (rc == 0 && secattr.flags != NETLBL_SECATTR_NONE) |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2446 | rc = selinux_netlbl_secattr_to_sid(skb, |
| 2447 | &secattr, |
| 2448 | base_sid, |
| 2449 | sid); |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2450 | else |
| 2451 | *sid = SECSID_NULL; |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2452 | netlbl_secattr_destroy(&secattr); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2453 | |
| 2454 | return rc; |
| 2455 | } |
| 2456 | |
| 2457 | /** |
| 2458 | * selinux_netlbl_socket_setsid - Label a socket using the NetLabel mechanism |
| 2459 | * @sock: the socket to label |
| 2460 | * @sid: the SID to use |
| 2461 | * |
| 2462 | * Description: |
| 2463 | * Attempt to label a socket using the NetLabel mechanism using the given |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2464 | * SID. Returns zero values on success, negative values on failure. The |
| 2465 | * caller is responsibile for calling rcu_read_lock() before calling this |
| 2466 | * this function and rcu_read_unlock() after this function returns. |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2467 | * |
| 2468 | */ |
| 2469 | static int selinux_netlbl_socket_setsid(struct socket *sock, u32 sid) |
| 2470 | { |
| 2471 | int rc = -ENOENT; |
| 2472 | struct sk_security_struct *sksec = sock->sk->sk_security; |
| 2473 | struct netlbl_lsm_secattr secattr; |
| 2474 | struct context *ctx; |
| 2475 | |
| 2476 | if (!ss_initialized) |
| 2477 | return 0; |
| 2478 | |
Paul Moore | bf0edf3 | 2006-10-11 19:10:48 -0400 | [diff] [blame] | 2479 | netlbl_secattr_init(&secattr); |
| 2480 | |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2481 | POLICY_RDLOCK; |
| 2482 | |
| 2483 | ctx = sidtab_search(&sidtab, sid); |
| 2484 | if (ctx == NULL) |
| 2485 | goto netlbl_socket_setsid_return; |
| 2486 | |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2487 | secattr.domain = kstrdup(policydb.p_type_val_to_name[ctx->type - 1], |
| 2488 | GFP_ATOMIC); |
| 2489 | mls_export_lvl(ctx, &secattr.mls_lvl, NULL); |
Paul Moore | bf0edf3 | 2006-10-11 19:10:48 -0400 | [diff] [blame] | 2490 | rc = mls_export_cat(ctx, |
| 2491 | &secattr.mls_cat, |
| 2492 | &secattr.mls_cat_len, |
| 2493 | NULL, |
| 2494 | NULL); |
| 2495 | if (rc != 0) |
| 2496 | goto netlbl_socket_setsid_return; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2497 | |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2498 | secattr.flags |= NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL; |
| 2499 | if (secattr.mls_cat) |
| 2500 | secattr.flags |= NETLBL_SECATTR_MLS_CAT; |
| 2501 | |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2502 | rc = netlbl_socket_setattr(sock, &secattr); |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2503 | if (rc == 0) { |
| 2504 | spin_lock(&sksec->nlbl_lock); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2505 | sksec->nlbl_state = NLBL_LABELED; |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2506 | spin_unlock(&sksec->nlbl_lock); |
| 2507 | } |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2508 | |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2509 | netlbl_socket_setsid_return: |
| 2510 | POLICY_RDUNLOCK; |
Paul Moore | bf0edf3 | 2006-10-11 19:10:48 -0400 | [diff] [blame] | 2511 | netlbl_secattr_destroy(&secattr); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2512 | return rc; |
| 2513 | } |
| 2514 | |
| 2515 | /** |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2516 | * selinux_netlbl_sk_security_reset - Reset the NetLabel fields |
| 2517 | * @ssec: the sk_security_struct |
| 2518 | * @family: the socket family |
| 2519 | * |
| 2520 | * Description: |
| 2521 | * Called when the NetLabel state of a sk_security_struct needs to be reset. |
| 2522 | * The caller is responsibile for all the NetLabel sk_security_struct locking. |
| 2523 | * |
| 2524 | */ |
| 2525 | void selinux_netlbl_sk_security_reset(struct sk_security_struct *ssec, |
| 2526 | int family) |
| 2527 | { |
| 2528 | if (family == PF_INET) |
| 2529 | ssec->nlbl_state = NLBL_REQUIRE; |
| 2530 | else |
| 2531 | ssec->nlbl_state = NLBL_UNSET; |
| 2532 | } |
| 2533 | |
| 2534 | /** |
Paul Moore | 99f59ed | 2006-08-29 17:53:48 -0700 | [diff] [blame] | 2535 | * selinux_netlbl_sk_security_init - Setup the NetLabel fields |
| 2536 | * @ssec: the sk_security_struct |
| 2537 | * @family: the socket family |
| 2538 | * |
| 2539 | * Description: |
| 2540 | * Called when a new sk_security_struct is allocated to initialize the NetLabel |
| 2541 | * fields. |
| 2542 | * |
| 2543 | */ |
| 2544 | void selinux_netlbl_sk_security_init(struct sk_security_struct *ssec, |
| 2545 | int family) |
| 2546 | { |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2547 | /* No locking needed, we are the only one who has access to ssec */ |
| 2548 | selinux_netlbl_sk_security_reset(ssec, family); |
| 2549 | spin_lock_init(&ssec->nlbl_lock); |
Paul Moore | 99f59ed | 2006-08-29 17:53:48 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | /** |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2553 | * selinux_netlbl_sk_security_clone - Copy the NetLabel fields |
Paul Moore | 99f59ed | 2006-08-29 17:53:48 -0700 | [diff] [blame] | 2554 | * @ssec: the original sk_security_struct |
| 2555 | * @newssec: the cloned sk_security_struct |
| 2556 | * |
| 2557 | * Description: |
| 2558 | * Clone the NetLabel specific sk_security_struct fields from @ssec to |
| 2559 | * @newssec. |
| 2560 | * |
| 2561 | */ |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2562 | void selinux_netlbl_sk_security_clone(struct sk_security_struct *ssec, |
Paul Moore | 99f59ed | 2006-08-29 17:53:48 -0700 | [diff] [blame] | 2563 | struct sk_security_struct *newssec) |
| 2564 | { |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2565 | /* We don't need to take newssec->nlbl_lock because we are the only |
| 2566 | * thread with access to newssec, but we do need to take the RCU read |
| 2567 | * lock as other threads could have access to ssec */ |
| 2568 | rcu_read_lock(); |
| 2569 | selinux_netlbl_sk_security_reset(newssec, ssec->sk->sk_family); |
Paul Moore | 99f59ed | 2006-08-29 17:53:48 -0700 | [diff] [blame] | 2570 | newssec->sclass = ssec->sclass; |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2571 | rcu_read_unlock(); |
Paul Moore | 99f59ed | 2006-08-29 17:53:48 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | /** |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2575 | * selinux_netlbl_socket_post_create - Label a socket using NetLabel |
| 2576 | * @sock: the socket to label |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2577 | * |
| 2578 | * Description: |
| 2579 | * Attempt to label a socket using the NetLabel mechanism using the given |
| 2580 | * SID. Returns zero values on success, negative values on failure. |
| 2581 | * |
| 2582 | */ |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2583 | int selinux_netlbl_socket_post_create(struct socket *sock) |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2584 | { |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2585 | int rc = 0; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2586 | struct inode_security_struct *isec = SOCK_INODE(sock)->i_security; |
| 2587 | struct sk_security_struct *sksec = sock->sk->sk_security; |
| 2588 | |
Paul Moore | 99f59ed | 2006-08-29 17:53:48 -0700 | [diff] [blame] | 2589 | sksec->sclass = isec->sclass; |
| 2590 | |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2591 | rcu_read_lock(); |
| 2592 | if (sksec->nlbl_state == NLBL_REQUIRE) |
| 2593 | rc = selinux_netlbl_socket_setsid(sock, sksec->sid); |
| 2594 | rcu_read_unlock(); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2595 | |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2596 | return rc; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | /** |
| 2600 | * selinux_netlbl_sock_graft - Netlabel the new socket |
| 2601 | * @sk: the new connection |
| 2602 | * @sock: the new socket |
| 2603 | * |
| 2604 | * Description: |
| 2605 | * The connection represented by @sk is being grafted onto @sock so set the |
| 2606 | * socket's NetLabel to match the SID of @sk. |
| 2607 | * |
| 2608 | */ |
| 2609 | void selinux_netlbl_sock_graft(struct sock *sk, struct socket *sock) |
| 2610 | { |
| 2611 | struct inode_security_struct *isec = SOCK_INODE(sock)->i_security; |
| 2612 | struct sk_security_struct *sksec = sk->sk_security; |
Paul Moore | 14a72f5 | 2006-09-25 15:52:01 -0700 | [diff] [blame] | 2613 | struct netlbl_lsm_secattr secattr; |
| 2614 | u32 nlbl_peer_sid; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2615 | |
Paul Moore | 99f59ed | 2006-08-29 17:53:48 -0700 | [diff] [blame] | 2616 | sksec->sclass = isec->sclass; |
| 2617 | |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2618 | rcu_read_lock(); |
| 2619 | |
| 2620 | if (sksec->nlbl_state != NLBL_REQUIRE) { |
| 2621 | rcu_read_unlock(); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2622 | return; |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2623 | } |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2624 | |
Paul Moore | 14a72f5 | 2006-09-25 15:52:01 -0700 | [diff] [blame] | 2625 | netlbl_secattr_init(&secattr); |
| 2626 | if (netlbl_sock_getattr(sk, &secattr) == 0 && |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2627 | secattr.flags != NETLBL_SECATTR_NONE && |
Paul Moore | 14a72f5 | 2006-09-25 15:52:01 -0700 | [diff] [blame] | 2628 | selinux_netlbl_secattr_to_sid(NULL, |
| 2629 | &secattr, |
paul.moore@hp.com | 388b240 | 2006-10-05 18:28:24 -0400 | [diff] [blame] | 2630 | SECINITSID_UNLABELED, |
Paul Moore | 14a72f5 | 2006-09-25 15:52:01 -0700 | [diff] [blame] | 2631 | &nlbl_peer_sid) == 0) |
| 2632 | sksec->peer_sid = nlbl_peer_sid; |
paul.moore@hp.com | ffb733c | 2006-10-04 11:46:31 -0400 | [diff] [blame] | 2633 | netlbl_secattr_destroy(&secattr); |
Paul Moore | 14a72f5 | 2006-09-25 15:52:01 -0700 | [diff] [blame] | 2634 | |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2635 | /* Try to set the NetLabel on the socket to save time later, if we fail |
| 2636 | * here we will pick up the pieces in later calls to |
| 2637 | * selinux_netlbl_inode_permission(). */ |
| 2638 | selinux_netlbl_socket_setsid(sock, sksec->sid); |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2639 | |
| 2640 | rcu_read_unlock(); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | /** |
Paul Moore | e448e93 | 2006-08-29 17:55:38 -0700 | [diff] [blame] | 2644 | * selinux_netlbl_inode_permission - Verify the socket is NetLabel labeled |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2645 | * @inode: the file descriptor's inode |
| 2646 | * @mask: the permission mask |
| 2647 | * |
| 2648 | * Description: |
Paul Moore | e448e93 | 2006-08-29 17:55:38 -0700 | [diff] [blame] | 2649 | * Looks at a file's inode and if it is marked as a socket protected by |
| 2650 | * NetLabel then verify that the socket has been labeled, if not try to label |
| 2651 | * the socket now with the inode's SID. Returns zero on success, negative |
| 2652 | * values on failure. |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2653 | * |
| 2654 | */ |
Paul Moore | e448e93 | 2006-08-29 17:55:38 -0700 | [diff] [blame] | 2655 | int selinux_netlbl_inode_permission(struct inode *inode, int mask) |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2656 | { |
| 2657 | int rc; |
Paul Moore | e448e93 | 2006-08-29 17:55:38 -0700 | [diff] [blame] | 2658 | struct sk_security_struct *sksec; |
| 2659 | struct socket *sock; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2660 | |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2661 | if (!S_ISSOCK(inode->i_mode) || |
| 2662 | ((mask & (MAY_WRITE | MAY_APPEND)) == 0)) |
Paul Moore | e448e93 | 2006-08-29 17:55:38 -0700 | [diff] [blame] | 2663 | return 0; |
Paul Moore | e448e93 | 2006-08-29 17:55:38 -0700 | [diff] [blame] | 2664 | sock = SOCKET_I(inode); |
Paul Moore | e448e93 | 2006-08-29 17:55:38 -0700 | [diff] [blame] | 2665 | sksec = sock->sk->sk_security; |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2666 | |
| 2667 | rcu_read_lock(); |
| 2668 | if (sksec->nlbl_state != NLBL_REQUIRE) { |
| 2669 | rcu_read_unlock(); |
| 2670 | return 0; |
| 2671 | } |
| 2672 | lock_sock(sock->sk); |
| 2673 | rc = selinux_netlbl_socket_setsid(sock, sksec->sid); |
| 2674 | release_sock(sock->sk); |
| 2675 | rcu_read_unlock(); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2676 | |
| 2677 | return rc; |
| 2678 | } |
| 2679 | |
| 2680 | /** |
| 2681 | * selinux_netlbl_sock_rcv_skb - Do an inbound access check using NetLabel |
| 2682 | * @sksec: the sock's sk_security_struct |
| 2683 | * @skb: the packet |
| 2684 | * @ad: the audit data |
| 2685 | * |
| 2686 | * Description: |
| 2687 | * Fetch the NetLabel security attributes from @skb and perform an access check |
| 2688 | * against the receiving socket. Returns zero on success, negative values on |
| 2689 | * error. |
| 2690 | * |
| 2691 | */ |
| 2692 | int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec, |
| 2693 | struct sk_buff *skb, |
| 2694 | struct avc_audit_data *ad) |
| 2695 | { |
| 2696 | int rc; |
| 2697 | u32 netlbl_sid; |
| 2698 | u32 recv_perm; |
| 2699 | |
paul.moore@hp.com | 388b240 | 2006-10-05 18:28:24 -0400 | [diff] [blame] | 2700 | rc = selinux_netlbl_skbuff_getsid(skb, |
| 2701 | SECINITSID_UNLABELED, |
| 2702 | &netlbl_sid); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2703 | if (rc != 0) |
| 2704 | return rc; |
| 2705 | |
paul.moore@hp.com | 388b240 | 2006-10-05 18:28:24 -0400 | [diff] [blame] | 2706 | if (netlbl_sid == SECSID_NULL) |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2707 | return 0; |
| 2708 | |
| 2709 | switch (sksec->sclass) { |
| 2710 | case SECCLASS_UDP_SOCKET: |
Paul Moore | df2115c | 2006-09-25 15:53:13 -0700 | [diff] [blame] | 2711 | recv_perm = UDP_SOCKET__RECVFROM; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2712 | break; |
| 2713 | case SECCLASS_TCP_SOCKET: |
Paul Moore | df2115c | 2006-09-25 15:53:13 -0700 | [diff] [blame] | 2714 | recv_perm = TCP_SOCKET__RECVFROM; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2715 | break; |
| 2716 | default: |
Paul Moore | df2115c | 2006-09-25 15:53:13 -0700 | [diff] [blame] | 2717 | recv_perm = RAWIP_SOCKET__RECVFROM; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | rc = avc_has_perm(sksec->sid, |
| 2721 | netlbl_sid, |
| 2722 | sksec->sclass, |
| 2723 | recv_perm, |
| 2724 | ad); |
| 2725 | if (rc == 0) |
| 2726 | return 0; |
| 2727 | |
| 2728 | netlbl_skbuff_err(skb, rc); |
| 2729 | return rc; |
| 2730 | } |
| 2731 | |
| 2732 | /** |
Paul Moore | f8687af | 2006-10-30 15:22:15 -0800 | [diff] [blame] | 2733 | * selinux_netlbl_socket_setsockopt - Do not allow users to remove a NetLabel |
| 2734 | * @sock: the socket |
| 2735 | * @level: the socket level or protocol |
| 2736 | * @optname: the socket option name |
| 2737 | * |
| 2738 | * Description: |
| 2739 | * Check the setsockopt() call and if the user is trying to replace the IP |
| 2740 | * options on a socket and a NetLabel is in place for the socket deny the |
| 2741 | * access; otherwise allow the access. Returns zero when the access is |
| 2742 | * allowed, -EACCES when denied, and other negative values on error. |
| 2743 | * |
| 2744 | */ |
| 2745 | int selinux_netlbl_socket_setsockopt(struct socket *sock, |
| 2746 | int level, |
| 2747 | int optname) |
| 2748 | { |
| 2749 | int rc = 0; |
Paul Moore | f8687af | 2006-10-30 15:22:15 -0800 | [diff] [blame] | 2750 | struct sk_security_struct *sksec = sock->sk->sk_security; |
Paul Moore | f8687af | 2006-10-30 15:22:15 -0800 | [diff] [blame] | 2751 | struct netlbl_lsm_secattr secattr; |
| 2752 | |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2753 | rcu_read_lock(); |
Paul Moore | f8687af | 2006-10-30 15:22:15 -0800 | [diff] [blame] | 2754 | if (level == IPPROTO_IP && optname == IP_OPTIONS && |
| 2755 | sksec->nlbl_state == NLBL_LABELED) { |
| 2756 | netlbl_secattr_init(&secattr); |
| 2757 | rc = netlbl_socket_getattr(sock, &secattr); |
Paul Moore | 701a90b | 2006-11-17 17:38:46 -0500 | [diff] [blame] | 2758 | if (rc == 0 && secattr.flags != NETLBL_SECATTR_NONE) |
Paul Moore | f8687af | 2006-10-30 15:22:15 -0800 | [diff] [blame] | 2759 | rc = -EACCES; |
| 2760 | netlbl_secattr_destroy(&secattr); |
| 2761 | } |
Paul Moore | 9f2ad66 | 2006-11-17 17:38:53 -0500 | [diff] [blame] | 2762 | rcu_read_unlock(); |
Paul Moore | f8687af | 2006-10-30 15:22:15 -0800 | [diff] [blame] | 2763 | |
| 2764 | return rc; |
| 2765 | } |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 2766 | #endif /* CONFIG_NETLABEL */ |