| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Implementation of the policy database. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 25 | 26 | * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. |
|---|
| 26 | 27 | * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. |
|---|
| 27 | 28 | * Copyright (C) 2003 - 2004 Tresys Technology, LLC |
|---|
| 28 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 29 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 30 | | - * the Free Software Foundation, version 2. |
|---|
| 31 | 29 | */ |
|---|
| 32 | 30 | |
|---|
| 33 | 31 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 36 | 34 | #include <linux/string.h> |
|---|
| 37 | 35 | #include <linux/errno.h> |
|---|
| 38 | 36 | #include <linux/audit.h> |
|---|
| 39 | | -#include <linux/flex_array.h> |
|---|
| 40 | 37 | #include "security.h" |
|---|
| 41 | 38 | |
|---|
| 42 | 39 | #include "policydb.h" |
|---|
| .. | .. |
|---|
| 58 | 55 | "categories", |
|---|
| 59 | 56 | }; |
|---|
| 60 | 57 | #endif |
|---|
| 61 | | - |
|---|
| 62 | | -static unsigned int symtab_sizes[SYM_NUM] = { |
|---|
| 63 | | - 2, |
|---|
| 64 | | - 32, |
|---|
| 65 | | - 16, |
|---|
| 66 | | - 512, |
|---|
| 67 | | - 128, |
|---|
| 68 | | - 16, |
|---|
| 69 | | - 16, |
|---|
| 70 | | - 16, |
|---|
| 71 | | -}; |
|---|
| 72 | 58 | |
|---|
| 73 | 59 | struct policydb_compat_info { |
|---|
| 74 | 60 | int version; |
|---|
| .. | .. |
|---|
| 163 | 149 | .sym_num = SYM_NUM, |
|---|
| 164 | 150 | .ocon_num = OCON_NUM, |
|---|
| 165 | 151 | }, |
|---|
| 152 | + { |
|---|
| 153 | + .version = POLICYDB_VERSION_GLBLUB, |
|---|
| 154 | + .sym_num = SYM_NUM, |
|---|
| 155 | + .ocon_num = OCON_NUM, |
|---|
| 156 | + }, |
|---|
| 157 | + { |
|---|
| 158 | + .version = POLICYDB_VERSION_COMP_FTRANS, |
|---|
| 159 | + .sym_num = SYM_NUM, |
|---|
| 160 | + .ocon_num = OCON_NUM, |
|---|
| 161 | + }, |
|---|
| 166 | 162 | }; |
|---|
| 167 | 163 | |
|---|
| 168 | 164 | static struct policydb_compat_info *policydb_lookup_compat(int version) |
|---|
| .. | .. |
|---|
| 177 | 173 | } |
|---|
| 178 | 174 | } |
|---|
| 179 | 175 | return info; |
|---|
| 180 | | -} |
|---|
| 181 | | - |
|---|
| 182 | | -/* |
|---|
| 183 | | - * Initialize the role table. |
|---|
| 184 | | - */ |
|---|
| 185 | | -static int roles_init(struct policydb *p) |
|---|
| 186 | | -{ |
|---|
| 187 | | - char *key = NULL; |
|---|
| 188 | | - int rc; |
|---|
| 189 | | - struct role_datum *role; |
|---|
| 190 | | - |
|---|
| 191 | | - role = kzalloc(sizeof(*role), GFP_KERNEL); |
|---|
| 192 | | - if (!role) |
|---|
| 193 | | - return -ENOMEM; |
|---|
| 194 | | - |
|---|
| 195 | | - rc = -EINVAL; |
|---|
| 196 | | - role->value = ++p->p_roles.nprim; |
|---|
| 197 | | - if (role->value != OBJECT_R_VAL) |
|---|
| 198 | | - goto out; |
|---|
| 199 | | - |
|---|
| 200 | | - rc = -ENOMEM; |
|---|
| 201 | | - key = kstrdup(OBJECT_R, GFP_KERNEL); |
|---|
| 202 | | - if (!key) |
|---|
| 203 | | - goto out; |
|---|
| 204 | | - |
|---|
| 205 | | - rc = hashtab_insert(p->p_roles.table, key, role); |
|---|
| 206 | | - if (rc) |
|---|
| 207 | | - goto out; |
|---|
| 208 | | - |
|---|
| 209 | | - return 0; |
|---|
| 210 | | -out: |
|---|
| 211 | | - kfree(key); |
|---|
| 212 | | - kfree(role); |
|---|
| 213 | | - return rc; |
|---|
| 214 | | -} |
|---|
| 215 | | - |
|---|
| 216 | | -static u32 filenametr_hash(struct hashtab *h, const void *k) |
|---|
| 217 | | -{ |
|---|
| 218 | | - const struct filename_trans *ft = k; |
|---|
| 219 | | - unsigned long hash; |
|---|
| 220 | | - unsigned int byte_num; |
|---|
| 221 | | - unsigned char focus; |
|---|
| 222 | | - |
|---|
| 223 | | - hash = ft->stype ^ ft->ttype ^ ft->tclass; |
|---|
| 224 | | - |
|---|
| 225 | | - byte_num = 0; |
|---|
| 226 | | - while ((focus = ft->name[byte_num++])) |
|---|
| 227 | | - hash = partial_name_hash(focus, hash); |
|---|
| 228 | | - return hash & (h->size - 1); |
|---|
| 229 | | -} |
|---|
| 230 | | - |
|---|
| 231 | | -static int filenametr_cmp(struct hashtab *h, const void *k1, const void *k2) |
|---|
| 232 | | -{ |
|---|
| 233 | | - const struct filename_trans *ft1 = k1; |
|---|
| 234 | | - const struct filename_trans *ft2 = k2; |
|---|
| 235 | | - int v; |
|---|
| 236 | | - |
|---|
| 237 | | - v = ft1->stype - ft2->stype; |
|---|
| 238 | | - if (v) |
|---|
| 239 | | - return v; |
|---|
| 240 | | - |
|---|
| 241 | | - v = ft1->ttype - ft2->ttype; |
|---|
| 242 | | - if (v) |
|---|
| 243 | | - return v; |
|---|
| 244 | | - |
|---|
| 245 | | - v = ft1->tclass - ft2->tclass; |
|---|
| 246 | | - if (v) |
|---|
| 247 | | - return v; |
|---|
| 248 | | - |
|---|
| 249 | | - return strcmp(ft1->name, ft2->name); |
|---|
| 250 | | - |
|---|
| 251 | | -} |
|---|
| 252 | | - |
|---|
| 253 | | -static u32 rangetr_hash(struct hashtab *h, const void *k) |
|---|
| 254 | | -{ |
|---|
| 255 | | - const struct range_trans *key = k; |
|---|
| 256 | | - return (key->source_type + (key->target_type << 3) + |
|---|
| 257 | | - (key->target_class << 5)) & (h->size - 1); |
|---|
| 258 | | -} |
|---|
| 259 | | - |
|---|
| 260 | | -static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2) |
|---|
| 261 | | -{ |
|---|
| 262 | | - const struct range_trans *key1 = k1, *key2 = k2; |
|---|
| 263 | | - int v; |
|---|
| 264 | | - |
|---|
| 265 | | - v = key1->source_type - key2->source_type; |
|---|
| 266 | | - if (v) |
|---|
| 267 | | - return v; |
|---|
| 268 | | - |
|---|
| 269 | | - v = key1->target_type - key2->target_type; |
|---|
| 270 | | - if (v) |
|---|
| 271 | | - return v; |
|---|
| 272 | | - |
|---|
| 273 | | - v = key1->target_class - key2->target_class; |
|---|
| 274 | | - |
|---|
| 275 | | - return v; |
|---|
| 276 | | -} |
|---|
| 277 | | - |
|---|
| 278 | | -static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap); |
|---|
| 279 | | - |
|---|
| 280 | | -/* |
|---|
| 281 | | - * Initialize a policy database structure. |
|---|
| 282 | | - */ |
|---|
| 283 | | -static int policydb_init(struct policydb *p) |
|---|
| 284 | | -{ |
|---|
| 285 | | - int i, rc; |
|---|
| 286 | | - |
|---|
| 287 | | - memset(p, 0, sizeof(*p)); |
|---|
| 288 | | - |
|---|
| 289 | | - for (i = 0; i < SYM_NUM; i++) { |
|---|
| 290 | | - rc = symtab_init(&p->symtab[i], symtab_sizes[i]); |
|---|
| 291 | | - if (rc) |
|---|
| 292 | | - goto out; |
|---|
| 293 | | - } |
|---|
| 294 | | - |
|---|
| 295 | | - rc = avtab_init(&p->te_avtab); |
|---|
| 296 | | - if (rc) |
|---|
| 297 | | - goto out; |
|---|
| 298 | | - |
|---|
| 299 | | - rc = roles_init(p); |
|---|
| 300 | | - if (rc) |
|---|
| 301 | | - goto out; |
|---|
| 302 | | - |
|---|
| 303 | | - rc = cond_policydb_init(p); |
|---|
| 304 | | - if (rc) |
|---|
| 305 | | - goto out; |
|---|
| 306 | | - |
|---|
| 307 | | - p->filename_trans = hashtab_create(filenametr_hash, filenametr_cmp, (1 << 10)); |
|---|
| 308 | | - if (!p->filename_trans) { |
|---|
| 309 | | - rc = -ENOMEM; |
|---|
| 310 | | - goto out; |
|---|
| 311 | | - } |
|---|
| 312 | | - |
|---|
| 313 | | - p->range_tr = hashtab_create(rangetr_hash, rangetr_cmp, 256); |
|---|
| 314 | | - if (!p->range_tr) { |
|---|
| 315 | | - rc = -ENOMEM; |
|---|
| 316 | | - goto out; |
|---|
| 317 | | - } |
|---|
| 318 | | - |
|---|
| 319 | | - ebitmap_init(&p->filename_trans_ttypes); |
|---|
| 320 | | - ebitmap_init(&p->policycaps); |
|---|
| 321 | | - ebitmap_init(&p->permissive_map); |
|---|
| 322 | | - |
|---|
| 323 | | - return 0; |
|---|
| 324 | | -out: |
|---|
| 325 | | - hashtab_destroy(p->filename_trans); |
|---|
| 326 | | - hashtab_destroy(p->range_tr); |
|---|
| 327 | | - for (i = 0; i < SYM_NUM; i++) { |
|---|
| 328 | | - hashtab_map(p->symtab[i].table, destroy_f[i], NULL); |
|---|
| 329 | | - hashtab_destroy(p->symtab[i].table); |
|---|
| 330 | | - } |
|---|
| 331 | | - return rc; |
|---|
| 332 | | -} |
|---|
| 333 | | - |
|---|
| 334 | | -/* |
|---|
| 335 | | - * The following *_index functions are used to |
|---|
| 336 | | - * define the val_to_name and val_to_struct arrays |
|---|
| 337 | | - * in a policy database structure. The val_to_name |
|---|
| 338 | | - * arrays are used when converting security context |
|---|
| 339 | | - * structures into string representations. The |
|---|
| 340 | | - * val_to_struct arrays are used when the attributes |
|---|
| 341 | | - * of a class, role, or user are needed. |
|---|
| 342 | | - */ |
|---|
| 343 | | - |
|---|
| 344 | | -static int common_index(void *key, void *datum, void *datap) |
|---|
| 345 | | -{ |
|---|
| 346 | | - struct policydb *p; |
|---|
| 347 | | - struct common_datum *comdatum; |
|---|
| 348 | | - struct flex_array *fa; |
|---|
| 349 | | - |
|---|
| 350 | | - comdatum = datum; |
|---|
| 351 | | - p = datap; |
|---|
| 352 | | - if (!comdatum->value || comdatum->value > p->p_commons.nprim) |
|---|
| 353 | | - return -EINVAL; |
|---|
| 354 | | - |
|---|
| 355 | | - fa = p->sym_val_to_name[SYM_COMMONS]; |
|---|
| 356 | | - if (flex_array_put_ptr(fa, comdatum->value - 1, key, |
|---|
| 357 | | - GFP_KERNEL | __GFP_ZERO)) |
|---|
| 358 | | - BUG(); |
|---|
| 359 | | - return 0; |
|---|
| 360 | | -} |
|---|
| 361 | | - |
|---|
| 362 | | -static int class_index(void *key, void *datum, void *datap) |
|---|
| 363 | | -{ |
|---|
| 364 | | - struct policydb *p; |
|---|
| 365 | | - struct class_datum *cladatum; |
|---|
| 366 | | - struct flex_array *fa; |
|---|
| 367 | | - |
|---|
| 368 | | - cladatum = datum; |
|---|
| 369 | | - p = datap; |
|---|
| 370 | | - if (!cladatum->value || cladatum->value > p->p_classes.nprim) |
|---|
| 371 | | - return -EINVAL; |
|---|
| 372 | | - fa = p->sym_val_to_name[SYM_CLASSES]; |
|---|
| 373 | | - if (flex_array_put_ptr(fa, cladatum->value - 1, key, |
|---|
| 374 | | - GFP_KERNEL | __GFP_ZERO)) |
|---|
| 375 | | - BUG(); |
|---|
| 376 | | - p->class_val_to_struct[cladatum->value - 1] = cladatum; |
|---|
| 377 | | - return 0; |
|---|
| 378 | | -} |
|---|
| 379 | | - |
|---|
| 380 | | -static int role_index(void *key, void *datum, void *datap) |
|---|
| 381 | | -{ |
|---|
| 382 | | - struct policydb *p; |
|---|
| 383 | | - struct role_datum *role; |
|---|
| 384 | | - struct flex_array *fa; |
|---|
| 385 | | - |
|---|
| 386 | | - role = datum; |
|---|
| 387 | | - p = datap; |
|---|
| 388 | | - if (!role->value |
|---|
| 389 | | - || role->value > p->p_roles.nprim |
|---|
| 390 | | - || role->bounds > p->p_roles.nprim) |
|---|
| 391 | | - return -EINVAL; |
|---|
| 392 | | - |
|---|
| 393 | | - fa = p->sym_val_to_name[SYM_ROLES]; |
|---|
| 394 | | - if (flex_array_put_ptr(fa, role->value - 1, key, |
|---|
| 395 | | - GFP_KERNEL | __GFP_ZERO)) |
|---|
| 396 | | - BUG(); |
|---|
| 397 | | - p->role_val_to_struct[role->value - 1] = role; |
|---|
| 398 | | - return 0; |
|---|
| 399 | | -} |
|---|
| 400 | | - |
|---|
| 401 | | -static int type_index(void *key, void *datum, void *datap) |
|---|
| 402 | | -{ |
|---|
| 403 | | - struct policydb *p; |
|---|
| 404 | | - struct type_datum *typdatum; |
|---|
| 405 | | - struct flex_array *fa; |
|---|
| 406 | | - |
|---|
| 407 | | - typdatum = datum; |
|---|
| 408 | | - p = datap; |
|---|
| 409 | | - |
|---|
| 410 | | - if (typdatum->primary) { |
|---|
| 411 | | - if (!typdatum->value |
|---|
| 412 | | - || typdatum->value > p->p_types.nprim |
|---|
| 413 | | - || typdatum->bounds > p->p_types.nprim) |
|---|
| 414 | | - return -EINVAL; |
|---|
| 415 | | - fa = p->sym_val_to_name[SYM_TYPES]; |
|---|
| 416 | | - if (flex_array_put_ptr(fa, typdatum->value - 1, key, |
|---|
| 417 | | - GFP_KERNEL | __GFP_ZERO)) |
|---|
| 418 | | - BUG(); |
|---|
| 419 | | - |
|---|
| 420 | | - fa = p->type_val_to_struct_array; |
|---|
| 421 | | - if (flex_array_put_ptr(fa, typdatum->value - 1, typdatum, |
|---|
| 422 | | - GFP_KERNEL | __GFP_ZERO)) |
|---|
| 423 | | - BUG(); |
|---|
| 424 | | - } |
|---|
| 425 | | - |
|---|
| 426 | | - return 0; |
|---|
| 427 | | -} |
|---|
| 428 | | - |
|---|
| 429 | | -static int user_index(void *key, void *datum, void *datap) |
|---|
| 430 | | -{ |
|---|
| 431 | | - struct policydb *p; |
|---|
| 432 | | - struct user_datum *usrdatum; |
|---|
| 433 | | - struct flex_array *fa; |
|---|
| 434 | | - |
|---|
| 435 | | - usrdatum = datum; |
|---|
| 436 | | - p = datap; |
|---|
| 437 | | - if (!usrdatum->value |
|---|
| 438 | | - || usrdatum->value > p->p_users.nprim |
|---|
| 439 | | - || usrdatum->bounds > p->p_users.nprim) |
|---|
| 440 | | - return -EINVAL; |
|---|
| 441 | | - |
|---|
| 442 | | - fa = p->sym_val_to_name[SYM_USERS]; |
|---|
| 443 | | - if (flex_array_put_ptr(fa, usrdatum->value - 1, key, |
|---|
| 444 | | - GFP_KERNEL | __GFP_ZERO)) |
|---|
| 445 | | - BUG(); |
|---|
| 446 | | - p->user_val_to_struct[usrdatum->value - 1] = usrdatum; |
|---|
| 447 | | - return 0; |
|---|
| 448 | | -} |
|---|
| 449 | | - |
|---|
| 450 | | -static int sens_index(void *key, void *datum, void *datap) |
|---|
| 451 | | -{ |
|---|
| 452 | | - struct policydb *p; |
|---|
| 453 | | - struct level_datum *levdatum; |
|---|
| 454 | | - struct flex_array *fa; |
|---|
| 455 | | - |
|---|
| 456 | | - levdatum = datum; |
|---|
| 457 | | - p = datap; |
|---|
| 458 | | - |
|---|
| 459 | | - if (!levdatum->isalias) { |
|---|
| 460 | | - if (!levdatum->level->sens || |
|---|
| 461 | | - levdatum->level->sens > p->p_levels.nprim) |
|---|
| 462 | | - return -EINVAL; |
|---|
| 463 | | - fa = p->sym_val_to_name[SYM_LEVELS]; |
|---|
| 464 | | - if (flex_array_put_ptr(fa, levdatum->level->sens - 1, key, |
|---|
| 465 | | - GFP_KERNEL | __GFP_ZERO)) |
|---|
| 466 | | - BUG(); |
|---|
| 467 | | - } |
|---|
| 468 | | - |
|---|
| 469 | | - return 0; |
|---|
| 470 | | -} |
|---|
| 471 | | - |
|---|
| 472 | | -static int cat_index(void *key, void *datum, void *datap) |
|---|
| 473 | | -{ |
|---|
| 474 | | - struct policydb *p; |
|---|
| 475 | | - struct cat_datum *catdatum; |
|---|
| 476 | | - struct flex_array *fa; |
|---|
| 477 | | - |
|---|
| 478 | | - catdatum = datum; |
|---|
| 479 | | - p = datap; |
|---|
| 480 | | - |
|---|
| 481 | | - if (!catdatum->isalias) { |
|---|
| 482 | | - if (!catdatum->value || catdatum->value > p->p_cats.nprim) |
|---|
| 483 | | - return -EINVAL; |
|---|
| 484 | | - fa = p->sym_val_to_name[SYM_CATS]; |
|---|
| 485 | | - if (flex_array_put_ptr(fa, catdatum->value - 1, key, |
|---|
| 486 | | - GFP_KERNEL | __GFP_ZERO)) |
|---|
| 487 | | - BUG(); |
|---|
| 488 | | - } |
|---|
| 489 | | - |
|---|
| 490 | | - return 0; |
|---|
| 491 | | -} |
|---|
| 492 | | - |
|---|
| 493 | | -static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) = |
|---|
| 494 | | -{ |
|---|
| 495 | | - common_index, |
|---|
| 496 | | - class_index, |
|---|
| 497 | | - role_index, |
|---|
| 498 | | - type_index, |
|---|
| 499 | | - user_index, |
|---|
| 500 | | - cond_index_bool, |
|---|
| 501 | | - sens_index, |
|---|
| 502 | | - cat_index, |
|---|
| 503 | | -}; |
|---|
| 504 | | - |
|---|
| 505 | | -#ifdef DEBUG_HASHES |
|---|
| 506 | | -static void hash_eval(struct hashtab *h, const char *hash_name) |
|---|
| 507 | | -{ |
|---|
| 508 | | - struct hashtab_info info; |
|---|
| 509 | | - |
|---|
| 510 | | - hashtab_stat(h, &info); |
|---|
| 511 | | - pr_debug("SELinux: %s: %d entries and %d/%d buckets used, " |
|---|
| 512 | | - "longest chain length %d\n", hash_name, h->nel, |
|---|
| 513 | | - info.slots_used, h->size, info.max_chain_len); |
|---|
| 514 | | -} |
|---|
| 515 | | - |
|---|
| 516 | | -static void symtab_hash_eval(struct symtab *s) |
|---|
| 517 | | -{ |
|---|
| 518 | | - int i; |
|---|
| 519 | | - |
|---|
| 520 | | - for (i = 0; i < SYM_NUM; i++) |
|---|
| 521 | | - hash_eval(s[i].table, symtab_name[i]); |
|---|
| 522 | | -} |
|---|
| 523 | | - |
|---|
| 524 | | -#else |
|---|
| 525 | | -static inline void hash_eval(struct hashtab *h, char *hash_name) |
|---|
| 526 | | -{ |
|---|
| 527 | | -} |
|---|
| 528 | | -#endif |
|---|
| 529 | | - |
|---|
| 530 | | -/* |
|---|
| 531 | | - * Define the other val_to_name and val_to_struct arrays |
|---|
| 532 | | - * in a policy database structure. |
|---|
| 533 | | - * |
|---|
| 534 | | - * Caller must clean up on failure. |
|---|
| 535 | | - */ |
|---|
| 536 | | -static int policydb_index(struct policydb *p) |
|---|
| 537 | | -{ |
|---|
| 538 | | - int i, rc; |
|---|
| 539 | | - |
|---|
| 540 | | - if (p->mls_enabled) |
|---|
| 541 | | - pr_debug("SELinux: %d users, %d roles, %d types, %d bools, %d sens, %d cats\n", |
|---|
| 542 | | - p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, |
|---|
| 543 | | - p->p_bools.nprim, p->p_levels.nprim, p->p_cats.nprim); |
|---|
| 544 | | - else |
|---|
| 545 | | - pr_debug("SELinux: %d users, %d roles, %d types, %d bools\n", |
|---|
| 546 | | - p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, |
|---|
| 547 | | - p->p_bools.nprim); |
|---|
| 548 | | - |
|---|
| 549 | | - pr_debug("SELinux: %d classes, %d rules\n", |
|---|
| 550 | | - p->p_classes.nprim, p->te_avtab.nel); |
|---|
| 551 | | - |
|---|
| 552 | | -#ifdef DEBUG_HASHES |
|---|
| 553 | | - avtab_hash_eval(&p->te_avtab, "rules"); |
|---|
| 554 | | - symtab_hash_eval(p->symtab); |
|---|
| 555 | | -#endif |
|---|
| 556 | | - |
|---|
| 557 | | - p->class_val_to_struct = kcalloc(p->p_classes.nprim, |
|---|
| 558 | | - sizeof(*p->class_val_to_struct), |
|---|
| 559 | | - GFP_KERNEL); |
|---|
| 560 | | - if (!p->class_val_to_struct) |
|---|
| 561 | | - return -ENOMEM; |
|---|
| 562 | | - |
|---|
| 563 | | - p->role_val_to_struct = kcalloc(p->p_roles.nprim, |
|---|
| 564 | | - sizeof(*p->role_val_to_struct), |
|---|
| 565 | | - GFP_KERNEL); |
|---|
| 566 | | - if (!p->role_val_to_struct) |
|---|
| 567 | | - return -ENOMEM; |
|---|
| 568 | | - |
|---|
| 569 | | - p->user_val_to_struct = kcalloc(p->p_users.nprim, |
|---|
| 570 | | - sizeof(*p->user_val_to_struct), |
|---|
| 571 | | - GFP_KERNEL); |
|---|
| 572 | | - if (!p->user_val_to_struct) |
|---|
| 573 | | - return -ENOMEM; |
|---|
| 574 | | - |
|---|
| 575 | | - /* Yes, I want the sizeof the pointer, not the structure */ |
|---|
| 576 | | - p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *), |
|---|
| 577 | | - p->p_types.nprim, |
|---|
| 578 | | - GFP_KERNEL | __GFP_ZERO); |
|---|
| 579 | | - if (!p->type_val_to_struct_array) |
|---|
| 580 | | - return -ENOMEM; |
|---|
| 581 | | - |
|---|
| 582 | | - rc = flex_array_prealloc(p->type_val_to_struct_array, 0, |
|---|
| 583 | | - p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); |
|---|
| 584 | | - if (rc) |
|---|
| 585 | | - goto out; |
|---|
| 586 | | - |
|---|
| 587 | | - rc = cond_init_bool_indexes(p); |
|---|
| 588 | | - if (rc) |
|---|
| 589 | | - goto out; |
|---|
| 590 | | - |
|---|
| 591 | | - for (i = 0; i < SYM_NUM; i++) { |
|---|
| 592 | | - p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), |
|---|
| 593 | | - p->symtab[i].nprim, |
|---|
| 594 | | - GFP_KERNEL | __GFP_ZERO); |
|---|
| 595 | | - if (!p->sym_val_to_name[i]) |
|---|
| 596 | | - return -ENOMEM; |
|---|
| 597 | | - |
|---|
| 598 | | - rc = flex_array_prealloc(p->sym_val_to_name[i], |
|---|
| 599 | | - 0, p->symtab[i].nprim, |
|---|
| 600 | | - GFP_KERNEL | __GFP_ZERO); |
|---|
| 601 | | - if (rc) |
|---|
| 602 | | - goto out; |
|---|
| 603 | | - |
|---|
| 604 | | - rc = hashtab_map(p->symtab[i].table, index_f[i], p); |
|---|
| 605 | | - if (rc) |
|---|
| 606 | | - goto out; |
|---|
| 607 | | - } |
|---|
| 608 | | - rc = 0; |
|---|
| 609 | | -out: |
|---|
| 610 | | - return rc; |
|---|
| 611 | 176 | } |
|---|
| 612 | 177 | |
|---|
| 613 | 178 | /* |
|---|
| .. | .. |
|---|
| 630 | 195 | kfree(key); |
|---|
| 631 | 196 | if (datum) { |
|---|
| 632 | 197 | comdatum = datum; |
|---|
| 633 | | - hashtab_map(comdatum->permissions.table, perm_destroy, NULL); |
|---|
| 634 | | - hashtab_destroy(comdatum->permissions.table); |
|---|
| 198 | + hashtab_map(&comdatum->permissions.table, perm_destroy, NULL); |
|---|
| 199 | + hashtab_destroy(&comdatum->permissions.table); |
|---|
| 635 | 200 | } |
|---|
| 636 | 201 | kfree(datum); |
|---|
| 637 | 202 | return 0; |
|---|
| .. | .. |
|---|
| 659 | 224 | kfree(key); |
|---|
| 660 | 225 | if (datum) { |
|---|
| 661 | 226 | cladatum = datum; |
|---|
| 662 | | - hashtab_map(cladatum->permissions.table, perm_destroy, NULL); |
|---|
| 663 | | - hashtab_destroy(cladatum->permissions.table); |
|---|
| 227 | + hashtab_map(&cladatum->permissions.table, perm_destroy, NULL); |
|---|
| 228 | + hashtab_destroy(&cladatum->permissions.table); |
|---|
| 664 | 229 | constraint = cladatum->constraints; |
|---|
| 665 | 230 | while (constraint) { |
|---|
| 666 | 231 | e = constraint->expr; |
|---|
| .. | .. |
|---|
| 765 | 330 | |
|---|
| 766 | 331 | static int filenametr_destroy(void *key, void *datum, void *p) |
|---|
| 767 | 332 | { |
|---|
| 768 | | - struct filename_trans *ft = key; |
|---|
| 333 | + struct filename_trans_key *ft = key; |
|---|
| 334 | + struct filename_trans_datum *next, *d = datum; |
|---|
| 335 | + |
|---|
| 769 | 336 | kfree(ft->name); |
|---|
| 770 | 337 | kfree(key); |
|---|
| 771 | | - kfree(datum); |
|---|
| 338 | + do { |
|---|
| 339 | + ebitmap_destroy(&d->stypes); |
|---|
| 340 | + next = d->next; |
|---|
| 341 | + kfree(d); |
|---|
| 342 | + d = next; |
|---|
| 343 | + } while (unlikely(d)); |
|---|
| 772 | 344 | cond_resched(); |
|---|
| 773 | 345 | return 0; |
|---|
| 774 | 346 | } |
|---|
| .. | .. |
|---|
| 776 | 348 | static int range_tr_destroy(void *key, void *datum, void *p) |
|---|
| 777 | 349 | { |
|---|
| 778 | 350 | struct mls_range *rt = datum; |
|---|
| 351 | + |
|---|
| 779 | 352 | kfree(key); |
|---|
| 780 | 353 | ebitmap_destroy(&rt->level[0].cat); |
|---|
| 781 | 354 | ebitmap_destroy(&rt->level[1].cat); |
|---|
| 782 | 355 | kfree(datum); |
|---|
| 783 | 356 | cond_resched(); |
|---|
| 357 | + return 0; |
|---|
| 358 | +} |
|---|
| 359 | + |
|---|
| 360 | +static int role_tr_destroy(void *key, void *datum, void *p) |
|---|
| 361 | +{ |
|---|
| 362 | + kfree(key); |
|---|
| 363 | + kfree(datum); |
|---|
| 784 | 364 | return 0; |
|---|
| 785 | 365 | } |
|---|
| 786 | 366 | |
|---|
| .. | .. |
|---|
| 798 | 378 | } |
|---|
| 799 | 379 | |
|---|
| 800 | 380 | /* |
|---|
| 381 | + * Initialize the role table. |
|---|
| 382 | + */ |
|---|
| 383 | +static int roles_init(struct policydb *p) |
|---|
| 384 | +{ |
|---|
| 385 | + char *key = NULL; |
|---|
| 386 | + int rc; |
|---|
| 387 | + struct role_datum *role; |
|---|
| 388 | + |
|---|
| 389 | + role = kzalloc(sizeof(*role), GFP_KERNEL); |
|---|
| 390 | + if (!role) |
|---|
| 391 | + return -ENOMEM; |
|---|
| 392 | + |
|---|
| 393 | + rc = -EINVAL; |
|---|
| 394 | + role->value = ++p->p_roles.nprim; |
|---|
| 395 | + if (role->value != OBJECT_R_VAL) |
|---|
| 396 | + goto out; |
|---|
| 397 | + |
|---|
| 398 | + rc = -ENOMEM; |
|---|
| 399 | + key = kstrdup(OBJECT_R, GFP_KERNEL); |
|---|
| 400 | + if (!key) |
|---|
| 401 | + goto out; |
|---|
| 402 | + |
|---|
| 403 | + rc = symtab_insert(&p->p_roles, key, role); |
|---|
| 404 | + if (rc) |
|---|
| 405 | + goto out; |
|---|
| 406 | + |
|---|
| 407 | + return 0; |
|---|
| 408 | +out: |
|---|
| 409 | + kfree(key); |
|---|
| 410 | + kfree(role); |
|---|
| 411 | + return rc; |
|---|
| 412 | +} |
|---|
| 413 | + |
|---|
| 414 | +static u32 filenametr_hash(const void *k) |
|---|
| 415 | +{ |
|---|
| 416 | + const struct filename_trans_key *ft = k; |
|---|
| 417 | + unsigned long hash; |
|---|
| 418 | + unsigned int byte_num; |
|---|
| 419 | + unsigned char focus; |
|---|
| 420 | + |
|---|
| 421 | + hash = ft->ttype ^ ft->tclass; |
|---|
| 422 | + |
|---|
| 423 | + byte_num = 0; |
|---|
| 424 | + while ((focus = ft->name[byte_num++])) |
|---|
| 425 | + hash = partial_name_hash(focus, hash); |
|---|
| 426 | + return hash; |
|---|
| 427 | +} |
|---|
| 428 | + |
|---|
| 429 | +static int filenametr_cmp(const void *k1, const void *k2) |
|---|
| 430 | +{ |
|---|
| 431 | + const struct filename_trans_key *ft1 = k1; |
|---|
| 432 | + const struct filename_trans_key *ft2 = k2; |
|---|
| 433 | + int v; |
|---|
| 434 | + |
|---|
| 435 | + v = ft1->ttype - ft2->ttype; |
|---|
| 436 | + if (v) |
|---|
| 437 | + return v; |
|---|
| 438 | + |
|---|
| 439 | + v = ft1->tclass - ft2->tclass; |
|---|
| 440 | + if (v) |
|---|
| 441 | + return v; |
|---|
| 442 | + |
|---|
| 443 | + return strcmp(ft1->name, ft2->name); |
|---|
| 444 | + |
|---|
| 445 | +} |
|---|
| 446 | + |
|---|
| 447 | +static const struct hashtab_key_params filenametr_key_params = { |
|---|
| 448 | + .hash = filenametr_hash, |
|---|
| 449 | + .cmp = filenametr_cmp, |
|---|
| 450 | +}; |
|---|
| 451 | + |
|---|
| 452 | +struct filename_trans_datum *policydb_filenametr_search( |
|---|
| 453 | + struct policydb *p, struct filename_trans_key *key) |
|---|
| 454 | +{ |
|---|
| 455 | + return hashtab_search(&p->filename_trans, key, filenametr_key_params); |
|---|
| 456 | +} |
|---|
| 457 | + |
|---|
| 458 | +static u32 rangetr_hash(const void *k) |
|---|
| 459 | +{ |
|---|
| 460 | + const struct range_trans *key = k; |
|---|
| 461 | + |
|---|
| 462 | + return key->source_type + (key->target_type << 3) + |
|---|
| 463 | + (key->target_class << 5); |
|---|
| 464 | +} |
|---|
| 465 | + |
|---|
| 466 | +static int rangetr_cmp(const void *k1, const void *k2) |
|---|
| 467 | +{ |
|---|
| 468 | + const struct range_trans *key1 = k1, *key2 = k2; |
|---|
| 469 | + int v; |
|---|
| 470 | + |
|---|
| 471 | + v = key1->source_type - key2->source_type; |
|---|
| 472 | + if (v) |
|---|
| 473 | + return v; |
|---|
| 474 | + |
|---|
| 475 | + v = key1->target_type - key2->target_type; |
|---|
| 476 | + if (v) |
|---|
| 477 | + return v; |
|---|
| 478 | + |
|---|
| 479 | + v = key1->target_class - key2->target_class; |
|---|
| 480 | + |
|---|
| 481 | + return v; |
|---|
| 482 | +} |
|---|
| 483 | + |
|---|
| 484 | +static const struct hashtab_key_params rangetr_key_params = { |
|---|
| 485 | + .hash = rangetr_hash, |
|---|
| 486 | + .cmp = rangetr_cmp, |
|---|
| 487 | +}; |
|---|
| 488 | + |
|---|
| 489 | +struct mls_range *policydb_rangetr_search(struct policydb *p, |
|---|
| 490 | + struct range_trans *key) |
|---|
| 491 | +{ |
|---|
| 492 | + return hashtab_search(&p->range_tr, key, rangetr_key_params); |
|---|
| 493 | +} |
|---|
| 494 | + |
|---|
| 495 | +static u32 role_trans_hash(const void *k) |
|---|
| 496 | +{ |
|---|
| 497 | + const struct role_trans_key *key = k; |
|---|
| 498 | + |
|---|
| 499 | + return key->role + (key->type << 3) + (key->tclass << 5); |
|---|
| 500 | +} |
|---|
| 501 | + |
|---|
| 502 | +static int role_trans_cmp(const void *k1, const void *k2) |
|---|
| 503 | +{ |
|---|
| 504 | + const struct role_trans_key *key1 = k1, *key2 = k2; |
|---|
| 505 | + int v; |
|---|
| 506 | + |
|---|
| 507 | + v = key1->role - key2->role; |
|---|
| 508 | + if (v) |
|---|
| 509 | + return v; |
|---|
| 510 | + |
|---|
| 511 | + v = key1->type - key2->type; |
|---|
| 512 | + if (v) |
|---|
| 513 | + return v; |
|---|
| 514 | + |
|---|
| 515 | + return key1->tclass - key2->tclass; |
|---|
| 516 | +} |
|---|
| 517 | + |
|---|
| 518 | +static const struct hashtab_key_params roletr_key_params = { |
|---|
| 519 | + .hash = role_trans_hash, |
|---|
| 520 | + .cmp = role_trans_cmp, |
|---|
| 521 | +}; |
|---|
| 522 | + |
|---|
| 523 | +struct role_trans_datum *policydb_roletr_search(struct policydb *p, |
|---|
| 524 | + struct role_trans_key *key) |
|---|
| 525 | +{ |
|---|
| 526 | + return hashtab_search(&p->role_tr, key, roletr_key_params); |
|---|
| 527 | +} |
|---|
| 528 | + |
|---|
| 529 | +/* |
|---|
| 530 | + * Initialize a policy database structure. |
|---|
| 531 | + */ |
|---|
| 532 | +static void policydb_init(struct policydb *p) |
|---|
| 533 | +{ |
|---|
| 534 | + memset(p, 0, sizeof(*p)); |
|---|
| 535 | + |
|---|
| 536 | + avtab_init(&p->te_avtab); |
|---|
| 537 | + cond_policydb_init(p); |
|---|
| 538 | + |
|---|
| 539 | + ebitmap_init(&p->filename_trans_ttypes); |
|---|
| 540 | + ebitmap_init(&p->policycaps); |
|---|
| 541 | + ebitmap_init(&p->permissive_map); |
|---|
| 542 | +} |
|---|
| 543 | + |
|---|
| 544 | +/* |
|---|
| 545 | + * The following *_index functions are used to |
|---|
| 546 | + * define the val_to_name and val_to_struct arrays |
|---|
| 547 | + * in a policy database structure. The val_to_name |
|---|
| 548 | + * arrays are used when converting security context |
|---|
| 549 | + * structures into string representations. The |
|---|
| 550 | + * val_to_struct arrays are used when the attributes |
|---|
| 551 | + * of a class, role, or user are needed. |
|---|
| 552 | + */ |
|---|
| 553 | + |
|---|
| 554 | +static int common_index(void *key, void *datum, void *datap) |
|---|
| 555 | +{ |
|---|
| 556 | + struct policydb *p; |
|---|
| 557 | + struct common_datum *comdatum; |
|---|
| 558 | + |
|---|
| 559 | + comdatum = datum; |
|---|
| 560 | + p = datap; |
|---|
| 561 | + if (!comdatum->value || comdatum->value > p->p_commons.nprim) |
|---|
| 562 | + return -EINVAL; |
|---|
| 563 | + |
|---|
| 564 | + p->sym_val_to_name[SYM_COMMONS][comdatum->value - 1] = key; |
|---|
| 565 | + |
|---|
| 566 | + return 0; |
|---|
| 567 | +} |
|---|
| 568 | + |
|---|
| 569 | +static int class_index(void *key, void *datum, void *datap) |
|---|
| 570 | +{ |
|---|
| 571 | + struct policydb *p; |
|---|
| 572 | + struct class_datum *cladatum; |
|---|
| 573 | + |
|---|
| 574 | + cladatum = datum; |
|---|
| 575 | + p = datap; |
|---|
| 576 | + if (!cladatum->value || cladatum->value > p->p_classes.nprim) |
|---|
| 577 | + return -EINVAL; |
|---|
| 578 | + |
|---|
| 579 | + p->sym_val_to_name[SYM_CLASSES][cladatum->value - 1] = key; |
|---|
| 580 | + p->class_val_to_struct[cladatum->value - 1] = cladatum; |
|---|
| 581 | + return 0; |
|---|
| 582 | +} |
|---|
| 583 | + |
|---|
| 584 | +static int role_index(void *key, void *datum, void *datap) |
|---|
| 585 | +{ |
|---|
| 586 | + struct policydb *p; |
|---|
| 587 | + struct role_datum *role; |
|---|
| 588 | + |
|---|
| 589 | + role = datum; |
|---|
| 590 | + p = datap; |
|---|
| 591 | + if (!role->value |
|---|
| 592 | + || role->value > p->p_roles.nprim |
|---|
| 593 | + || role->bounds > p->p_roles.nprim) |
|---|
| 594 | + return -EINVAL; |
|---|
| 595 | + |
|---|
| 596 | + p->sym_val_to_name[SYM_ROLES][role->value - 1] = key; |
|---|
| 597 | + p->role_val_to_struct[role->value - 1] = role; |
|---|
| 598 | + return 0; |
|---|
| 599 | +} |
|---|
| 600 | + |
|---|
| 601 | +static int type_index(void *key, void *datum, void *datap) |
|---|
| 602 | +{ |
|---|
| 603 | + struct policydb *p; |
|---|
| 604 | + struct type_datum *typdatum; |
|---|
| 605 | + |
|---|
| 606 | + typdatum = datum; |
|---|
| 607 | + p = datap; |
|---|
| 608 | + |
|---|
| 609 | + if (typdatum->primary) { |
|---|
| 610 | + if (!typdatum->value |
|---|
| 611 | + || typdatum->value > p->p_types.nprim |
|---|
| 612 | + || typdatum->bounds > p->p_types.nprim) |
|---|
| 613 | + return -EINVAL; |
|---|
| 614 | + p->sym_val_to_name[SYM_TYPES][typdatum->value - 1] = key; |
|---|
| 615 | + p->type_val_to_struct[typdatum->value - 1] = typdatum; |
|---|
| 616 | + } |
|---|
| 617 | + |
|---|
| 618 | + return 0; |
|---|
| 619 | +} |
|---|
| 620 | + |
|---|
| 621 | +static int user_index(void *key, void *datum, void *datap) |
|---|
| 622 | +{ |
|---|
| 623 | + struct policydb *p; |
|---|
| 624 | + struct user_datum *usrdatum; |
|---|
| 625 | + |
|---|
| 626 | + usrdatum = datum; |
|---|
| 627 | + p = datap; |
|---|
| 628 | + if (!usrdatum->value |
|---|
| 629 | + || usrdatum->value > p->p_users.nprim |
|---|
| 630 | + || usrdatum->bounds > p->p_users.nprim) |
|---|
| 631 | + return -EINVAL; |
|---|
| 632 | + |
|---|
| 633 | + p->sym_val_to_name[SYM_USERS][usrdatum->value - 1] = key; |
|---|
| 634 | + p->user_val_to_struct[usrdatum->value - 1] = usrdatum; |
|---|
| 635 | + return 0; |
|---|
| 636 | +} |
|---|
| 637 | + |
|---|
| 638 | +static int sens_index(void *key, void *datum, void *datap) |
|---|
| 639 | +{ |
|---|
| 640 | + struct policydb *p; |
|---|
| 641 | + struct level_datum *levdatum; |
|---|
| 642 | + |
|---|
| 643 | + levdatum = datum; |
|---|
| 644 | + p = datap; |
|---|
| 645 | + |
|---|
| 646 | + if (!levdatum->isalias) { |
|---|
| 647 | + if (!levdatum->level->sens || |
|---|
| 648 | + levdatum->level->sens > p->p_levels.nprim) |
|---|
| 649 | + return -EINVAL; |
|---|
| 650 | + |
|---|
| 651 | + p->sym_val_to_name[SYM_LEVELS][levdatum->level->sens - 1] = key; |
|---|
| 652 | + } |
|---|
| 653 | + |
|---|
| 654 | + return 0; |
|---|
| 655 | +} |
|---|
| 656 | + |
|---|
| 657 | +static int cat_index(void *key, void *datum, void *datap) |
|---|
| 658 | +{ |
|---|
| 659 | + struct policydb *p; |
|---|
| 660 | + struct cat_datum *catdatum; |
|---|
| 661 | + |
|---|
| 662 | + catdatum = datum; |
|---|
| 663 | + p = datap; |
|---|
| 664 | + |
|---|
| 665 | + if (!catdatum->isalias) { |
|---|
| 666 | + if (!catdatum->value || catdatum->value > p->p_cats.nprim) |
|---|
| 667 | + return -EINVAL; |
|---|
| 668 | + |
|---|
| 669 | + p->sym_val_to_name[SYM_CATS][catdatum->value - 1] = key; |
|---|
| 670 | + } |
|---|
| 671 | + |
|---|
| 672 | + return 0; |
|---|
| 673 | +} |
|---|
| 674 | + |
|---|
| 675 | +static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) = |
|---|
| 676 | +{ |
|---|
| 677 | + common_index, |
|---|
| 678 | + class_index, |
|---|
| 679 | + role_index, |
|---|
| 680 | + type_index, |
|---|
| 681 | + user_index, |
|---|
| 682 | + cond_index_bool, |
|---|
| 683 | + sens_index, |
|---|
| 684 | + cat_index, |
|---|
| 685 | +}; |
|---|
| 686 | + |
|---|
| 687 | +#ifdef DEBUG_HASHES |
|---|
| 688 | +static void hash_eval(struct hashtab *h, const char *hash_name) |
|---|
| 689 | +{ |
|---|
| 690 | + struct hashtab_info info; |
|---|
| 691 | + |
|---|
| 692 | + hashtab_stat(h, &info); |
|---|
| 693 | + pr_debug("SELinux: %s: %d entries and %d/%d buckets used, longest chain length %d\n", |
|---|
| 694 | + hash_name, h->nel, info.slots_used, h->size, |
|---|
| 695 | + info.max_chain_len); |
|---|
| 696 | +} |
|---|
| 697 | + |
|---|
| 698 | +static void symtab_hash_eval(struct symtab *s) |
|---|
| 699 | +{ |
|---|
| 700 | + int i; |
|---|
| 701 | + |
|---|
| 702 | + for (i = 0; i < SYM_NUM; i++) |
|---|
| 703 | + hash_eval(&s[i].table, symtab_name[i]); |
|---|
| 704 | +} |
|---|
| 705 | + |
|---|
| 706 | +#else |
|---|
| 707 | +static inline void hash_eval(struct hashtab *h, char *hash_name) |
|---|
| 708 | +{ |
|---|
| 709 | +} |
|---|
| 710 | +#endif |
|---|
| 711 | + |
|---|
| 712 | +/* |
|---|
| 713 | + * Define the other val_to_name and val_to_struct arrays |
|---|
| 714 | + * in a policy database structure. |
|---|
| 715 | + * |
|---|
| 716 | + * Caller must clean up on failure. |
|---|
| 717 | + */ |
|---|
| 718 | +static int policydb_index(struct policydb *p) |
|---|
| 719 | +{ |
|---|
| 720 | + int i, rc; |
|---|
| 721 | + |
|---|
| 722 | + if (p->mls_enabled) |
|---|
| 723 | + pr_debug("SELinux: %d users, %d roles, %d types, %d bools, %d sens, %d cats\n", |
|---|
| 724 | + p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, |
|---|
| 725 | + p->p_bools.nprim, p->p_levels.nprim, p->p_cats.nprim); |
|---|
| 726 | + else |
|---|
| 727 | + pr_debug("SELinux: %d users, %d roles, %d types, %d bools\n", |
|---|
| 728 | + p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, |
|---|
| 729 | + p->p_bools.nprim); |
|---|
| 730 | + |
|---|
| 731 | + pr_debug("SELinux: %d classes, %d rules\n", |
|---|
| 732 | + p->p_classes.nprim, p->te_avtab.nel); |
|---|
| 733 | + |
|---|
| 734 | +#ifdef DEBUG_HASHES |
|---|
| 735 | + avtab_hash_eval(&p->te_avtab, "rules"); |
|---|
| 736 | + symtab_hash_eval(p->symtab); |
|---|
| 737 | +#endif |
|---|
| 738 | + |
|---|
| 739 | + p->class_val_to_struct = kcalloc(p->p_classes.nprim, |
|---|
| 740 | + sizeof(*p->class_val_to_struct), |
|---|
| 741 | + GFP_KERNEL); |
|---|
| 742 | + if (!p->class_val_to_struct) |
|---|
| 743 | + return -ENOMEM; |
|---|
| 744 | + |
|---|
| 745 | + p->role_val_to_struct = kcalloc(p->p_roles.nprim, |
|---|
| 746 | + sizeof(*p->role_val_to_struct), |
|---|
| 747 | + GFP_KERNEL); |
|---|
| 748 | + if (!p->role_val_to_struct) |
|---|
| 749 | + return -ENOMEM; |
|---|
| 750 | + |
|---|
| 751 | + p->user_val_to_struct = kcalloc(p->p_users.nprim, |
|---|
| 752 | + sizeof(*p->user_val_to_struct), |
|---|
| 753 | + GFP_KERNEL); |
|---|
| 754 | + if (!p->user_val_to_struct) |
|---|
| 755 | + return -ENOMEM; |
|---|
| 756 | + |
|---|
| 757 | + p->type_val_to_struct = kvcalloc(p->p_types.nprim, |
|---|
| 758 | + sizeof(*p->type_val_to_struct), |
|---|
| 759 | + GFP_KERNEL); |
|---|
| 760 | + if (!p->type_val_to_struct) |
|---|
| 761 | + return -ENOMEM; |
|---|
| 762 | + |
|---|
| 763 | + rc = cond_init_bool_indexes(p); |
|---|
| 764 | + if (rc) |
|---|
| 765 | + goto out; |
|---|
| 766 | + |
|---|
| 767 | + for (i = 0; i < SYM_NUM; i++) { |
|---|
| 768 | + p->sym_val_to_name[i] = kvcalloc(p->symtab[i].nprim, |
|---|
| 769 | + sizeof(char *), |
|---|
| 770 | + GFP_KERNEL); |
|---|
| 771 | + if (!p->sym_val_to_name[i]) |
|---|
| 772 | + return -ENOMEM; |
|---|
| 773 | + |
|---|
| 774 | + rc = hashtab_map(&p->symtab[i].table, index_f[i], p); |
|---|
| 775 | + if (rc) |
|---|
| 776 | + goto out; |
|---|
| 777 | + } |
|---|
| 778 | + rc = 0; |
|---|
| 779 | +out: |
|---|
| 780 | + return rc; |
|---|
| 781 | +} |
|---|
| 782 | + |
|---|
| 783 | +/* |
|---|
| 801 | 784 | * Free any memory allocated by a policy database structure. |
|---|
| 802 | 785 | */ |
|---|
| 803 | 786 | void policydb_destroy(struct policydb *p) |
|---|
| .. | .. |
|---|
| 806 | 789 | struct genfs *g, *gtmp; |
|---|
| 807 | 790 | int i; |
|---|
| 808 | 791 | struct role_allow *ra, *lra = NULL; |
|---|
| 809 | | - struct role_trans *tr, *ltr = NULL; |
|---|
| 810 | 792 | |
|---|
| 811 | 793 | for (i = 0; i < SYM_NUM; i++) { |
|---|
| 812 | 794 | cond_resched(); |
|---|
| 813 | | - hashtab_map(p->symtab[i].table, destroy_f[i], NULL); |
|---|
| 814 | | - hashtab_destroy(p->symtab[i].table); |
|---|
| 795 | + hashtab_map(&p->symtab[i].table, destroy_f[i], NULL); |
|---|
| 796 | + hashtab_destroy(&p->symtab[i].table); |
|---|
| 815 | 797 | } |
|---|
| 816 | 798 | |
|---|
| 817 | | - for (i = 0; i < SYM_NUM; i++) { |
|---|
| 818 | | - if (p->sym_val_to_name[i]) |
|---|
| 819 | | - flex_array_free(p->sym_val_to_name[i]); |
|---|
| 820 | | - } |
|---|
| 799 | + for (i = 0; i < SYM_NUM; i++) |
|---|
| 800 | + kvfree(p->sym_val_to_name[i]); |
|---|
| 821 | 801 | |
|---|
| 822 | 802 | kfree(p->class_val_to_struct); |
|---|
| 823 | 803 | kfree(p->role_val_to_struct); |
|---|
| 824 | 804 | kfree(p->user_val_to_struct); |
|---|
| 825 | | - if (p->type_val_to_struct_array) |
|---|
| 826 | | - flex_array_free(p->type_val_to_struct_array); |
|---|
| 805 | + kvfree(p->type_val_to_struct); |
|---|
| 827 | 806 | |
|---|
| 828 | 807 | avtab_destroy(&p->te_avtab); |
|---|
| 829 | 808 | |
|---|
| .. | .. |
|---|
| 856 | 835 | |
|---|
| 857 | 836 | cond_policydb_destroy(p); |
|---|
| 858 | 837 | |
|---|
| 859 | | - for (tr = p->role_tr; tr; tr = tr->next) { |
|---|
| 860 | | - cond_resched(); |
|---|
| 861 | | - kfree(ltr); |
|---|
| 862 | | - ltr = tr; |
|---|
| 863 | | - } |
|---|
| 864 | | - kfree(ltr); |
|---|
| 838 | + hashtab_map(&p->role_tr, role_tr_destroy, NULL); |
|---|
| 839 | + hashtab_destroy(&p->role_tr); |
|---|
| 865 | 840 | |
|---|
| 866 | 841 | for (ra = p->role_allow; ra; ra = ra->next) { |
|---|
| 867 | 842 | cond_resched(); |
|---|
| .. | .. |
|---|
| 870 | 845 | } |
|---|
| 871 | 846 | kfree(lra); |
|---|
| 872 | 847 | |
|---|
| 873 | | - hashtab_map(p->filename_trans, filenametr_destroy, NULL); |
|---|
| 874 | | - hashtab_destroy(p->filename_trans); |
|---|
| 848 | + hashtab_map(&p->filename_trans, filenametr_destroy, NULL); |
|---|
| 849 | + hashtab_destroy(&p->filename_trans); |
|---|
| 875 | 850 | |
|---|
| 876 | | - hashtab_map(p->range_tr, range_tr_destroy, NULL); |
|---|
| 877 | | - hashtab_destroy(p->range_tr); |
|---|
| 851 | + hashtab_map(&p->range_tr, range_tr_destroy, NULL); |
|---|
| 852 | + hashtab_destroy(&p->range_tr); |
|---|
| 878 | 853 | |
|---|
| 879 | 854 | if (p->type_attr_map_array) { |
|---|
| 880 | | - for (i = 0; i < p->p_types.nprim; i++) { |
|---|
| 881 | | - struct ebitmap *e; |
|---|
| 882 | | - |
|---|
| 883 | | - e = flex_array_get(p->type_attr_map_array, i); |
|---|
| 884 | | - if (!e) |
|---|
| 885 | | - continue; |
|---|
| 886 | | - ebitmap_destroy(e); |
|---|
| 887 | | - } |
|---|
| 888 | | - flex_array_free(p->type_attr_map_array); |
|---|
| 855 | + for (i = 0; i < p->p_types.nprim; i++) |
|---|
| 856 | + ebitmap_destroy(&p->type_attr_map_array[i]); |
|---|
| 857 | + kvfree(p->type_attr_map_array); |
|---|
| 889 | 858 | } |
|---|
| 890 | 859 | |
|---|
| 891 | 860 | ebitmap_destroy(&p->filename_trans_ttypes); |
|---|
| .. | .. |
|---|
| 905 | 874 | rc = sidtab_init(s); |
|---|
| 906 | 875 | if (rc) { |
|---|
| 907 | 876 | pr_err("SELinux: out of memory on SID table init\n"); |
|---|
| 908 | | - goto out; |
|---|
| 877 | + return rc; |
|---|
| 909 | 878 | } |
|---|
| 910 | 879 | |
|---|
| 911 | 880 | head = p->ocontexts[OCON_ISID]; |
|---|
| 912 | 881 | for (c = head; c; c = c->next) { |
|---|
| 913 | | - rc = -EINVAL; |
|---|
| 914 | | - if (!c->context[0].user) { |
|---|
| 915 | | - pr_err("SELinux: SID %s was never defined.\n", |
|---|
| 916 | | - c->u.name); |
|---|
| 882 | + u32 sid = c->sid[0]; |
|---|
| 883 | + const char *name = security_get_initial_sid_context(sid); |
|---|
| 884 | + |
|---|
| 885 | + if (sid == SECSID_NULL) { |
|---|
| 886 | + pr_err("SELinux: SID 0 was assigned a context.\n"); |
|---|
| 917 | 887 | sidtab_destroy(s); |
|---|
| 918 | | - goto out; |
|---|
| 919 | | - } |
|---|
| 920 | | - if (c->sid[0] == SECSID_NULL || c->sid[0] > SECINITSID_NUM) { |
|---|
| 921 | | - pr_err("SELinux: Initial SID %s out of range.\n", |
|---|
| 922 | | - c->u.name); |
|---|
| 923 | | - sidtab_destroy(s); |
|---|
| 924 | | - goto out; |
|---|
| 925 | | - } |
|---|
| 926 | | - rc = context_add_hash(p, &c->context[0]); |
|---|
| 927 | | - if (rc) { |
|---|
| 928 | | - sidtab_destroy(s); |
|---|
| 929 | | - goto out; |
|---|
| 888 | + return -EINVAL; |
|---|
| 930 | 889 | } |
|---|
| 931 | 890 | |
|---|
| 932 | | - rc = sidtab_set_initial(s, c->sid[0], &c->context[0]); |
|---|
| 891 | + /* Ignore initial SIDs unused by this kernel. */ |
|---|
| 892 | + if (!name) |
|---|
| 893 | + continue; |
|---|
| 894 | + |
|---|
| 895 | + rc = sidtab_set_initial(s, sid, &c->context[0]); |
|---|
| 933 | 896 | if (rc) { |
|---|
| 934 | 897 | pr_err("SELinux: unable to load initial SID %s.\n", |
|---|
| 935 | | - c->u.name); |
|---|
| 898 | + name); |
|---|
| 936 | 899 | sidtab_destroy(s); |
|---|
| 937 | | - goto out; |
|---|
| 900 | + return rc; |
|---|
| 938 | 901 | } |
|---|
| 939 | 902 | } |
|---|
| 940 | | - rc = 0; |
|---|
| 941 | | -out: |
|---|
| 942 | | - return rc; |
|---|
| 903 | + return 0; |
|---|
| 943 | 904 | } |
|---|
| 944 | 905 | |
|---|
| 945 | 906 | int policydb_class_isvalid(struct policydb *p, unsigned int class) |
|---|
| .. | .. |
|---|
| 1123 | 1084 | if (!str) |
|---|
| 1124 | 1085 | return -ENOMEM; |
|---|
| 1125 | 1086 | |
|---|
| 1126 | | - /* it's expected the caller should free the str */ |
|---|
| 1127 | | - *strp = str; |
|---|
| 1128 | | - |
|---|
| 1129 | 1087 | rc = next_entry(str, fp, len); |
|---|
| 1130 | | - if (rc) |
|---|
| 1088 | + if (rc) { |
|---|
| 1089 | + kfree(str); |
|---|
| 1131 | 1090 | return rc; |
|---|
| 1091 | + } |
|---|
| 1132 | 1092 | |
|---|
| 1133 | 1093 | str[len] = '\0'; |
|---|
| 1094 | + *strp = str; |
|---|
| 1134 | 1095 | return 0; |
|---|
| 1135 | 1096 | } |
|---|
| 1136 | 1097 | |
|---|
| 1137 | | -static int perm_read(struct policydb *p, struct hashtab *h, void *fp) |
|---|
| 1098 | +static int perm_read(struct policydb *p, struct symtab *s, void *fp) |
|---|
| 1138 | 1099 | { |
|---|
| 1139 | 1100 | char *key = NULL; |
|---|
| 1140 | 1101 | struct perm_datum *perdatum; |
|---|
| .. | .. |
|---|
| 1157 | 1118 | if (rc) |
|---|
| 1158 | 1119 | goto bad; |
|---|
| 1159 | 1120 | |
|---|
| 1160 | | - rc = hashtab_insert(h, key, perdatum); |
|---|
| 1121 | + rc = symtab_insert(s, key, perdatum); |
|---|
| 1161 | 1122 | if (rc) |
|---|
| 1162 | 1123 | goto bad; |
|---|
| 1163 | 1124 | |
|---|
| .. | .. |
|---|
| 1167 | 1128 | return rc; |
|---|
| 1168 | 1129 | } |
|---|
| 1169 | 1130 | |
|---|
| 1170 | | -static int common_read(struct policydb *p, struct hashtab *h, void *fp) |
|---|
| 1131 | +static int common_read(struct policydb *p, struct symtab *s, void *fp) |
|---|
| 1171 | 1132 | { |
|---|
| 1172 | 1133 | char *key = NULL; |
|---|
| 1173 | 1134 | struct common_datum *comdatum; |
|---|
| .. | .. |
|---|
| 1185 | 1146 | |
|---|
| 1186 | 1147 | len = le32_to_cpu(buf[0]); |
|---|
| 1187 | 1148 | comdatum->value = le32_to_cpu(buf[1]); |
|---|
| 1149 | + nel = le32_to_cpu(buf[3]); |
|---|
| 1188 | 1150 | |
|---|
| 1189 | | - rc = symtab_init(&comdatum->permissions, PERM_SYMTAB_SIZE); |
|---|
| 1151 | + rc = symtab_init(&comdatum->permissions, nel); |
|---|
| 1190 | 1152 | if (rc) |
|---|
| 1191 | 1153 | goto bad; |
|---|
| 1192 | 1154 | comdatum->permissions.nprim = le32_to_cpu(buf[2]); |
|---|
| 1193 | | - nel = le32_to_cpu(buf[3]); |
|---|
| 1194 | 1155 | |
|---|
| 1195 | 1156 | rc = str_read(&key, GFP_KERNEL, fp, len); |
|---|
| 1196 | 1157 | if (rc) |
|---|
| 1197 | 1158 | goto bad; |
|---|
| 1198 | 1159 | |
|---|
| 1199 | 1160 | for (i = 0; i < nel; i++) { |
|---|
| 1200 | | - rc = perm_read(p, comdatum->permissions.table, fp); |
|---|
| 1161 | + rc = perm_read(p, &comdatum->permissions, fp); |
|---|
| 1201 | 1162 | if (rc) |
|---|
| 1202 | 1163 | goto bad; |
|---|
| 1203 | 1164 | } |
|---|
| 1204 | 1165 | |
|---|
| 1205 | | - rc = hashtab_insert(h, key, comdatum); |
|---|
| 1166 | + rc = symtab_insert(s, key, comdatum); |
|---|
| 1206 | 1167 | if (rc) |
|---|
| 1207 | 1168 | goto bad; |
|---|
| 1208 | 1169 | return 0; |
|---|
| .. | .. |
|---|
| 1307 | 1268 | if (rc) |
|---|
| 1308 | 1269 | return rc; |
|---|
| 1309 | 1270 | if (p->policyvers >= |
|---|
| 1310 | | - POLICYDB_VERSION_CONSTRAINT_NAMES) { |
|---|
| 1311 | | - e->type_names = kzalloc(sizeof |
|---|
| 1312 | | - (*e->type_names), |
|---|
| 1313 | | - GFP_KERNEL); |
|---|
| 1271 | + POLICYDB_VERSION_CONSTRAINT_NAMES) { |
|---|
| 1272 | + e->type_names = kzalloc(sizeof |
|---|
| 1273 | + (*e->type_names), GFP_KERNEL); |
|---|
| 1314 | 1274 | if (!e->type_names) |
|---|
| 1315 | 1275 | return -ENOMEM; |
|---|
| 1316 | 1276 | type_set_init(e->type_names); |
|---|
| .. | .. |
|---|
| 1332 | 1292 | return 0; |
|---|
| 1333 | 1293 | } |
|---|
| 1334 | 1294 | |
|---|
| 1335 | | -static int class_read(struct policydb *p, struct hashtab *h, void *fp) |
|---|
| 1295 | +static int class_read(struct policydb *p, struct symtab *s, void *fp) |
|---|
| 1336 | 1296 | { |
|---|
| 1337 | 1297 | char *key = NULL; |
|---|
| 1338 | 1298 | struct class_datum *cladatum; |
|---|
| .. | .. |
|---|
| 1351 | 1311 | len = le32_to_cpu(buf[0]); |
|---|
| 1352 | 1312 | len2 = le32_to_cpu(buf[1]); |
|---|
| 1353 | 1313 | cladatum->value = le32_to_cpu(buf[2]); |
|---|
| 1314 | + nel = le32_to_cpu(buf[4]); |
|---|
| 1354 | 1315 | |
|---|
| 1355 | | - rc = symtab_init(&cladatum->permissions, PERM_SYMTAB_SIZE); |
|---|
| 1316 | + rc = symtab_init(&cladatum->permissions, nel); |
|---|
| 1356 | 1317 | if (rc) |
|---|
| 1357 | 1318 | goto bad; |
|---|
| 1358 | 1319 | cladatum->permissions.nprim = le32_to_cpu(buf[3]); |
|---|
| 1359 | | - nel = le32_to_cpu(buf[4]); |
|---|
| 1360 | 1320 | |
|---|
| 1361 | 1321 | ncons = le32_to_cpu(buf[5]); |
|---|
| 1362 | 1322 | |
|---|
| .. | .. |
|---|
| 1370 | 1330 | goto bad; |
|---|
| 1371 | 1331 | |
|---|
| 1372 | 1332 | rc = -EINVAL; |
|---|
| 1373 | | - cladatum->comdatum = hashtab_search(p->p_commons.table, cladatum->comkey); |
|---|
| 1333 | + cladatum->comdatum = symtab_search(&p->p_commons, |
|---|
| 1334 | + cladatum->comkey); |
|---|
| 1374 | 1335 | if (!cladatum->comdatum) { |
|---|
| 1375 | 1336 | pr_err("SELinux: unknown common %s\n", |
|---|
| 1376 | 1337 | cladatum->comkey); |
|---|
| .. | .. |
|---|
| 1378 | 1339 | } |
|---|
| 1379 | 1340 | } |
|---|
| 1380 | 1341 | for (i = 0; i < nel; i++) { |
|---|
| 1381 | | - rc = perm_read(p, cladatum->permissions.table, fp); |
|---|
| 1342 | + rc = perm_read(p, &cladatum->permissions, fp); |
|---|
| 1382 | 1343 | if (rc) |
|---|
| 1383 | 1344 | goto bad; |
|---|
| 1384 | 1345 | } |
|---|
| .. | .. |
|---|
| 1416 | 1377 | cladatum->default_type = le32_to_cpu(buf[0]); |
|---|
| 1417 | 1378 | } |
|---|
| 1418 | 1379 | |
|---|
| 1419 | | - rc = hashtab_insert(h, key, cladatum); |
|---|
| 1380 | + rc = symtab_insert(s, key, cladatum); |
|---|
| 1420 | 1381 | if (rc) |
|---|
| 1421 | 1382 | goto bad; |
|---|
| 1422 | 1383 | |
|---|
| .. | .. |
|---|
| 1426 | 1387 | return rc; |
|---|
| 1427 | 1388 | } |
|---|
| 1428 | 1389 | |
|---|
| 1429 | | -static int role_read(struct policydb *p, struct hashtab *h, void *fp) |
|---|
| 1390 | +static int role_read(struct policydb *p, struct symtab *s, void *fp) |
|---|
| 1430 | 1391 | { |
|---|
| 1431 | 1392 | char *key = NULL; |
|---|
| 1432 | 1393 | struct role_datum *role; |
|---|
| .. | .. |
|---|
| 1473 | 1434 | goto bad; |
|---|
| 1474 | 1435 | } |
|---|
| 1475 | 1436 | |
|---|
| 1476 | | - rc = hashtab_insert(h, key, role); |
|---|
| 1437 | + rc = symtab_insert(s, key, role); |
|---|
| 1477 | 1438 | if (rc) |
|---|
| 1478 | 1439 | goto bad; |
|---|
| 1479 | 1440 | return 0; |
|---|
| .. | .. |
|---|
| 1482 | 1443 | return rc; |
|---|
| 1483 | 1444 | } |
|---|
| 1484 | 1445 | |
|---|
| 1485 | | -static int type_read(struct policydb *p, struct hashtab *h, void *fp) |
|---|
| 1446 | +static int type_read(struct policydb *p, struct symtab *s, void *fp) |
|---|
| 1486 | 1447 | { |
|---|
| 1487 | 1448 | char *key = NULL; |
|---|
| 1488 | 1449 | struct type_datum *typdatum; |
|---|
| .. | .. |
|---|
| 1520 | 1481 | if (rc) |
|---|
| 1521 | 1482 | goto bad; |
|---|
| 1522 | 1483 | |
|---|
| 1523 | | - rc = hashtab_insert(h, key, typdatum); |
|---|
| 1484 | + rc = symtab_insert(s, key, typdatum); |
|---|
| 1524 | 1485 | if (rc) |
|---|
| 1525 | 1486 | goto bad; |
|---|
| 1526 | 1487 | return 0; |
|---|
| .. | .. |
|---|
| 1556 | 1517 | return 0; |
|---|
| 1557 | 1518 | } |
|---|
| 1558 | 1519 | |
|---|
| 1559 | | -static int user_read(struct policydb *p, struct hashtab *h, void *fp) |
|---|
| 1520 | +static int user_read(struct policydb *p, struct symtab *s, void *fp) |
|---|
| 1560 | 1521 | { |
|---|
| 1561 | 1522 | char *key = NULL; |
|---|
| 1562 | 1523 | struct user_datum *usrdatum; |
|---|
| .. | .. |
|---|
| 1597 | 1558 | goto bad; |
|---|
| 1598 | 1559 | } |
|---|
| 1599 | 1560 | |
|---|
| 1600 | | - rc = hashtab_insert(h, key, usrdatum); |
|---|
| 1561 | + rc = symtab_insert(s, key, usrdatum); |
|---|
| 1601 | 1562 | if (rc) |
|---|
| 1602 | 1563 | goto bad; |
|---|
| 1603 | 1564 | return 0; |
|---|
| .. | .. |
|---|
| 1606 | 1567 | return rc; |
|---|
| 1607 | 1568 | } |
|---|
| 1608 | 1569 | |
|---|
| 1609 | | -static int sens_read(struct policydb *p, struct hashtab *h, void *fp) |
|---|
| 1570 | +static int sens_read(struct policydb *p, struct symtab *s, void *fp) |
|---|
| 1610 | 1571 | { |
|---|
| 1611 | 1572 | char *key = NULL; |
|---|
| 1612 | 1573 | struct level_datum *levdatum; |
|---|
| .. | .. |
|---|
| 1638 | 1599 | if (rc) |
|---|
| 1639 | 1600 | goto bad; |
|---|
| 1640 | 1601 | |
|---|
| 1641 | | - rc = hashtab_insert(h, key, levdatum); |
|---|
| 1602 | + rc = symtab_insert(s, key, levdatum); |
|---|
| 1642 | 1603 | if (rc) |
|---|
| 1643 | 1604 | goto bad; |
|---|
| 1644 | 1605 | return 0; |
|---|
| .. | .. |
|---|
| 1647 | 1608 | return rc; |
|---|
| 1648 | 1609 | } |
|---|
| 1649 | 1610 | |
|---|
| 1650 | | -static int cat_read(struct policydb *p, struct hashtab *h, void *fp) |
|---|
| 1611 | +static int cat_read(struct policydb *p, struct symtab *s, void *fp) |
|---|
| 1651 | 1612 | { |
|---|
| 1652 | 1613 | char *key = NULL; |
|---|
| 1653 | 1614 | struct cat_datum *catdatum; |
|---|
| .. | .. |
|---|
| 1671 | 1632 | if (rc) |
|---|
| 1672 | 1633 | goto bad; |
|---|
| 1673 | 1634 | |
|---|
| 1674 | | - rc = hashtab_insert(h, key, catdatum); |
|---|
| 1635 | + rc = symtab_insert(s, key, catdatum); |
|---|
| 1675 | 1636 | if (rc) |
|---|
| 1676 | 1637 | goto bad; |
|---|
| 1677 | 1638 | return 0; |
|---|
| .. | .. |
|---|
| 1680 | 1641 | return rc; |
|---|
| 1681 | 1642 | } |
|---|
| 1682 | 1643 | |
|---|
| 1683 | | -static int (*read_f[SYM_NUM]) (struct policydb *p, struct hashtab *h, void *fp) = |
|---|
| 1644 | +static int (*read_f[SYM_NUM]) (struct policydb *p, struct symtab *s, void *fp) = |
|---|
| 1684 | 1645 | { |
|---|
| 1685 | 1646 | common_read, |
|---|
| 1686 | 1647 | class_read, |
|---|
| .. | .. |
|---|
| 1779 | 1740 | return -EINVAL; |
|---|
| 1780 | 1741 | } |
|---|
| 1781 | 1742 | |
|---|
| 1782 | | - upper = flex_array_get_ptr(p->type_val_to_struct_array, |
|---|
| 1783 | | - upper->bounds - 1); |
|---|
| 1743 | + upper = p->type_val_to_struct[upper->bounds - 1]; |
|---|
| 1784 | 1744 | BUG_ON(!upper); |
|---|
| 1785 | 1745 | |
|---|
| 1786 | 1746 | if (upper->attribute) { |
|---|
| .. | .. |
|---|
| 1802 | 1762 | if (p->policyvers < POLICYDB_VERSION_BOUNDARY) |
|---|
| 1803 | 1763 | return 0; |
|---|
| 1804 | 1764 | |
|---|
| 1805 | | - rc = hashtab_map(p->p_users.table, |
|---|
| 1806 | | - user_bounds_sanity_check, p); |
|---|
| 1765 | + rc = hashtab_map(&p->p_users.table, user_bounds_sanity_check, p); |
|---|
| 1807 | 1766 | if (rc) |
|---|
| 1808 | 1767 | return rc; |
|---|
| 1809 | 1768 | |
|---|
| 1810 | | - rc = hashtab_map(p->p_roles.table, |
|---|
| 1811 | | - role_bounds_sanity_check, p); |
|---|
| 1769 | + rc = hashtab_map(&p->p_roles.table, role_bounds_sanity_check, p); |
|---|
| 1812 | 1770 | if (rc) |
|---|
| 1813 | 1771 | return rc; |
|---|
| 1814 | 1772 | |
|---|
| 1815 | | - rc = hashtab_map(p->p_types.table, |
|---|
| 1816 | | - type_bounds_sanity_check, p); |
|---|
| 1773 | + rc = hashtab_map(&p->p_types.table, type_bounds_sanity_check, p); |
|---|
| 1817 | 1774 | if (rc) |
|---|
| 1818 | 1775 | return rc; |
|---|
| 1819 | 1776 | |
|---|
| .. | .. |
|---|
| 1824 | 1781 | { |
|---|
| 1825 | 1782 | struct class_datum *cladatum; |
|---|
| 1826 | 1783 | |
|---|
| 1827 | | - cladatum = hashtab_search(p->p_classes.table, name); |
|---|
| 1784 | + cladatum = symtab_search(&p->p_classes, name); |
|---|
| 1828 | 1785 | if (!cladatum) |
|---|
| 1829 | 1786 | return 0; |
|---|
| 1830 | 1787 | |
|---|
| .. | .. |
|---|
| 1843 | 1800 | cladatum = p->class_val_to_struct[tclass-1]; |
|---|
| 1844 | 1801 | comdatum = cladatum->comdatum; |
|---|
| 1845 | 1802 | if (comdatum) |
|---|
| 1846 | | - perdatum = hashtab_search(comdatum->permissions.table, |
|---|
| 1847 | | - name); |
|---|
| 1803 | + perdatum = symtab_search(&comdatum->permissions, name); |
|---|
| 1848 | 1804 | if (!perdatum) |
|---|
| 1849 | | - perdatum = hashtab_search(cladatum->permissions.table, |
|---|
| 1850 | | - name); |
|---|
| 1805 | + perdatum = symtab_search(&cladatum->permissions, name); |
|---|
| 1851 | 1806 | if (!perdatum) |
|---|
| 1852 | 1807 | return 0; |
|---|
| 1853 | 1808 | |
|---|
| .. | .. |
|---|
| 1870 | 1825 | return rc; |
|---|
| 1871 | 1826 | |
|---|
| 1872 | 1827 | nel = le32_to_cpu(buf[0]); |
|---|
| 1828 | + |
|---|
| 1829 | + rc = hashtab_init(&p->range_tr, nel); |
|---|
| 1830 | + if (rc) |
|---|
| 1831 | + return rc; |
|---|
| 1832 | + |
|---|
| 1873 | 1833 | for (i = 0; i < nel; i++) { |
|---|
| 1874 | 1834 | rc = -ENOMEM; |
|---|
| 1875 | 1835 | rt = kzalloc(sizeof(*rt), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 1911 | 1871 | goto out; |
|---|
| 1912 | 1872 | } |
|---|
| 1913 | 1873 | |
|---|
| 1914 | | - rc = hashtab_insert(p->range_tr, rt, r); |
|---|
| 1874 | + rc = hashtab_insert(&p->range_tr, rt, r, rangetr_key_params); |
|---|
| 1915 | 1875 | if (rc) |
|---|
| 1916 | 1876 | goto out; |
|---|
| 1917 | 1877 | |
|---|
| 1918 | 1878 | rt = NULL; |
|---|
| 1919 | 1879 | r = NULL; |
|---|
| 1920 | 1880 | } |
|---|
| 1921 | | - hash_eval(p->range_tr, "rangetr"); |
|---|
| 1881 | + hash_eval(&p->range_tr, "rangetr"); |
|---|
| 1922 | 1882 | rc = 0; |
|---|
| 1923 | 1883 | out: |
|---|
| 1924 | 1884 | kfree(rt); |
|---|
| .. | .. |
|---|
| 1926 | 1886 | return rc; |
|---|
| 1927 | 1887 | } |
|---|
| 1928 | 1888 | |
|---|
| 1889 | +static int filename_trans_read_helper_compat(struct policydb *p, void *fp) |
|---|
| 1890 | +{ |
|---|
| 1891 | + struct filename_trans_key key, *ft = NULL; |
|---|
| 1892 | + struct filename_trans_datum *last, *datum = NULL; |
|---|
| 1893 | + char *name = NULL; |
|---|
| 1894 | + u32 len, stype, otype; |
|---|
| 1895 | + __le32 buf[4]; |
|---|
| 1896 | + int rc; |
|---|
| 1897 | + |
|---|
| 1898 | + /* length of the path component string */ |
|---|
| 1899 | + rc = next_entry(buf, fp, sizeof(u32)); |
|---|
| 1900 | + if (rc) |
|---|
| 1901 | + return rc; |
|---|
| 1902 | + len = le32_to_cpu(buf[0]); |
|---|
| 1903 | + |
|---|
| 1904 | + /* path component string */ |
|---|
| 1905 | + rc = str_read(&name, GFP_KERNEL, fp, len); |
|---|
| 1906 | + if (rc) |
|---|
| 1907 | + return rc; |
|---|
| 1908 | + |
|---|
| 1909 | + rc = next_entry(buf, fp, sizeof(u32) * 4); |
|---|
| 1910 | + if (rc) |
|---|
| 1911 | + goto out; |
|---|
| 1912 | + |
|---|
| 1913 | + stype = le32_to_cpu(buf[0]); |
|---|
| 1914 | + key.ttype = le32_to_cpu(buf[1]); |
|---|
| 1915 | + key.tclass = le32_to_cpu(buf[2]); |
|---|
| 1916 | + key.name = name; |
|---|
| 1917 | + |
|---|
| 1918 | + otype = le32_to_cpu(buf[3]); |
|---|
| 1919 | + |
|---|
| 1920 | + last = NULL; |
|---|
| 1921 | + datum = policydb_filenametr_search(p, &key); |
|---|
| 1922 | + while (datum) { |
|---|
| 1923 | + if (unlikely(ebitmap_get_bit(&datum->stypes, stype - 1))) { |
|---|
| 1924 | + /* conflicting/duplicate rules are ignored */ |
|---|
| 1925 | + datum = NULL; |
|---|
| 1926 | + goto out; |
|---|
| 1927 | + } |
|---|
| 1928 | + if (likely(datum->otype == otype)) |
|---|
| 1929 | + break; |
|---|
| 1930 | + last = datum; |
|---|
| 1931 | + datum = datum->next; |
|---|
| 1932 | + } |
|---|
| 1933 | + if (!datum) { |
|---|
| 1934 | + rc = -ENOMEM; |
|---|
| 1935 | + datum = kmalloc(sizeof(*datum), GFP_KERNEL); |
|---|
| 1936 | + if (!datum) |
|---|
| 1937 | + goto out; |
|---|
| 1938 | + |
|---|
| 1939 | + ebitmap_init(&datum->stypes); |
|---|
| 1940 | + datum->otype = otype; |
|---|
| 1941 | + datum->next = NULL; |
|---|
| 1942 | + |
|---|
| 1943 | + if (unlikely(last)) { |
|---|
| 1944 | + last->next = datum; |
|---|
| 1945 | + } else { |
|---|
| 1946 | + rc = -ENOMEM; |
|---|
| 1947 | + ft = kmemdup(&key, sizeof(key), GFP_KERNEL); |
|---|
| 1948 | + if (!ft) |
|---|
| 1949 | + goto out; |
|---|
| 1950 | + |
|---|
| 1951 | + rc = hashtab_insert(&p->filename_trans, ft, datum, |
|---|
| 1952 | + filenametr_key_params); |
|---|
| 1953 | + if (rc) |
|---|
| 1954 | + goto out; |
|---|
| 1955 | + name = NULL; |
|---|
| 1956 | + |
|---|
| 1957 | + rc = ebitmap_set_bit(&p->filename_trans_ttypes, |
|---|
| 1958 | + key.ttype, 1); |
|---|
| 1959 | + if (rc) |
|---|
| 1960 | + return rc; |
|---|
| 1961 | + } |
|---|
| 1962 | + } |
|---|
| 1963 | + kfree(name); |
|---|
| 1964 | + return ebitmap_set_bit(&datum->stypes, stype - 1, 1); |
|---|
| 1965 | + |
|---|
| 1966 | +out: |
|---|
| 1967 | + kfree(ft); |
|---|
| 1968 | + kfree(name); |
|---|
| 1969 | + kfree(datum); |
|---|
| 1970 | + return rc; |
|---|
| 1971 | +} |
|---|
| 1972 | + |
|---|
| 1973 | +static int filename_trans_read_helper(struct policydb *p, void *fp) |
|---|
| 1974 | +{ |
|---|
| 1975 | + struct filename_trans_key *ft = NULL; |
|---|
| 1976 | + struct filename_trans_datum **dst, *datum, *first = NULL; |
|---|
| 1977 | + char *name = NULL; |
|---|
| 1978 | + u32 len, ttype, tclass, ndatum, i; |
|---|
| 1979 | + __le32 buf[3]; |
|---|
| 1980 | + int rc; |
|---|
| 1981 | + |
|---|
| 1982 | + /* length of the path component string */ |
|---|
| 1983 | + rc = next_entry(buf, fp, sizeof(u32)); |
|---|
| 1984 | + if (rc) |
|---|
| 1985 | + return rc; |
|---|
| 1986 | + len = le32_to_cpu(buf[0]); |
|---|
| 1987 | + |
|---|
| 1988 | + /* path component string */ |
|---|
| 1989 | + rc = str_read(&name, GFP_KERNEL, fp, len); |
|---|
| 1990 | + if (rc) |
|---|
| 1991 | + return rc; |
|---|
| 1992 | + |
|---|
| 1993 | + rc = next_entry(buf, fp, sizeof(u32) * 3); |
|---|
| 1994 | + if (rc) |
|---|
| 1995 | + goto out; |
|---|
| 1996 | + |
|---|
| 1997 | + ttype = le32_to_cpu(buf[0]); |
|---|
| 1998 | + tclass = le32_to_cpu(buf[1]); |
|---|
| 1999 | + |
|---|
| 2000 | + ndatum = le32_to_cpu(buf[2]); |
|---|
| 2001 | + if (ndatum == 0) { |
|---|
| 2002 | + pr_err("SELinux: Filename transition key with no datum\n"); |
|---|
| 2003 | + rc = -ENOENT; |
|---|
| 2004 | + goto out; |
|---|
| 2005 | + } |
|---|
| 2006 | + |
|---|
| 2007 | + dst = &first; |
|---|
| 2008 | + for (i = 0; i < ndatum; i++) { |
|---|
| 2009 | + rc = -ENOMEM; |
|---|
| 2010 | + datum = kmalloc(sizeof(*datum), GFP_KERNEL); |
|---|
| 2011 | + if (!datum) |
|---|
| 2012 | + goto out; |
|---|
| 2013 | + |
|---|
| 2014 | + datum->next = NULL; |
|---|
| 2015 | + *dst = datum; |
|---|
| 2016 | + |
|---|
| 2017 | + /* ebitmap_read() will at least init the bitmap */ |
|---|
| 2018 | + rc = ebitmap_read(&datum->stypes, fp); |
|---|
| 2019 | + if (rc) |
|---|
| 2020 | + goto out; |
|---|
| 2021 | + |
|---|
| 2022 | + rc = next_entry(buf, fp, sizeof(u32)); |
|---|
| 2023 | + if (rc) |
|---|
| 2024 | + goto out; |
|---|
| 2025 | + |
|---|
| 2026 | + datum->otype = le32_to_cpu(buf[0]); |
|---|
| 2027 | + |
|---|
| 2028 | + dst = &datum->next; |
|---|
| 2029 | + } |
|---|
| 2030 | + |
|---|
| 2031 | + rc = -ENOMEM; |
|---|
| 2032 | + ft = kmalloc(sizeof(*ft), GFP_KERNEL); |
|---|
| 2033 | + if (!ft) |
|---|
| 2034 | + goto out; |
|---|
| 2035 | + |
|---|
| 2036 | + ft->ttype = ttype; |
|---|
| 2037 | + ft->tclass = tclass; |
|---|
| 2038 | + ft->name = name; |
|---|
| 2039 | + |
|---|
| 2040 | + rc = hashtab_insert(&p->filename_trans, ft, first, |
|---|
| 2041 | + filenametr_key_params); |
|---|
| 2042 | + if (rc == -EEXIST) |
|---|
| 2043 | + pr_err("SELinux: Duplicate filename transition key\n"); |
|---|
| 2044 | + if (rc) |
|---|
| 2045 | + goto out; |
|---|
| 2046 | + |
|---|
| 2047 | + return ebitmap_set_bit(&p->filename_trans_ttypes, ttype, 1); |
|---|
| 2048 | + |
|---|
| 2049 | +out: |
|---|
| 2050 | + kfree(ft); |
|---|
| 2051 | + kfree(name); |
|---|
| 2052 | + while (first) { |
|---|
| 2053 | + datum = first; |
|---|
| 2054 | + first = first->next; |
|---|
| 2055 | + |
|---|
| 2056 | + ebitmap_destroy(&datum->stypes); |
|---|
| 2057 | + kfree(datum); |
|---|
| 2058 | + } |
|---|
| 2059 | + return rc; |
|---|
| 2060 | +} |
|---|
| 2061 | + |
|---|
| 1929 | 2062 | static int filename_trans_read(struct policydb *p, void *fp) |
|---|
| 1930 | 2063 | { |
|---|
| 1931 | | - struct filename_trans *ft; |
|---|
| 1932 | | - struct filename_trans_datum *otype; |
|---|
| 1933 | | - char *name; |
|---|
| 1934 | | - u32 nel, len; |
|---|
| 1935 | | - __le32 buf[4]; |
|---|
| 2064 | + u32 nel; |
|---|
| 2065 | + __le32 buf[1]; |
|---|
| 1936 | 2066 | int rc, i; |
|---|
| 1937 | 2067 | |
|---|
| 1938 | 2068 | if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS) |
|---|
| .. | .. |
|---|
| 1943 | 2073 | return rc; |
|---|
| 1944 | 2074 | nel = le32_to_cpu(buf[0]); |
|---|
| 1945 | 2075 | |
|---|
| 1946 | | - for (i = 0; i < nel; i++) { |
|---|
| 1947 | | - otype = NULL; |
|---|
| 1948 | | - name = NULL; |
|---|
| 2076 | + if (p->policyvers < POLICYDB_VERSION_COMP_FTRANS) { |
|---|
| 2077 | + p->compat_filename_trans_count = nel; |
|---|
| 1949 | 2078 | |
|---|
| 1950 | | - rc = -ENOMEM; |
|---|
| 1951 | | - ft = kzalloc(sizeof(*ft), GFP_KERNEL); |
|---|
| 1952 | | - if (!ft) |
|---|
| 1953 | | - goto out; |
|---|
| 1954 | | - |
|---|
| 1955 | | - rc = -ENOMEM; |
|---|
| 1956 | | - otype = kmalloc(sizeof(*otype), GFP_KERNEL); |
|---|
| 1957 | | - if (!otype) |
|---|
| 1958 | | - goto out; |
|---|
| 1959 | | - |
|---|
| 1960 | | - /* length of the path component string */ |
|---|
| 1961 | | - rc = next_entry(buf, fp, sizeof(u32)); |
|---|
| 2079 | + rc = hashtab_init(&p->filename_trans, (1 << 11)); |
|---|
| 1962 | 2080 | if (rc) |
|---|
| 1963 | | - goto out; |
|---|
| 1964 | | - len = le32_to_cpu(buf[0]); |
|---|
| 2081 | + return rc; |
|---|
| 1965 | 2082 | |
|---|
| 1966 | | - /* path component string */ |
|---|
| 1967 | | - rc = str_read(&name, GFP_KERNEL, fp, len); |
|---|
| 2083 | + for (i = 0; i < nel; i++) { |
|---|
| 2084 | + rc = filename_trans_read_helper_compat(p, fp); |
|---|
| 2085 | + if (rc) |
|---|
| 2086 | + return rc; |
|---|
| 2087 | + } |
|---|
| 2088 | + } else { |
|---|
| 2089 | + rc = hashtab_init(&p->filename_trans, nel); |
|---|
| 1968 | 2090 | if (rc) |
|---|
| 1969 | | - goto out; |
|---|
| 2091 | + return rc; |
|---|
| 1970 | 2092 | |
|---|
| 1971 | | - ft->name = name; |
|---|
| 1972 | | - |
|---|
| 1973 | | - rc = next_entry(buf, fp, sizeof(u32) * 4); |
|---|
| 1974 | | - if (rc) |
|---|
| 1975 | | - goto out; |
|---|
| 1976 | | - |
|---|
| 1977 | | - ft->stype = le32_to_cpu(buf[0]); |
|---|
| 1978 | | - ft->ttype = le32_to_cpu(buf[1]); |
|---|
| 1979 | | - ft->tclass = le32_to_cpu(buf[2]); |
|---|
| 1980 | | - |
|---|
| 1981 | | - otype->otype = le32_to_cpu(buf[3]); |
|---|
| 1982 | | - |
|---|
| 1983 | | - rc = ebitmap_set_bit(&p->filename_trans_ttypes, ft->ttype, 1); |
|---|
| 1984 | | - if (rc) |
|---|
| 1985 | | - goto out; |
|---|
| 1986 | | - |
|---|
| 1987 | | - rc = hashtab_insert(p->filename_trans, ft, otype); |
|---|
| 1988 | | - if (rc) { |
|---|
| 1989 | | - /* |
|---|
| 1990 | | - * Do not return -EEXIST to the caller, or the system |
|---|
| 1991 | | - * will not boot. |
|---|
| 1992 | | - */ |
|---|
| 1993 | | - if (rc != -EEXIST) |
|---|
| 1994 | | - goto out; |
|---|
| 1995 | | - /* But free memory to avoid memory leak. */ |
|---|
| 1996 | | - kfree(ft); |
|---|
| 1997 | | - kfree(name); |
|---|
| 1998 | | - kfree(otype); |
|---|
| 2093 | + for (i = 0; i < nel; i++) { |
|---|
| 2094 | + rc = filename_trans_read_helper(p, fp); |
|---|
| 2095 | + if (rc) |
|---|
| 2096 | + return rc; |
|---|
| 1999 | 2097 | } |
|---|
| 2000 | 2098 | } |
|---|
| 2001 | | - hash_eval(p->filename_trans, "filenametr"); |
|---|
| 2099 | + hash_eval(&p->filename_trans, "filenametr"); |
|---|
| 2002 | 2100 | return 0; |
|---|
| 2003 | | -out: |
|---|
| 2004 | | - kfree(ft); |
|---|
| 2005 | | - kfree(name); |
|---|
| 2006 | | - kfree(otype); |
|---|
| 2007 | | - |
|---|
| 2008 | | - return rc; |
|---|
| 2009 | 2101 | } |
|---|
| 2010 | 2102 | |
|---|
| 2011 | 2103 | static int genfs_read(struct policydb *p, void *fp) |
|---|
| .. | .. |
|---|
| 2310 | 2402 | int policydb_read(struct policydb *p, void *fp) |
|---|
| 2311 | 2403 | { |
|---|
| 2312 | 2404 | struct role_allow *ra, *lra; |
|---|
| 2313 | | - struct role_trans *tr, *ltr; |
|---|
| 2405 | + struct role_trans_key *rtk = NULL; |
|---|
| 2406 | + struct role_trans_datum *rtd = NULL; |
|---|
| 2314 | 2407 | int i, j, rc; |
|---|
| 2315 | 2408 | __le32 buf[4]; |
|---|
| 2316 | | - u32 len, nprim, nel; |
|---|
| 2409 | + u32 len, nprim, nel, perm; |
|---|
| 2317 | 2410 | |
|---|
| 2318 | 2411 | char *policydb_str; |
|---|
| 2319 | 2412 | struct policydb_compat_info *info; |
|---|
| 2320 | 2413 | |
|---|
| 2321 | | - rc = policydb_init(p); |
|---|
| 2322 | | - if (rc) |
|---|
| 2323 | | - return rc; |
|---|
| 2414 | + policydb_init(p); |
|---|
| 2324 | 2415 | |
|---|
| 2325 | 2416 | /* Read the magic number and string length. */ |
|---|
| 2326 | 2417 | rc = next_entry(buf, fp, sizeof(u32) * 2); |
|---|
| .. | .. |
|---|
| 2444 | 2535 | goto bad; |
|---|
| 2445 | 2536 | nprim = le32_to_cpu(buf[0]); |
|---|
| 2446 | 2537 | nel = le32_to_cpu(buf[1]); |
|---|
| 2538 | + |
|---|
| 2539 | + rc = symtab_init(&p->symtab[i], nel); |
|---|
| 2540 | + if (rc) |
|---|
| 2541 | + goto out; |
|---|
| 2542 | + |
|---|
| 2543 | + if (i == SYM_ROLES) { |
|---|
| 2544 | + rc = roles_init(p); |
|---|
| 2545 | + if (rc) |
|---|
| 2546 | + goto out; |
|---|
| 2547 | + } |
|---|
| 2548 | + |
|---|
| 2447 | 2549 | for (j = 0; j < nel; j++) { |
|---|
| 2448 | | - rc = read_f[i](p, p->symtab[i].table, fp); |
|---|
| 2550 | + rc = read_f[i](p, &p->symtab[i], fp); |
|---|
| 2449 | 2551 | if (rc) |
|---|
| 2450 | 2552 | goto bad; |
|---|
| 2451 | 2553 | } |
|---|
| .. | .. |
|---|
| 2455 | 2557 | |
|---|
| 2456 | 2558 | rc = -EINVAL; |
|---|
| 2457 | 2559 | p->process_class = string_to_security_class(p, "process"); |
|---|
| 2458 | | - if (!p->process_class) |
|---|
| 2560 | + if (!p->process_class) { |
|---|
| 2561 | + pr_err("SELinux: process class is required, not defined in policy\n"); |
|---|
| 2459 | 2562 | goto bad; |
|---|
| 2563 | + } |
|---|
| 2460 | 2564 | |
|---|
| 2461 | 2565 | rc = avtab_read(&p->te_avtab, fp, p); |
|---|
| 2462 | 2566 | if (rc) |
|---|
| .. | .. |
|---|
| 2472 | 2576 | if (rc) |
|---|
| 2473 | 2577 | goto bad; |
|---|
| 2474 | 2578 | nel = le32_to_cpu(buf[0]); |
|---|
| 2475 | | - ltr = NULL; |
|---|
| 2579 | + |
|---|
| 2580 | + rc = hashtab_init(&p->role_tr, nel); |
|---|
| 2581 | + if (rc) |
|---|
| 2582 | + goto bad; |
|---|
| 2476 | 2583 | for (i = 0; i < nel; i++) { |
|---|
| 2477 | 2584 | rc = -ENOMEM; |
|---|
| 2478 | | - tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
|---|
| 2479 | | - if (!tr) |
|---|
| 2585 | + rtk = kmalloc(sizeof(*rtk), GFP_KERNEL); |
|---|
| 2586 | + if (!rtk) |
|---|
| 2480 | 2587 | goto bad; |
|---|
| 2481 | | - if (ltr) |
|---|
| 2482 | | - ltr->next = tr; |
|---|
| 2483 | | - else |
|---|
| 2484 | | - p->role_tr = tr; |
|---|
| 2588 | + |
|---|
| 2589 | + rc = -ENOMEM; |
|---|
| 2590 | + rtd = kmalloc(sizeof(*rtd), GFP_KERNEL); |
|---|
| 2591 | + if (!rtd) |
|---|
| 2592 | + goto bad; |
|---|
| 2593 | + |
|---|
| 2485 | 2594 | rc = next_entry(buf, fp, sizeof(u32)*3); |
|---|
| 2486 | 2595 | if (rc) |
|---|
| 2487 | 2596 | goto bad; |
|---|
| 2488 | 2597 | |
|---|
| 2489 | 2598 | rc = -EINVAL; |
|---|
| 2490 | | - tr->role = le32_to_cpu(buf[0]); |
|---|
| 2491 | | - tr->type = le32_to_cpu(buf[1]); |
|---|
| 2492 | | - tr->new_role = le32_to_cpu(buf[2]); |
|---|
| 2599 | + rtk->role = le32_to_cpu(buf[0]); |
|---|
| 2600 | + rtk->type = le32_to_cpu(buf[1]); |
|---|
| 2601 | + rtd->new_role = le32_to_cpu(buf[2]); |
|---|
| 2493 | 2602 | if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) { |
|---|
| 2494 | 2603 | rc = next_entry(buf, fp, sizeof(u32)); |
|---|
| 2495 | 2604 | if (rc) |
|---|
| 2496 | 2605 | goto bad; |
|---|
| 2497 | | - tr->tclass = le32_to_cpu(buf[0]); |
|---|
| 2606 | + rtk->tclass = le32_to_cpu(buf[0]); |
|---|
| 2498 | 2607 | } else |
|---|
| 2499 | | - tr->tclass = p->process_class; |
|---|
| 2608 | + rtk->tclass = p->process_class; |
|---|
| 2500 | 2609 | |
|---|
| 2501 | 2610 | rc = -EINVAL; |
|---|
| 2502 | | - if (!policydb_role_isvalid(p, tr->role) || |
|---|
| 2503 | | - !policydb_type_isvalid(p, tr->type) || |
|---|
| 2504 | | - !policydb_class_isvalid(p, tr->tclass) || |
|---|
| 2505 | | - !policydb_role_isvalid(p, tr->new_role)) |
|---|
| 2611 | + if (!policydb_role_isvalid(p, rtk->role) || |
|---|
| 2612 | + !policydb_type_isvalid(p, rtk->type) || |
|---|
| 2613 | + !policydb_class_isvalid(p, rtk->tclass) || |
|---|
| 2614 | + !policydb_role_isvalid(p, rtd->new_role)) |
|---|
| 2506 | 2615 | goto bad; |
|---|
| 2507 | | - ltr = tr; |
|---|
| 2616 | + |
|---|
| 2617 | + rc = hashtab_insert(&p->role_tr, rtk, rtd, roletr_key_params); |
|---|
| 2618 | + if (rc) |
|---|
| 2619 | + goto bad; |
|---|
| 2620 | + |
|---|
| 2621 | + rtk = NULL; |
|---|
| 2622 | + rtd = NULL; |
|---|
| 2508 | 2623 | } |
|---|
| 2509 | 2624 | |
|---|
| 2510 | 2625 | rc = next_entry(buf, fp, sizeof(u32)); |
|---|
| .. | .. |
|---|
| 2543 | 2658 | goto bad; |
|---|
| 2544 | 2659 | |
|---|
| 2545 | 2660 | rc = -EINVAL; |
|---|
| 2546 | | - p->process_trans_perms = string_to_av_perm(p, p->process_class, "transition"); |
|---|
| 2547 | | - p->process_trans_perms |= string_to_av_perm(p, p->process_class, "dyntransition"); |
|---|
| 2548 | | - if (!p->process_trans_perms) |
|---|
| 2661 | + perm = string_to_av_perm(p, p->process_class, "transition"); |
|---|
| 2662 | + if (!perm) { |
|---|
| 2663 | + pr_err("SELinux: process transition permission is required, not defined in policy\n"); |
|---|
| 2549 | 2664 | goto bad; |
|---|
| 2665 | + } |
|---|
| 2666 | + p->process_trans_perms = perm; |
|---|
| 2667 | + perm = string_to_av_perm(p, p->process_class, "dyntransition"); |
|---|
| 2668 | + if (!perm) { |
|---|
| 2669 | + pr_err("SELinux: process dyntransition permission is required, not defined in policy\n"); |
|---|
| 2670 | + goto bad; |
|---|
| 2671 | + } |
|---|
| 2672 | + p->process_trans_perms |= perm; |
|---|
| 2550 | 2673 | |
|---|
| 2551 | 2674 | rc = ocontext_read(p, info, fp); |
|---|
| 2552 | 2675 | if (rc) |
|---|
| .. | .. |
|---|
| 2561 | 2684 | goto bad; |
|---|
| 2562 | 2685 | |
|---|
| 2563 | 2686 | rc = -ENOMEM; |
|---|
| 2564 | | - p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap), |
|---|
| 2565 | | - p->p_types.nprim, |
|---|
| 2566 | | - GFP_KERNEL | __GFP_ZERO); |
|---|
| 2687 | + p->type_attr_map_array = kvcalloc(p->p_types.nprim, |
|---|
| 2688 | + sizeof(*p->type_attr_map_array), |
|---|
| 2689 | + GFP_KERNEL); |
|---|
| 2567 | 2690 | if (!p->type_attr_map_array) |
|---|
| 2568 | 2691 | goto bad; |
|---|
| 2569 | 2692 | |
|---|
| 2570 | | - /* preallocate so we don't have to worry about the put ever failing */ |
|---|
| 2571 | | - rc = flex_array_prealloc(p->type_attr_map_array, 0, p->p_types.nprim, |
|---|
| 2572 | | - GFP_KERNEL | __GFP_ZERO); |
|---|
| 2573 | | - if (rc) |
|---|
| 2574 | | - goto bad; |
|---|
| 2693 | + /* just in case ebitmap_init() becomes more than just a memset(0): */ |
|---|
| 2694 | + for (i = 0; i < p->p_types.nprim; i++) |
|---|
| 2695 | + ebitmap_init(&p->type_attr_map_array[i]); |
|---|
| 2575 | 2696 | |
|---|
| 2576 | 2697 | for (i = 0; i < p->p_types.nprim; i++) { |
|---|
| 2577 | | - struct ebitmap *e = flex_array_get(p->type_attr_map_array, i); |
|---|
| 2698 | + struct ebitmap *e = &p->type_attr_map_array[i]; |
|---|
| 2578 | 2699 | |
|---|
| 2579 | | - BUG_ON(!e); |
|---|
| 2580 | | - ebitmap_init(e); |
|---|
| 2581 | 2700 | if (p->policyvers >= POLICYDB_VERSION_AVTAB) { |
|---|
| 2582 | 2701 | rc = ebitmap_read(e, fp); |
|---|
| 2583 | 2702 | if (rc) |
|---|
| .. | .. |
|---|
| 2597 | 2716 | out: |
|---|
| 2598 | 2717 | return rc; |
|---|
| 2599 | 2718 | bad: |
|---|
| 2719 | + kfree(rtk); |
|---|
| 2720 | + kfree(rtd); |
|---|
| 2600 | 2721 | policydb_destroy(p); |
|---|
| 2601 | 2722 | goto out; |
|---|
| 2602 | 2723 | } |
|---|
| .. | .. |
|---|
| 2714 | 2835 | return 0; |
|---|
| 2715 | 2836 | } |
|---|
| 2716 | 2837 | |
|---|
| 2717 | | -static int role_trans_write(struct policydb *p, void *fp) |
|---|
| 2838 | +static int role_trans_write_one(void *key, void *datum, void *ptr) |
|---|
| 2718 | 2839 | { |
|---|
| 2719 | | - struct role_trans *r = p->role_tr; |
|---|
| 2720 | | - struct role_trans *tr; |
|---|
| 2721 | | - u32 buf[3]; |
|---|
| 2722 | | - size_t nel; |
|---|
| 2840 | + struct role_trans_key *rtk = key; |
|---|
| 2841 | + struct role_trans_datum *rtd = datum; |
|---|
| 2842 | + struct policy_data *pd = ptr; |
|---|
| 2843 | + void *fp = pd->fp; |
|---|
| 2844 | + struct policydb *p = pd->p; |
|---|
| 2845 | + __le32 buf[3]; |
|---|
| 2723 | 2846 | int rc; |
|---|
| 2724 | 2847 | |
|---|
| 2725 | | - nel = 0; |
|---|
| 2726 | | - for (tr = r; tr; tr = tr->next) |
|---|
| 2727 | | - nel++; |
|---|
| 2728 | | - buf[0] = cpu_to_le32(nel); |
|---|
| 2848 | + buf[0] = cpu_to_le32(rtk->role); |
|---|
| 2849 | + buf[1] = cpu_to_le32(rtk->type); |
|---|
| 2850 | + buf[2] = cpu_to_le32(rtd->new_role); |
|---|
| 2851 | + rc = put_entry(buf, sizeof(u32), 3, fp); |
|---|
| 2852 | + if (rc) |
|---|
| 2853 | + return rc; |
|---|
| 2854 | + if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) { |
|---|
| 2855 | + buf[0] = cpu_to_le32(rtk->tclass); |
|---|
| 2856 | + rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 2857 | + if (rc) |
|---|
| 2858 | + return rc; |
|---|
| 2859 | + } |
|---|
| 2860 | + return 0; |
|---|
| 2861 | +} |
|---|
| 2862 | + |
|---|
| 2863 | +static int role_trans_write(struct policydb *p, void *fp) |
|---|
| 2864 | +{ |
|---|
| 2865 | + struct policy_data pd = { .p = p, .fp = fp }; |
|---|
| 2866 | + __le32 buf[1]; |
|---|
| 2867 | + int rc; |
|---|
| 2868 | + |
|---|
| 2869 | + buf[0] = cpu_to_le32(p->role_tr.nel); |
|---|
| 2729 | 2870 | rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 2730 | 2871 | if (rc) |
|---|
| 2731 | 2872 | return rc; |
|---|
| 2732 | | - for (tr = r; tr; tr = tr->next) { |
|---|
| 2733 | | - buf[0] = cpu_to_le32(tr->role); |
|---|
| 2734 | | - buf[1] = cpu_to_le32(tr->type); |
|---|
| 2735 | | - buf[2] = cpu_to_le32(tr->new_role); |
|---|
| 2736 | | - rc = put_entry(buf, sizeof(u32), 3, fp); |
|---|
| 2737 | | - if (rc) |
|---|
| 2738 | | - return rc; |
|---|
| 2739 | | - if (p->policyvers >= POLICYDB_VERSION_ROLETRANS) { |
|---|
| 2740 | | - buf[0] = cpu_to_le32(tr->tclass); |
|---|
| 2741 | | - rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 2742 | | - if (rc) |
|---|
| 2743 | | - return rc; |
|---|
| 2744 | | - } |
|---|
| 2745 | | - } |
|---|
| 2746 | 2873 | |
|---|
| 2747 | | - return 0; |
|---|
| 2874 | + return hashtab_map(&p->role_tr, role_trans_write_one, &pd); |
|---|
| 2748 | 2875 | } |
|---|
| 2749 | 2876 | |
|---|
| 2750 | 2877 | static int role_allow_write(struct role_allow *r, void *fp) |
|---|
| 2751 | 2878 | { |
|---|
| 2752 | 2879 | struct role_allow *ra; |
|---|
| 2753 | | - u32 buf[2]; |
|---|
| 2880 | + __le32 buf[2]; |
|---|
| 2754 | 2881 | size_t nel; |
|---|
| 2755 | 2882 | int rc; |
|---|
| 2756 | 2883 | |
|---|
| .. | .. |
|---|
| 2838 | 2965 | buf[0] = cpu_to_le32(len); |
|---|
| 2839 | 2966 | buf[1] = cpu_to_le32(comdatum->value); |
|---|
| 2840 | 2967 | buf[2] = cpu_to_le32(comdatum->permissions.nprim); |
|---|
| 2841 | | - buf[3] = cpu_to_le32(comdatum->permissions.table->nel); |
|---|
| 2968 | + buf[3] = cpu_to_le32(comdatum->permissions.table.nel); |
|---|
| 2842 | 2969 | rc = put_entry(buf, sizeof(u32), 4, fp); |
|---|
| 2843 | 2970 | if (rc) |
|---|
| 2844 | 2971 | return rc; |
|---|
| .. | .. |
|---|
| 2847 | 2974 | if (rc) |
|---|
| 2848 | 2975 | return rc; |
|---|
| 2849 | 2976 | |
|---|
| 2850 | | - rc = hashtab_map(comdatum->permissions.table, perm_write, fp); |
|---|
| 2977 | + rc = hashtab_map(&comdatum->permissions.table, perm_write, fp); |
|---|
| 2851 | 2978 | if (rc) |
|---|
| 2852 | 2979 | return rc; |
|---|
| 2853 | 2980 | |
|---|
| .. | .. |
|---|
| 2946 | 3073 | buf[1] = cpu_to_le32(len2); |
|---|
| 2947 | 3074 | buf[2] = cpu_to_le32(cladatum->value); |
|---|
| 2948 | 3075 | buf[3] = cpu_to_le32(cladatum->permissions.nprim); |
|---|
| 2949 | | - if (cladatum->permissions.table) |
|---|
| 2950 | | - buf[4] = cpu_to_le32(cladatum->permissions.table->nel); |
|---|
| 2951 | | - else |
|---|
| 2952 | | - buf[4] = 0; |
|---|
| 3076 | + buf[4] = cpu_to_le32(cladatum->permissions.table.nel); |
|---|
| 2953 | 3077 | buf[5] = cpu_to_le32(ncons); |
|---|
| 2954 | 3078 | rc = put_entry(buf, sizeof(u32), 6, fp); |
|---|
| 2955 | 3079 | if (rc) |
|---|
| .. | .. |
|---|
| 2965 | 3089 | return rc; |
|---|
| 2966 | 3090 | } |
|---|
| 2967 | 3091 | |
|---|
| 2968 | | - rc = hashtab_map(cladatum->permissions.table, perm_write, fp); |
|---|
| 3092 | + rc = hashtab_map(&cladatum->permissions.table, perm_write, fp); |
|---|
| 2969 | 3093 | if (rc) |
|---|
| 2970 | 3094 | return rc; |
|---|
| 2971 | 3095 | |
|---|
| .. | .. |
|---|
| 3323 | 3447 | return 0; |
|---|
| 3324 | 3448 | } |
|---|
| 3325 | 3449 | |
|---|
| 3326 | | -static int hashtab_cnt(void *key, void *data, void *ptr) |
|---|
| 3327 | | -{ |
|---|
| 3328 | | - int *cnt = ptr; |
|---|
| 3329 | | - *cnt = *cnt + 1; |
|---|
| 3330 | | - |
|---|
| 3331 | | - return 0; |
|---|
| 3332 | | -} |
|---|
| 3333 | | - |
|---|
| 3334 | 3450 | static int range_write_helper(void *key, void *data, void *ptr) |
|---|
| 3335 | 3451 | { |
|---|
| 3336 | 3452 | __le32 buf[2]; |
|---|
| .. | .. |
|---|
| 3362 | 3478 | static int range_write(struct policydb *p, void *fp) |
|---|
| 3363 | 3479 | { |
|---|
| 3364 | 3480 | __le32 buf[1]; |
|---|
| 3365 | | - int rc, nel; |
|---|
| 3481 | + int rc; |
|---|
| 3366 | 3482 | struct policy_data pd; |
|---|
| 3367 | 3483 | |
|---|
| 3368 | 3484 | pd.p = p; |
|---|
| 3369 | 3485 | pd.fp = fp; |
|---|
| 3370 | 3486 | |
|---|
| 3371 | | - /* count the number of entries in the hashtab */ |
|---|
| 3372 | | - nel = 0; |
|---|
| 3373 | | - rc = hashtab_map(p->range_tr, hashtab_cnt, &nel); |
|---|
| 3374 | | - if (rc) |
|---|
| 3375 | | - return rc; |
|---|
| 3376 | | - |
|---|
| 3377 | | - buf[0] = cpu_to_le32(nel); |
|---|
| 3487 | + buf[0] = cpu_to_le32(p->range_tr.nel); |
|---|
| 3378 | 3488 | rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 3379 | 3489 | if (rc) |
|---|
| 3380 | 3490 | return rc; |
|---|
| 3381 | 3491 | |
|---|
| 3382 | 3492 | /* actually write all of the entries */ |
|---|
| 3383 | | - rc = hashtab_map(p->range_tr, range_write_helper, &pd); |
|---|
| 3493 | + rc = hashtab_map(&p->range_tr, range_write_helper, &pd); |
|---|
| 3384 | 3494 | if (rc) |
|---|
| 3385 | 3495 | return rc; |
|---|
| 3386 | 3496 | |
|---|
| 3387 | 3497 | return 0; |
|---|
| 3388 | 3498 | } |
|---|
| 3389 | 3499 | |
|---|
| 3500 | +static int filename_write_helper_compat(void *key, void *data, void *ptr) |
|---|
| 3501 | +{ |
|---|
| 3502 | + struct filename_trans_key *ft = key; |
|---|
| 3503 | + struct filename_trans_datum *datum = data; |
|---|
| 3504 | + struct ebitmap_node *node; |
|---|
| 3505 | + void *fp = ptr; |
|---|
| 3506 | + __le32 buf[4]; |
|---|
| 3507 | + int rc; |
|---|
| 3508 | + u32 bit, len = strlen(ft->name); |
|---|
| 3509 | + |
|---|
| 3510 | + do { |
|---|
| 3511 | + ebitmap_for_each_positive_bit(&datum->stypes, node, bit) { |
|---|
| 3512 | + buf[0] = cpu_to_le32(len); |
|---|
| 3513 | + rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 3514 | + if (rc) |
|---|
| 3515 | + return rc; |
|---|
| 3516 | + |
|---|
| 3517 | + rc = put_entry(ft->name, sizeof(char), len, fp); |
|---|
| 3518 | + if (rc) |
|---|
| 3519 | + return rc; |
|---|
| 3520 | + |
|---|
| 3521 | + buf[0] = cpu_to_le32(bit + 1); |
|---|
| 3522 | + buf[1] = cpu_to_le32(ft->ttype); |
|---|
| 3523 | + buf[2] = cpu_to_le32(ft->tclass); |
|---|
| 3524 | + buf[3] = cpu_to_le32(datum->otype); |
|---|
| 3525 | + |
|---|
| 3526 | + rc = put_entry(buf, sizeof(u32), 4, fp); |
|---|
| 3527 | + if (rc) |
|---|
| 3528 | + return rc; |
|---|
| 3529 | + } |
|---|
| 3530 | + |
|---|
| 3531 | + datum = datum->next; |
|---|
| 3532 | + } while (unlikely(datum)); |
|---|
| 3533 | + |
|---|
| 3534 | + return 0; |
|---|
| 3535 | +} |
|---|
| 3536 | + |
|---|
| 3390 | 3537 | static int filename_write_helper(void *key, void *data, void *ptr) |
|---|
| 3391 | 3538 | { |
|---|
| 3392 | | - __le32 buf[4]; |
|---|
| 3393 | | - struct filename_trans *ft = key; |
|---|
| 3394 | | - struct filename_trans_datum *otype = data; |
|---|
| 3539 | + struct filename_trans_key *ft = key; |
|---|
| 3540 | + struct filename_trans_datum *datum; |
|---|
| 3395 | 3541 | void *fp = ptr; |
|---|
| 3542 | + __le32 buf[3]; |
|---|
| 3396 | 3543 | int rc; |
|---|
| 3397 | | - u32 len; |
|---|
| 3544 | + u32 ndatum, len = strlen(ft->name); |
|---|
| 3398 | 3545 | |
|---|
| 3399 | | - len = strlen(ft->name); |
|---|
| 3400 | 3546 | buf[0] = cpu_to_le32(len); |
|---|
| 3401 | 3547 | rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 3402 | 3548 | if (rc) |
|---|
| .. | .. |
|---|
| 3406 | 3552 | if (rc) |
|---|
| 3407 | 3553 | return rc; |
|---|
| 3408 | 3554 | |
|---|
| 3409 | | - buf[0] = cpu_to_le32(ft->stype); |
|---|
| 3410 | | - buf[1] = cpu_to_le32(ft->ttype); |
|---|
| 3411 | | - buf[2] = cpu_to_le32(ft->tclass); |
|---|
| 3412 | | - buf[3] = cpu_to_le32(otype->otype); |
|---|
| 3555 | + ndatum = 0; |
|---|
| 3556 | + datum = data; |
|---|
| 3557 | + do { |
|---|
| 3558 | + ndatum++; |
|---|
| 3559 | + datum = datum->next; |
|---|
| 3560 | + } while (unlikely(datum)); |
|---|
| 3413 | 3561 | |
|---|
| 3414 | | - rc = put_entry(buf, sizeof(u32), 4, fp); |
|---|
| 3562 | + buf[0] = cpu_to_le32(ft->ttype); |
|---|
| 3563 | + buf[1] = cpu_to_le32(ft->tclass); |
|---|
| 3564 | + buf[2] = cpu_to_le32(ndatum); |
|---|
| 3565 | + rc = put_entry(buf, sizeof(u32), 3, fp); |
|---|
| 3415 | 3566 | if (rc) |
|---|
| 3416 | 3567 | return rc; |
|---|
| 3568 | + |
|---|
| 3569 | + datum = data; |
|---|
| 3570 | + do { |
|---|
| 3571 | + rc = ebitmap_write(&datum->stypes, fp); |
|---|
| 3572 | + if (rc) |
|---|
| 3573 | + return rc; |
|---|
| 3574 | + |
|---|
| 3575 | + buf[0] = cpu_to_le32(datum->otype); |
|---|
| 3576 | + rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 3577 | + if (rc) |
|---|
| 3578 | + return rc; |
|---|
| 3579 | + |
|---|
| 3580 | + datum = datum->next; |
|---|
| 3581 | + } while (unlikely(datum)); |
|---|
| 3417 | 3582 | |
|---|
| 3418 | 3583 | return 0; |
|---|
| 3419 | 3584 | } |
|---|
| 3420 | 3585 | |
|---|
| 3421 | 3586 | static int filename_trans_write(struct policydb *p, void *fp) |
|---|
| 3422 | 3587 | { |
|---|
| 3423 | | - u32 nel; |
|---|
| 3424 | 3588 | __le32 buf[1]; |
|---|
| 3425 | 3589 | int rc; |
|---|
| 3426 | 3590 | |
|---|
| 3427 | 3591 | if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS) |
|---|
| 3428 | 3592 | return 0; |
|---|
| 3429 | 3593 | |
|---|
| 3430 | | - nel = 0; |
|---|
| 3431 | | - rc = hashtab_map(p->filename_trans, hashtab_cnt, &nel); |
|---|
| 3432 | | - if (rc) |
|---|
| 3433 | | - return rc; |
|---|
| 3594 | + if (p->policyvers < POLICYDB_VERSION_COMP_FTRANS) { |
|---|
| 3595 | + buf[0] = cpu_to_le32(p->compat_filename_trans_count); |
|---|
| 3596 | + rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 3597 | + if (rc) |
|---|
| 3598 | + return rc; |
|---|
| 3434 | 3599 | |
|---|
| 3435 | | - buf[0] = cpu_to_le32(nel); |
|---|
| 3436 | | - rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 3437 | | - if (rc) |
|---|
| 3438 | | - return rc; |
|---|
| 3600 | + rc = hashtab_map(&p->filename_trans, |
|---|
| 3601 | + filename_write_helper_compat, fp); |
|---|
| 3602 | + } else { |
|---|
| 3603 | + buf[0] = cpu_to_le32(p->filename_trans.nel); |
|---|
| 3604 | + rc = put_entry(buf, sizeof(u32), 1, fp); |
|---|
| 3605 | + if (rc) |
|---|
| 3606 | + return rc; |
|---|
| 3439 | 3607 | |
|---|
| 3440 | | - rc = hashtab_map(p->filename_trans, filename_write_helper, fp); |
|---|
| 3441 | | - if (rc) |
|---|
| 3442 | | - return rc; |
|---|
| 3443 | | - |
|---|
| 3444 | | - return 0; |
|---|
| 3608 | + rc = hashtab_map(&p->filename_trans, filename_write_helper, fp); |
|---|
| 3609 | + } |
|---|
| 3610 | + return rc; |
|---|
| 3445 | 3611 | } |
|---|
| 3446 | 3612 | |
|---|
| 3447 | 3613 | /* |
|---|
| .. | .. |
|---|
| 3528 | 3694 | pd.p = p; |
|---|
| 3529 | 3695 | |
|---|
| 3530 | 3696 | buf[0] = cpu_to_le32(p->symtab[i].nprim); |
|---|
| 3531 | | - buf[1] = cpu_to_le32(p->symtab[i].table->nel); |
|---|
| 3697 | + buf[1] = cpu_to_le32(p->symtab[i].table.nel); |
|---|
| 3532 | 3698 | |
|---|
| 3533 | 3699 | rc = put_entry(buf, sizeof(u32), 2, fp); |
|---|
| 3534 | 3700 | if (rc) |
|---|
| 3535 | 3701 | return rc; |
|---|
| 3536 | | - rc = hashtab_map(p->symtab[i].table, write_f[i], &pd); |
|---|
| 3702 | + rc = hashtab_map(&p->symtab[i].table, write_f[i], &pd); |
|---|
| 3537 | 3703 | if (rc) |
|---|
| 3538 | 3704 | return rc; |
|---|
| 3539 | 3705 | } |
|---|
| .. | .. |
|---|
| 3542 | 3708 | if (rc) |
|---|
| 3543 | 3709 | return rc; |
|---|
| 3544 | 3710 | |
|---|
| 3545 | | - rc = cond_write_list(p, p->cond_list, fp); |
|---|
| 3711 | + rc = cond_write_list(p, fp); |
|---|
| 3546 | 3712 | if (rc) |
|---|
| 3547 | 3713 | return rc; |
|---|
| 3548 | 3714 | |
|---|
| .. | .. |
|---|
| 3571 | 3737 | return rc; |
|---|
| 3572 | 3738 | |
|---|
| 3573 | 3739 | for (i = 0; i < p->p_types.nprim; i++) { |
|---|
| 3574 | | - struct ebitmap *e = flex_array_get(p->type_attr_map_array, i); |
|---|
| 3740 | + struct ebitmap *e = &p->type_attr_map_array[i]; |
|---|
| 3575 | 3741 | |
|---|
| 3576 | | - BUG_ON(!e); |
|---|
| 3577 | 3742 | rc = ebitmap_write(e, fp); |
|---|
| 3578 | 3743 | if (rc) |
|---|
| 3579 | 3744 | return rc; |
|---|