diff options
| -rw-r--r-- | security/selinux/ss/policydb.c | 69 |
1 files changed, 10 insertions, 59 deletions
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 5adca670e5af..be9de3872837 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c | |||
| @@ -411,58 +411,6 @@ static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) = | |||
| 411 | cat_index, | 411 | cat_index, |
| 412 | }; | 412 | }; |
| 413 | 413 | ||
| 414 | /* | ||
| 415 | * Define the common val_to_name array and the class | ||
| 416 | * val_to_name and val_to_struct arrays in a policy | ||
| 417 | * database structure. | ||
| 418 | * | ||
| 419 | * Caller must clean up upon failure. | ||
| 420 | */ | ||
| 421 | static int policydb_index_classes(struct policydb *p) | ||
| 422 | { | ||
| 423 | int rc; | ||
| 424 | |||
| 425 | rc = -ENOMEM; | ||
| 426 | p->sym_val_to_name[SYM_COMMONS] = flex_array_alloc(sizeof(char *), | ||
| 427 | p->p_commons.nprim, | ||
| 428 | GFP_KERNEL | __GFP_ZERO); | ||
| 429 | if (!p->sym_val_to_name[SYM_COMMONS]) | ||
| 430 | goto out; | ||
| 431 | |||
| 432 | rc = flex_array_prealloc(p->sym_val_to_name[SYM_COMMONS], | ||
| 433 | 0, p->p_commons.nprim - 1, | ||
| 434 | GFP_KERNEL | __GFP_ZERO); | ||
| 435 | if (rc) | ||
| 436 | goto out; | ||
| 437 | |||
| 438 | rc = hashtab_map(p->p_commons.table, common_index, p); | ||
| 439 | if (rc) | ||
| 440 | goto out; | ||
| 441 | |||
| 442 | rc = -ENOMEM; | ||
| 443 | p->class_val_to_struct = | ||
| 444 | kmalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)), GFP_KERNEL); | ||
| 445 | if (!p->class_val_to_struct) | ||
| 446 | goto out; | ||
| 447 | |||
| 448 | rc = -ENOMEM; | ||
| 449 | p->sym_val_to_name[SYM_CLASSES] = flex_array_alloc(sizeof(char *), | ||
| 450 | p->p_classes.nprim, | ||
| 451 | GFP_KERNEL | __GFP_ZERO); | ||
| 452 | if (!p->sym_val_to_name[SYM_CLASSES]) | ||
| 453 | goto out; | ||
| 454 | |||
| 455 | rc = flex_array_prealloc(p->sym_val_to_name[SYM_CLASSES], | ||
| 456 | 0, p->p_classes.nprim - 1, | ||
| 457 | GFP_KERNEL | __GFP_ZERO); | ||
| 458 | if (rc) | ||
| 459 | goto out; | ||
| 460 | |||
| 461 | rc = hashtab_map(p->p_classes.table, class_index, p); | ||
| 462 | out: | ||
| 463 | return rc; | ||
| 464 | } | ||
| 465 | |||
| 466 | #ifdef DEBUG_HASHES | 414 | #ifdef DEBUG_HASHES |
| 467 | static void symtab_hash_eval(struct symtab *s) | 415 | static void symtab_hash_eval(struct symtab *s) |
| 468 | { | 416 | { |
| @@ -500,7 +448,7 @@ static inline void rangetr_hash_eval(struct hashtab *h) | |||
| 500 | * | 448 | * |
| 501 | * Caller must clean up on failure. | 449 | * Caller must clean up on failure. |
| 502 | */ | 450 | */ |
| 503 | static int policydb_index_others(struct policydb *p) | 451 | static int policydb_index(struct policydb *p) |
| 504 | { | 452 | { |
| 505 | int i, rc; | 453 | int i, rc; |
| 506 | 454 | ||
| @@ -520,6 +468,13 @@ static int policydb_index_others(struct policydb *p) | |||
| 520 | #endif | 468 | #endif |
| 521 | 469 | ||
| 522 | rc = -ENOMEM; | 470 | rc = -ENOMEM; |
| 471 | p->class_val_to_struct = | ||
| 472 | kmalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)), | ||
| 473 | GFP_KERNEL); | ||
| 474 | if (!p->class_val_to_struct) | ||
| 475 | goto out; | ||
| 476 | |||
| 477 | rc = -ENOMEM; | ||
| 523 | p->role_val_to_struct = | 478 | p->role_val_to_struct = |
| 524 | kmalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)), | 479 | kmalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)), |
| 525 | GFP_KERNEL); | 480 | GFP_KERNEL); |
| @@ -550,7 +505,7 @@ static int policydb_index_others(struct policydb *p) | |||
| 550 | if (cond_init_bool_indexes(p)) | 505 | if (cond_init_bool_indexes(p)) |
| 551 | goto out; | 506 | goto out; |
| 552 | 507 | ||
| 553 | for (i = SYM_ROLES; i < SYM_NUM; i++) { | 508 | for (i = 0; i < SYM_NUM; i++) { |
| 554 | rc = -ENOMEM; | 509 | rc = -ENOMEM; |
| 555 | p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), | 510 | p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), |
| 556 | p->symtab[i].nprim, | 511 | p->symtab[i].nprim, |
| @@ -2296,11 +2251,7 @@ int policydb_read(struct policydb *p, void *fp) | |||
| 2296 | lra = ra; | 2251 | lra = ra; |
| 2297 | } | 2252 | } |
| 2298 | 2253 | ||
| 2299 | rc = policydb_index_classes(p); | 2254 | rc = policydb_index(p); |
| 2300 | if (rc) | ||
| 2301 | goto bad; | ||
| 2302 | |||
| 2303 | rc = policydb_index_others(p); | ||
| 2304 | if (rc) | 2255 | if (rc) |
| 2305 | goto bad; | 2256 | goto bad; |
| 2306 | 2257 | ||
