diff options
Diffstat (limited to 'kernel/auditsc.c')
| -rw-r--r-- | kernel/auditsc.c | 269 |
1 files changed, 140 insertions, 129 deletions
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 7f160df21a23..1c03a4ed1b27 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
| @@ -58,6 +58,7 @@ | |||
| 58 | #include <linux/security.h> | 58 | #include <linux/security.h> |
| 59 | #include <linux/list.h> | 59 | #include <linux/list.h> |
| 60 | #include <linux/tty.h> | 60 | #include <linux/tty.h> |
| 61 | #include <linux/selinux.h> | ||
| 61 | 62 | ||
| 62 | #include "audit.h" | 63 | #include "audit.h" |
| 63 | 64 | ||
| @@ -89,7 +90,7 @@ struct audit_names { | |||
| 89 | uid_t uid; | 90 | uid_t uid; |
| 90 | gid_t gid; | 91 | gid_t gid; |
| 91 | dev_t rdev; | 92 | dev_t rdev; |
| 92 | char *ctx; | 93 | u32 osid; |
| 93 | }; | 94 | }; |
| 94 | 95 | ||
| 95 | struct audit_aux_data { | 96 | struct audit_aux_data { |
| @@ -106,7 +107,7 @@ struct audit_aux_data_ipcctl { | |||
| 106 | uid_t uid; | 107 | uid_t uid; |
| 107 | gid_t gid; | 108 | gid_t gid; |
| 108 | mode_t mode; | 109 | mode_t mode; |
| 109 | char *ctx; | 110 | u32 osid; |
| 110 | }; | 111 | }; |
| 111 | 112 | ||
| 112 | struct audit_aux_data_socketcall { | 113 | struct audit_aux_data_socketcall { |
| @@ -167,7 +168,8 @@ static int audit_filter_rules(struct task_struct *tsk, | |||
| 167 | struct audit_context *ctx, | 168 | struct audit_context *ctx, |
| 168 | enum audit_state *state) | 169 | enum audit_state *state) |
| 169 | { | 170 | { |
| 170 | int i, j; | 171 | int i, j, need_sid = 1; |
| 172 | u32 sid; | ||
| 171 | 173 | ||
| 172 | for (i = 0; i < rule->field_count; i++) { | 174 | for (i = 0; i < rule->field_count; i++) { |
| 173 | struct audit_field *f = &rule->fields[i]; | 175 | struct audit_field *f = &rule->fields[i]; |
| @@ -257,6 +259,27 @@ static int audit_filter_rules(struct task_struct *tsk, | |||
| 257 | if (ctx) | 259 | if (ctx) |
| 258 | result = audit_comparator(ctx->loginuid, f->op, f->val); | 260 | result = audit_comparator(ctx->loginuid, f->op, f->val); |
| 259 | break; | 261 | break; |
| 262 | case AUDIT_SE_USER: | ||
| 263 | case AUDIT_SE_ROLE: | ||
| 264 | case AUDIT_SE_TYPE: | ||
| 265 | case AUDIT_SE_SEN: | ||
| 266 | case AUDIT_SE_CLR: | ||
| 267 | /* NOTE: this may return negative values indicating | ||
| 268 | a temporary error. We simply treat this as a | ||
| 269 | match for now to avoid losing information that | ||
| 270 | may be wanted. An error message will also be | ||
| 271 | logged upon error */ | ||
| 272 | if (f->se_rule) { | ||
| 273 | if (need_sid) { | ||
| 274 | selinux_task_ctxid(tsk, &sid); | ||
| 275 | need_sid = 0; | ||
| 276 | } | ||
| 277 | result = selinux_audit_rule_match(sid, f->type, | ||
| 278 | f->op, | ||
| 279 | f->se_rule, | ||
| 280 | ctx); | ||
| 281 | } | ||
| 282 | break; | ||
| 260 | case AUDIT_ARG0: | 283 | case AUDIT_ARG0: |
| 261 | case AUDIT_ARG1: | 284 | case AUDIT_ARG1: |
| 262 | case AUDIT_ARG2: | 285 | case AUDIT_ARG2: |
| @@ -329,7 +352,6 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk, | |||
| 329 | return AUDIT_BUILD_CONTEXT; | 352 | return AUDIT_BUILD_CONTEXT; |
| 330 | } | 353 | } |
| 331 | 354 | ||
| 332 | /* This should be called with task_lock() held. */ | ||
| 333 | static inline struct audit_context *audit_get_context(struct task_struct *tsk, | 355 | static inline struct audit_context *audit_get_context(struct task_struct *tsk, |
| 334 | int return_valid, | 356 | int return_valid, |
| 335 | int return_code) | 357 | int return_code) |
| @@ -391,9 +413,6 @@ static inline void audit_free_names(struct audit_context *context) | |||
| 391 | #endif | 413 | #endif |
| 392 | 414 | ||
| 393 | for (i = 0; i < context->name_count; i++) { | 415 | for (i = 0; i < context->name_count; i++) { |
| 394 | char *p = context->names[i].ctx; | ||
| 395 | context->names[i].ctx = NULL; | ||
| 396 | kfree(p); | ||
| 397 | if (context->names[i].name) | 416 | if (context->names[i].name) |
| 398 | __putname(context->names[i].name); | 417 | __putname(context->names[i].name); |
| 399 | } | 418 | } |
| @@ -416,11 +435,6 @@ static inline void audit_free_aux(struct audit_context *context) | |||
| 416 | dput(axi->dentry); | 435 | dput(axi->dentry); |
| 417 | mntput(axi->mnt); | 436 | mntput(axi->mnt); |
| 418 | } | 437 | } |
| 419 | if ( aux->type == AUDIT_IPC ) { | ||
| 420 | struct audit_aux_data_ipcctl *axi = (void *)aux; | ||
| 421 | if (axi->ctx) | ||
| 422 | kfree(axi->ctx); | ||
| 423 | } | ||
| 424 | 438 | ||
| 425 | context->aux = aux->next; | 439 | context->aux = aux->next; |
| 426 | kfree(aux); | 440 | kfree(aux); |
| @@ -506,7 +520,7 @@ static inline void audit_free_context(struct audit_context *context) | |||
| 506 | printk(KERN_ERR "audit: freed %d contexts\n", count); | 520 | printk(KERN_ERR "audit: freed %d contexts\n", count); |
| 507 | } | 521 | } |
| 508 | 522 | ||
| 509 | static void audit_log_task_context(struct audit_buffer *ab, gfp_t gfp_mask) | 523 | static void audit_log_task_context(struct audit_buffer *ab) |
| 510 | { | 524 | { |
| 511 | char *ctx = NULL; | 525 | char *ctx = NULL; |
| 512 | ssize_t len = 0; | 526 | ssize_t len = 0; |
| @@ -518,7 +532,7 @@ static void audit_log_task_context(struct audit_buffer *ab, gfp_t gfp_mask) | |||
| 518 | return; | 532 | return; |
| 519 | } | 533 | } |
| 520 | 534 | ||
| 521 | ctx = kmalloc(len, gfp_mask); | 535 | ctx = kmalloc(len, GFP_KERNEL); |
| 522 | if (!ctx) | 536 | if (!ctx) |
| 523 | goto error_path; | 537 | goto error_path; |
| 524 | 538 | ||
| @@ -536,47 +550,46 @@ error_path: | |||
| 536 | return; | 550 | return; |
| 537 | } | 551 | } |
| 538 | 552 | ||
| 539 | static void audit_log_task_info(struct audit_buffer *ab, gfp_t gfp_mask) | 553 | static void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk) |
| 540 | { | 554 | { |
| 541 | char name[sizeof(current->comm)]; | 555 | char name[sizeof(tsk->comm)]; |
| 542 | struct mm_struct *mm = current->mm; | 556 | struct mm_struct *mm = tsk->mm; |
| 543 | struct vm_area_struct *vma; | 557 | struct vm_area_struct *vma; |
| 544 | 558 | ||
| 545 | get_task_comm(name, current); | 559 | /* tsk == current */ |
| 560 | |||
| 561 | get_task_comm(name, tsk); | ||
| 546 | audit_log_format(ab, " comm="); | 562 | audit_log_format(ab, " comm="); |
| 547 | audit_log_untrustedstring(ab, name); | 563 | audit_log_untrustedstring(ab, name); |
| 548 | 564 | ||
| 549 | if (!mm) | 565 | if (mm) { |
| 550 | return; | 566 | down_read(&mm->mmap_sem); |
| 551 | 567 | vma = mm->mmap; | |
| 552 | /* | 568 | while (vma) { |
| 553 | * this is brittle; all callers that pass GFP_ATOMIC will have | 569 | if ((vma->vm_flags & VM_EXECUTABLE) && |
| 554 | * NULL current->mm and we won't get here. | 570 | vma->vm_file) { |
| 555 | */ | 571 | audit_log_d_path(ab, "exe=", |
| 556 | down_read(&mm->mmap_sem); | 572 | vma->vm_file->f_dentry, |
| 557 | vma = mm->mmap; | 573 | vma->vm_file->f_vfsmnt); |
| 558 | while (vma) { | 574 | break; |
| 559 | if ((vma->vm_flags & VM_EXECUTABLE) && | 575 | } |
| 560 | vma->vm_file) { | 576 | vma = vma->vm_next; |
| 561 | audit_log_d_path(ab, "exe=", | ||
| 562 | vma->vm_file->f_dentry, | ||
| 563 | vma->vm_file->f_vfsmnt); | ||
| 564 | break; | ||
| 565 | } | 577 | } |
| 566 | vma = vma->vm_next; | 578 | up_read(&mm->mmap_sem); |
| 567 | } | 579 | } |
| 568 | up_read(&mm->mmap_sem); | 580 | audit_log_task_context(ab); |
| 569 | audit_log_task_context(ab, gfp_mask); | ||
| 570 | } | 581 | } |
| 571 | 582 | ||
| 572 | static void audit_log_exit(struct audit_context *context, gfp_t gfp_mask) | 583 | static void audit_log_exit(struct audit_context *context, struct task_struct *tsk) |
| 573 | { | 584 | { |
| 574 | int i; | 585 | int i, call_panic = 0; |
| 575 | struct audit_buffer *ab; | 586 | struct audit_buffer *ab; |
| 576 | struct audit_aux_data *aux; | 587 | struct audit_aux_data *aux; |
| 577 | const char *tty; | 588 | const char *tty; |
| 578 | 589 | ||
| 579 | ab = audit_log_start(context, gfp_mask, AUDIT_SYSCALL); | 590 | /* tsk == current */ |
| 591 | |||
| 592 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_SYSCALL); | ||
| 580 | if (!ab) | 593 | if (!ab) |
| 581 | return; /* audit_panic has been called */ | 594 | return; /* audit_panic has been called */ |
| 582 | audit_log_format(ab, "arch=%x syscall=%d", | 595 | audit_log_format(ab, "arch=%x syscall=%d", |
| @@ -587,8 +600,8 @@ static void audit_log_exit(struct audit_context *context, gfp_t gfp_mask) | |||
| 587 | audit_log_format(ab, " success=%s exit=%ld", | 600 | audit_log_format(ab, " success=%s exit=%ld", |
| 588 | (context->return_valid==AUDITSC_SUCCESS)?"yes":"no", | 601 | (context->return_valid==AUDITSC_SUCCESS)?"yes":"no", |
| 589 | context->return_code); | 602 | context->return_code); |
| 590 | if (current->signal->tty && current->signal->tty->name) | 603 | if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name) |
| 591 | tty = current->signal->tty->name; | 604 | tty = tsk->signal->tty->name; |
| 592 | else | 605 | else |
| 593 | tty = "(none)"; | 606 | tty = "(none)"; |
| 594 | audit_log_format(ab, | 607 | audit_log_format(ab, |
| @@ -607,12 +620,12 @@ static void audit_log_exit(struct audit_context *context, gfp_t gfp_mask) | |||
| 607 | context->gid, | 620 | context->gid, |
| 608 | context->euid, context->suid, context->fsuid, | 621 | context->euid, context->suid, context->fsuid, |
| 609 | context->egid, context->sgid, context->fsgid, tty); | 622 | context->egid, context->sgid, context->fsgid, tty); |
| 610 | audit_log_task_info(ab, gfp_mask); | 623 | audit_log_task_info(ab, tsk); |
| 611 | audit_log_end(ab); | 624 | audit_log_end(ab); |
| 612 | 625 | ||
| 613 | for (aux = context->aux; aux; aux = aux->next) { | 626 | for (aux = context->aux; aux; aux = aux->next) { |
| 614 | 627 | ||
| 615 | ab = audit_log_start(context, gfp_mask, aux->type); | 628 | ab = audit_log_start(context, GFP_KERNEL, aux->type); |
| 616 | if (!ab) | 629 | if (!ab) |
| 617 | continue; /* audit_panic has been called */ | 630 | continue; /* audit_panic has been called */ |
| 618 | 631 | ||
| @@ -620,8 +633,39 @@ static void audit_log_exit(struct audit_context *context, gfp_t gfp_mask) | |||
| 620 | case AUDIT_IPC: { | 633 | case AUDIT_IPC: { |
| 621 | struct audit_aux_data_ipcctl *axi = (void *)aux; | 634 | struct audit_aux_data_ipcctl *axi = (void *)aux; |
| 622 | audit_log_format(ab, | 635 | audit_log_format(ab, |
| 623 | " qbytes=%lx iuid=%u igid=%u mode=%x obj=%s", | 636 | " qbytes=%lx iuid=%u igid=%u mode=%x", |
| 624 | axi->qbytes, axi->uid, axi->gid, axi->mode, axi->ctx); | 637 | axi->qbytes, axi->uid, axi->gid, axi->mode); |
| 638 | if (axi->osid != 0) { | ||
| 639 | char *ctx = NULL; | ||
| 640 | u32 len; | ||
| 641 | if (selinux_ctxid_to_string( | ||
| 642 | axi->osid, &ctx, &len)) { | ||
| 643 | audit_log_format(ab, " osid=%u", | ||
| 644 | axi->osid); | ||
| 645 | call_panic = 1; | ||
| 646 | } else | ||
| 647 | audit_log_format(ab, " obj=%s", ctx); | ||
| 648 | kfree(ctx); | ||
| 649 | } | ||
| 650 | break; } | ||
| 651 | |||
| 652 | case AUDIT_IPC_SET_PERM: { | ||
| 653 | struct audit_aux_data_ipcctl *axi = (void *)aux; | ||
| 654 | audit_log_format(ab, | ||
| 655 | " new qbytes=%lx new iuid=%u new igid=%u new mode=%x", | ||
| 656 | axi->qbytes, axi->uid, axi->gid, axi->mode); | ||
| 657 | if (axi->osid != 0) { | ||
| 658 | char *ctx = NULL; | ||
| 659 | u32 len; | ||
| 660 | if (selinux_ctxid_to_string( | ||
| 661 | axi->osid, &ctx, &len)) { | ||
| 662 | audit_log_format(ab, " osid=%u", | ||
| 663 | axi->osid); | ||
| 664 | call_panic = 1; | ||
| 665 | } else | ||
| 666 | audit_log_format(ab, " obj=%s", ctx); | ||
| 667 | kfree(ctx); | ||
| 668 | } | ||
| 625 | break; } | 669 | break; } |
| 626 | 670 | ||
| 627 | case AUDIT_SOCKETCALL: { | 671 | case AUDIT_SOCKETCALL: { |
| @@ -649,7 +693,7 @@ static void audit_log_exit(struct audit_context *context, gfp_t gfp_mask) | |||
| 649 | } | 693 | } |
| 650 | 694 | ||
| 651 | if (context->pwd && context->pwdmnt) { | 695 | if (context->pwd && context->pwdmnt) { |
| 652 | ab = audit_log_start(context, gfp_mask, AUDIT_CWD); | 696 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_CWD); |
| 653 | if (ab) { | 697 | if (ab) { |
| 654 | audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt); | 698 | audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt); |
| 655 | audit_log_end(ab); | 699 | audit_log_end(ab); |
| @@ -659,7 +703,7 @@ static void audit_log_exit(struct audit_context *context, gfp_t gfp_mask) | |||
| 659 | unsigned long ino = context->names[i].ino; | 703 | unsigned long ino = context->names[i].ino; |
| 660 | unsigned long pino = context->names[i].pino; | 704 | unsigned long pino = context->names[i].pino; |
| 661 | 705 | ||
| 662 | ab = audit_log_start(context, gfp_mask, AUDIT_PATH); | 706 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH); |
| 663 | if (!ab) | 707 | if (!ab) |
| 664 | continue; /* audit_panic has been called */ | 708 | continue; /* audit_panic has been called */ |
| 665 | 709 | ||
| @@ -685,32 +729,35 @@ static void audit_log_exit(struct audit_context *context, gfp_t gfp_mask) | |||
| 685 | context->names[i].gid, | 729 | context->names[i].gid, |
| 686 | MAJOR(context->names[i].rdev), | 730 | MAJOR(context->names[i].rdev), |
| 687 | MINOR(context->names[i].rdev)); | 731 | MINOR(context->names[i].rdev)); |
| 688 | if (context->names[i].ctx) { | 732 | if (context->names[i].osid != 0) { |
| 689 | audit_log_format(ab, " obj=%s", | 733 | char *ctx = NULL; |
| 690 | context->names[i].ctx); | 734 | u32 len; |
| 735 | if (selinux_ctxid_to_string( | ||
| 736 | context->names[i].osid, &ctx, &len)) { | ||
| 737 | audit_log_format(ab, " osid=%u", | ||
| 738 | context->names[i].osid); | ||
| 739 | call_panic = 2; | ||
| 740 | } else | ||
| 741 | audit_log_format(ab, " obj=%s", ctx); | ||
| 742 | kfree(ctx); | ||
| 691 | } | 743 | } |
| 692 | 744 | ||
| 693 | audit_log_end(ab); | 745 | audit_log_end(ab); |
| 694 | } | 746 | } |
| 747 | if (call_panic) | ||
| 748 | audit_panic("error converting sid to string"); | ||
| 695 | } | 749 | } |
| 696 | 750 | ||
| 697 | /** | 751 | /** |
| 698 | * audit_free - free a per-task audit context | 752 | * audit_free - free a per-task audit context |
| 699 | * @tsk: task whose audit context block to free | 753 | * @tsk: task whose audit context block to free |
| 700 | * | 754 | * |
| 701 | * Called from copy_process and __put_task_struct. | 755 | * Called from copy_process and do_exit |
| 702 | */ | 756 | */ |
| 703 | void audit_free(struct task_struct *tsk) | 757 | void audit_free(struct task_struct *tsk) |
| 704 | { | 758 | { |
| 705 | struct audit_context *context; | 759 | struct audit_context *context; |
| 706 | 760 | ||
| 707 | /* | ||
| 708 | * No need to lock the task - when we execute audit_free() | ||
| 709 | * then the task has no external references anymore, and | ||
| 710 | * we are tearing it down. (The locking also confuses | ||
| 711 | * DEBUG_LOCKDEP - this freeing may occur in softirq | ||
| 712 | * contexts as well, via RCU.) | ||
| 713 | */ | ||
| 714 | context = audit_get_context(tsk, 0, 0); | 761 | context = audit_get_context(tsk, 0, 0); |
| 715 | if (likely(!context)) | 762 | if (likely(!context)) |
| 716 | return; | 763 | return; |
| @@ -719,8 +766,9 @@ void audit_free(struct task_struct *tsk) | |||
| 719 | * function (e.g., exit_group), then free context block. | 766 | * function (e.g., exit_group), then free context block. |
| 720 | * We use GFP_ATOMIC here because we might be doing this | 767 | * We use GFP_ATOMIC here because we might be doing this |
| 721 | * in the context of the idle thread */ | 768 | * in the context of the idle thread */ |
| 769 | /* that can happen only if we are called from do_exit() */ | ||
| 722 | if (context->in_syscall && context->auditable) | 770 | if (context->in_syscall && context->auditable) |
| 723 | audit_log_exit(context, GFP_ATOMIC); | 771 | audit_log_exit(context, tsk); |
| 724 | 772 | ||
| 725 | audit_free_context(context); | 773 | audit_free_context(context); |
| 726 | } | 774 | } |
| @@ -743,10 +791,11 @@ void audit_free(struct task_struct *tsk) | |||
| 743 | * will only be written if another part of the kernel requests that it | 791 | * will only be written if another part of the kernel requests that it |
| 744 | * be written). | 792 | * be written). |
| 745 | */ | 793 | */ |
| 746 | void audit_syscall_entry(struct task_struct *tsk, int arch, int major, | 794 | void audit_syscall_entry(int arch, int major, |
| 747 | unsigned long a1, unsigned long a2, | 795 | unsigned long a1, unsigned long a2, |
| 748 | unsigned long a3, unsigned long a4) | 796 | unsigned long a3, unsigned long a4) |
| 749 | { | 797 | { |
| 798 | struct task_struct *tsk = current; | ||
| 750 | struct audit_context *context = tsk->audit_context; | 799 | struct audit_context *context = tsk->audit_context; |
| 751 | enum audit_state state; | 800 | enum audit_state state; |
| 752 | 801 | ||
| @@ -824,22 +873,18 @@ void audit_syscall_entry(struct task_struct *tsk, int arch, int major, | |||
| 824 | * message), then write out the syscall information. In call cases, | 873 | * message), then write out the syscall information. In call cases, |
| 825 | * free the names stored from getname(). | 874 | * free the names stored from getname(). |
| 826 | */ | 875 | */ |
| 827 | void audit_syscall_exit(struct task_struct *tsk, int valid, long return_code) | 876 | void audit_syscall_exit(int valid, long return_code) |
| 828 | { | 877 | { |
| 878 | struct task_struct *tsk = current; | ||
| 829 | struct audit_context *context; | 879 | struct audit_context *context; |
| 830 | 880 | ||
| 831 | get_task_struct(tsk); | ||
| 832 | task_lock(tsk); | ||
| 833 | context = audit_get_context(tsk, valid, return_code); | 881 | context = audit_get_context(tsk, valid, return_code); |
| 834 | task_unlock(tsk); | ||
| 835 | 882 | ||
| 836 | /* Not having a context here is ok, since the parent may have | ||
| 837 | * called __put_task_struct. */ | ||
| 838 | if (likely(!context)) | 883 | if (likely(!context)) |
| 839 | goto out; | 884 | return; |
| 840 | 885 | ||
| 841 | if (context->in_syscall && context->auditable) | 886 | if (context->in_syscall && context->auditable) |
| 842 | audit_log_exit(context, GFP_KERNEL); | 887 | audit_log_exit(context, tsk); |
| 843 | 888 | ||
| 844 | context->in_syscall = 0; | 889 | context->in_syscall = 0; |
| 845 | context->auditable = 0; | 890 | context->auditable = 0; |
| @@ -854,8 +899,6 @@ void audit_syscall_exit(struct task_struct *tsk, int valid, long return_code) | |||
| 854 | audit_free_aux(context); | 899 | audit_free_aux(context); |
| 855 | tsk->audit_context = context; | 900 | tsk->audit_context = context; |
| 856 | } | 901 | } |
| 857 | out: | ||
| 858 | put_task_struct(tsk); | ||
| 859 | } | 902 | } |
| 860 | 903 | ||
| 861 | /** | 904 | /** |
| @@ -936,40 +979,11 @@ void audit_putname(const char *name) | |||
| 936 | #endif | 979 | #endif |
| 937 | } | 980 | } |
| 938 | 981 | ||
| 939 | void audit_inode_context(int idx, const struct inode *inode) | 982 | static void audit_inode_context(int idx, const struct inode *inode) |
| 940 | { | 983 | { |
| 941 | struct audit_context *context = current->audit_context; | 984 | struct audit_context *context = current->audit_context; |
| 942 | const char *suffix = security_inode_xattr_getsuffix(); | ||
| 943 | char *ctx = NULL; | ||
| 944 | int len = 0; | ||
| 945 | |||
| 946 | if (!suffix) | ||
| 947 | goto ret; | ||
| 948 | |||
| 949 | len = security_inode_getsecurity(inode, suffix, NULL, 0, 0); | ||
| 950 | if (len == -EOPNOTSUPP) | ||
| 951 | goto ret; | ||
| 952 | if (len < 0) | ||
| 953 | goto error_path; | ||
| 954 | |||
| 955 | ctx = kmalloc(len, GFP_KERNEL); | ||
| 956 | if (!ctx) | ||
| 957 | goto error_path; | ||
| 958 | 985 | ||
| 959 | len = security_inode_getsecurity(inode, suffix, ctx, len, 0); | 986 | selinux_get_inode_sid(inode, &context->names[idx].osid); |
| 960 | if (len < 0) | ||
| 961 | goto error_path; | ||
| 962 | |||
| 963 | kfree(context->names[idx].ctx); | ||
| 964 | context->names[idx].ctx = ctx; | ||
| 965 | goto ret; | ||
| 966 | |||
| 967 | error_path: | ||
| 968 | if (ctx) | ||
| 969 | kfree(ctx); | ||
| 970 | audit_panic("error in audit_inode_context"); | ||
| 971 | ret: | ||
| 972 | return; | ||
| 973 | } | 987 | } |
| 974 | 988 | ||
| 975 | 989 | ||
| @@ -1155,40 +1169,37 @@ uid_t audit_get_loginuid(struct audit_context *ctx) | |||
| 1155 | return ctx ? ctx->loginuid : -1; | 1169 | return ctx ? ctx->loginuid : -1; |
| 1156 | } | 1170 | } |
| 1157 | 1171 | ||
| 1158 | static char *audit_ipc_context(struct kern_ipc_perm *ipcp) | 1172 | /** |
| 1173 | * audit_ipc_obj - record audit data for ipc object | ||
| 1174 | * @ipcp: ipc permissions | ||
| 1175 | * | ||
| 1176 | * Returns 0 for success or NULL context or < 0 on error. | ||
| 1177 | */ | ||
| 1178 | int audit_ipc_obj(struct kern_ipc_perm *ipcp) | ||
| 1159 | { | 1179 | { |
| 1180 | struct audit_aux_data_ipcctl *ax; | ||
| 1160 | struct audit_context *context = current->audit_context; | 1181 | struct audit_context *context = current->audit_context; |
| 1161 | char *ctx = NULL; | ||
| 1162 | int len = 0; | ||
| 1163 | 1182 | ||
| 1164 | if (likely(!context)) | 1183 | if (likely(!context)) |
| 1165 | return NULL; | 1184 | return 0; |
| 1166 | |||
| 1167 | len = security_ipc_getsecurity(ipcp, NULL, 0); | ||
| 1168 | if (len == -EOPNOTSUPP) | ||
| 1169 | goto ret; | ||
| 1170 | if (len < 0) | ||
| 1171 | goto error_path; | ||
| 1172 | |||
| 1173 | ctx = kmalloc(len, GFP_ATOMIC); | ||
| 1174 | if (!ctx) | ||
| 1175 | goto error_path; | ||
| 1176 | 1185 | ||
| 1177 | len = security_ipc_getsecurity(ipcp, ctx, len); | 1186 | ax = kmalloc(sizeof(*ax), GFP_ATOMIC); |
| 1178 | if (len < 0) | 1187 | if (!ax) |
| 1179 | goto error_path; | 1188 | return -ENOMEM; |
| 1180 | 1189 | ||
| 1181 | return ctx; | 1190 | ax->uid = ipcp->uid; |
| 1191 | ax->gid = ipcp->gid; | ||
| 1192 | ax->mode = ipcp->mode; | ||
| 1193 | selinux_get_ipc_sid(ipcp, &ax->osid); | ||
| 1182 | 1194 | ||
| 1183 | error_path: | 1195 | ax->d.type = AUDIT_IPC; |
| 1184 | kfree(ctx); | 1196 | ax->d.next = context->aux; |
| 1185 | audit_panic("error in audit_ipc_context"); | 1197 | context->aux = (void *)ax; |
| 1186 | ret: | 1198 | return 0; |
| 1187 | return NULL; | ||
| 1188 | } | 1199 | } |
| 1189 | 1200 | ||
| 1190 | /** | 1201 | /** |
| 1191 | * audit_ipc_perms - record audit data for ipc | 1202 | * audit_ipc_set_perm - record audit data for new ipc permissions |
| 1192 | * @qbytes: msgq bytes | 1203 | * @qbytes: msgq bytes |
| 1193 | * @uid: msgq user id | 1204 | * @uid: msgq user id |
| 1194 | * @gid: msgq group id | 1205 | * @gid: msgq group id |
| @@ -1196,7 +1207,7 @@ ret: | |||
| 1196 | * | 1207 | * |
| 1197 | * Returns 0 for success or NULL context or < 0 on error. | 1208 | * Returns 0 for success or NULL context or < 0 on error. |
| 1198 | */ | 1209 | */ |
| 1199 | int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode, struct kern_ipc_perm *ipcp) | 1210 | int audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode, struct kern_ipc_perm *ipcp) |
| 1200 | { | 1211 | { |
| 1201 | struct audit_aux_data_ipcctl *ax; | 1212 | struct audit_aux_data_ipcctl *ax; |
| 1202 | struct audit_context *context = current->audit_context; | 1213 | struct audit_context *context = current->audit_context; |
| @@ -1212,9 +1223,9 @@ int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode, str | |||
| 1212 | ax->uid = uid; | 1223 | ax->uid = uid; |
| 1213 | ax->gid = gid; | 1224 | ax->gid = gid; |
| 1214 | ax->mode = mode; | 1225 | ax->mode = mode; |
| 1215 | ax->ctx = audit_ipc_context(ipcp); | 1226 | selinux_get_ipc_sid(ipcp, &ax->osid); |
| 1216 | 1227 | ||
| 1217 | ax->d.type = AUDIT_IPC; | 1228 | ax->d.type = AUDIT_IPC_SET_PERM; |
| 1218 | ax->d.next = context->aux; | 1229 | ax->d.next = context->aux; |
| 1219 | context->aux = (void *)ax; | 1230 | context->aux = (void *)ax; |
| 1220 | return 0; | 1231 | return 0; |
