diff options
Diffstat (limited to 'kernel/audit.c')
| -rw-r--r-- | kernel/audit.c | 68 |
1 files changed, 42 insertions, 26 deletions
diff --git a/kernel/audit.c b/kernel/audit.c index 34c5a2310fbf..7c2893602d06 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
| @@ -182,7 +182,7 @@ struct audit_buffer { | |||
| 182 | 182 | ||
| 183 | struct audit_reply { | 183 | struct audit_reply { |
| 184 | __u32 portid; | 184 | __u32 portid; |
| 185 | pid_t pid; | 185 | struct net *net; |
| 186 | struct sk_buff *skb; | 186 | struct sk_buff *skb; |
| 187 | }; | 187 | }; |
| 188 | 188 | ||
| @@ -396,7 +396,7 @@ static void audit_printk_skb(struct sk_buff *skb) | |||
| 396 | if (printk_ratelimit()) | 396 | if (printk_ratelimit()) |
| 397 | pr_notice("type=%d %s\n", nlh->nlmsg_type, data); | 397 | pr_notice("type=%d %s\n", nlh->nlmsg_type, data); |
| 398 | else | 398 | else |
| 399 | audit_log_lost("printk limit exceeded\n"); | 399 | audit_log_lost("printk limit exceeded"); |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | audit_hold_skb(skb); | 402 | audit_hold_skb(skb); |
| @@ -412,7 +412,7 @@ static void kauditd_send_skb(struct sk_buff *skb) | |||
| 412 | BUG_ON(err != -ECONNREFUSED); /* Shouldn't happen */ | 412 | BUG_ON(err != -ECONNREFUSED); /* Shouldn't happen */ |
| 413 | if (audit_pid) { | 413 | if (audit_pid) { |
| 414 | pr_err("*NO* daemon at audit_pid=%d\n", audit_pid); | 414 | pr_err("*NO* daemon at audit_pid=%d\n", audit_pid); |
| 415 | audit_log_lost("auditd disappeared\n"); | 415 | audit_log_lost("auditd disappeared"); |
| 416 | audit_pid = 0; | 416 | audit_pid = 0; |
| 417 | audit_sock = NULL; | 417 | audit_sock = NULL; |
| 418 | } | 418 | } |
| @@ -500,7 +500,7 @@ int audit_send_list(void *_dest) | |||
| 500 | { | 500 | { |
| 501 | struct audit_netlink_list *dest = _dest; | 501 | struct audit_netlink_list *dest = _dest; |
| 502 | struct sk_buff *skb; | 502 | struct sk_buff *skb; |
| 503 | struct net *net = get_net_ns_by_pid(dest->pid); | 503 | struct net *net = dest->net; |
| 504 | struct audit_net *aunet = net_generic(net, audit_net_id); | 504 | struct audit_net *aunet = net_generic(net, audit_net_id); |
| 505 | 505 | ||
| 506 | /* wait for parent to finish and send an ACK */ | 506 | /* wait for parent to finish and send an ACK */ |
| @@ -510,6 +510,7 @@ int audit_send_list(void *_dest) | |||
| 510 | while ((skb = __skb_dequeue(&dest->q)) != NULL) | 510 | while ((skb = __skb_dequeue(&dest->q)) != NULL) |
| 511 | netlink_unicast(aunet->nlsk, skb, dest->portid, 0); | 511 | netlink_unicast(aunet->nlsk, skb, dest->portid, 0); |
| 512 | 512 | ||
| 513 | put_net(net); | ||
| 513 | kfree(dest); | 514 | kfree(dest); |
| 514 | 515 | ||
| 515 | return 0; | 516 | return 0; |
| @@ -543,7 +544,7 @@ out_kfree_skb: | |||
| 543 | static int audit_send_reply_thread(void *arg) | 544 | static int audit_send_reply_thread(void *arg) |
| 544 | { | 545 | { |
| 545 | struct audit_reply *reply = (struct audit_reply *)arg; | 546 | struct audit_reply *reply = (struct audit_reply *)arg; |
| 546 | struct net *net = get_net_ns_by_pid(reply->pid); | 547 | struct net *net = reply->net; |
| 547 | struct audit_net *aunet = net_generic(net, audit_net_id); | 548 | struct audit_net *aunet = net_generic(net, audit_net_id); |
| 548 | 549 | ||
| 549 | mutex_lock(&audit_cmd_mutex); | 550 | mutex_lock(&audit_cmd_mutex); |
| @@ -552,12 +553,13 @@ static int audit_send_reply_thread(void *arg) | |||
| 552 | /* Ignore failure. It'll only happen if the sender goes away, | 553 | /* Ignore failure. It'll only happen if the sender goes away, |
| 553 | because our timeout is set to infinite. */ | 554 | because our timeout is set to infinite. */ |
| 554 | netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0); | 555 | netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0); |
| 556 | put_net(net); | ||
| 555 | kfree(reply); | 557 | kfree(reply); |
| 556 | return 0; | 558 | return 0; |
| 557 | } | 559 | } |
| 558 | /** | 560 | /** |
| 559 | * audit_send_reply - send an audit reply message via netlink | 561 | * audit_send_reply - send an audit reply message via netlink |
| 560 | * @portid: netlink port to which to send reply | 562 | * @request_skb: skb of request we are replying to (used to target the reply) |
| 561 | * @seq: sequence number | 563 | * @seq: sequence number |
| 562 | * @type: audit message type | 564 | * @type: audit message type |
| 563 | * @done: done (last) flag | 565 | * @done: done (last) flag |
| @@ -568,9 +570,11 @@ static int audit_send_reply_thread(void *arg) | |||
| 568 | * Allocates an skb, builds the netlink message, and sends it to the port id. | 570 | * Allocates an skb, builds the netlink message, and sends it to the port id. |
| 569 | * No failure notifications. | 571 | * No failure notifications. |
| 570 | */ | 572 | */ |
| 571 | static void audit_send_reply(__u32 portid, int seq, int type, int done, | 573 | static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int done, |
| 572 | int multi, const void *payload, int size) | 574 | int multi, const void *payload, int size) |
| 573 | { | 575 | { |
| 576 | u32 portid = NETLINK_CB(request_skb).portid; | ||
| 577 | struct net *net = sock_net(NETLINK_CB(request_skb).sk); | ||
| 574 | struct sk_buff *skb; | 578 | struct sk_buff *skb; |
| 575 | struct task_struct *tsk; | 579 | struct task_struct *tsk; |
| 576 | struct audit_reply *reply = kmalloc(sizeof(struct audit_reply), | 580 | struct audit_reply *reply = kmalloc(sizeof(struct audit_reply), |
| @@ -583,8 +587,8 @@ static void audit_send_reply(__u32 portid, int seq, int type, int done, | |||
| 583 | if (!skb) | 587 | if (!skb) |
| 584 | goto out; | 588 | goto out; |
| 585 | 589 | ||
| 590 | reply->net = get_net(net); | ||
| 586 | reply->portid = portid; | 591 | reply->portid = portid; |
| 587 | reply->pid = task_pid_vnr(current); | ||
| 588 | reply->skb = skb; | 592 | reply->skb = skb; |
| 589 | 593 | ||
| 590 | tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); | 594 | tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); |
| @@ -603,10 +607,19 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type) | |||
| 603 | { | 607 | { |
| 604 | int err = 0; | 608 | int err = 0; |
| 605 | 609 | ||
| 606 | /* Only support the initial namespaces for now. */ | 610 | /* Only support initial user namespace for now. */ |
| 607 | if ((current_user_ns() != &init_user_ns) || | 611 | /* |
| 608 | (task_active_pid_ns(current) != &init_pid_ns)) | 612 | * We return ECONNREFUSED because it tricks userspace into thinking |
| 609 | return -EPERM; | 613 | * that audit was not configured into the kernel. Lots of users |
| 614 | * configure their PAM stack (because that's what the distro does) | ||
| 615 | * to reject login if unable to send messages to audit. If we return | ||
| 616 | * ECONNREFUSED the PAM stack thinks the kernel does not have audit | ||
| 617 | * configured in and will let login proceed. If we return EPERM | ||
| 618 | * userspace will reject all logins. This should be removed when we | ||
| 619 | * support non init namespaces!! | ||
| 620 | */ | ||
| 621 | if (current_user_ns() != &init_user_ns) | ||
| 622 | return -ECONNREFUSED; | ||
| 610 | 623 | ||
| 611 | switch (msg_type) { | 624 | switch (msg_type) { |
| 612 | case AUDIT_LIST: | 625 | case AUDIT_LIST: |
| @@ -625,6 +638,11 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type) | |||
| 625 | case AUDIT_TTY_SET: | 638 | case AUDIT_TTY_SET: |
| 626 | case AUDIT_TRIM: | 639 | case AUDIT_TRIM: |
| 627 | case AUDIT_MAKE_EQUIV: | 640 | case AUDIT_MAKE_EQUIV: |
| 641 | /* Only support auditd and auditctl in initial pid namespace | ||
| 642 | * for now. */ | ||
| 643 | if ((task_active_pid_ns(current) != &init_pid_ns)) | ||
| 644 | return -EPERM; | ||
| 645 | |||
| 628 | if (!capable(CAP_AUDIT_CONTROL)) | 646 | if (!capable(CAP_AUDIT_CONTROL)) |
| 629 | err = -EPERM; | 647 | err = -EPERM; |
| 630 | break; | 648 | break; |
| @@ -645,6 +663,7 @@ static int audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type) | |||
| 645 | { | 663 | { |
| 646 | int rc = 0; | 664 | int rc = 0; |
| 647 | uid_t uid = from_kuid(&init_user_ns, current_uid()); | 665 | uid_t uid = from_kuid(&init_user_ns, current_uid()); |
| 666 | pid_t pid = task_tgid_nr(current); | ||
| 648 | 667 | ||
| 649 | if (!audit_enabled && msg_type != AUDIT_USER_AVC) { | 668 | if (!audit_enabled && msg_type != AUDIT_USER_AVC) { |
| 650 | *ab = NULL; | 669 | *ab = NULL; |
| @@ -654,7 +673,7 @@ static int audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type) | |||
| 654 | *ab = audit_log_start(NULL, GFP_KERNEL, msg_type); | 673 | *ab = audit_log_start(NULL, GFP_KERNEL, msg_type); |
| 655 | if (unlikely(!*ab)) | 674 | if (unlikely(!*ab)) |
| 656 | return rc; | 675 | return rc; |
| 657 | audit_log_format(*ab, "pid=%d uid=%u", task_tgid_vnr(current), uid); | 676 | audit_log_format(*ab, "pid=%d uid=%u", pid, uid); |
| 658 | audit_log_session_info(*ab); | 677 | audit_log_session_info(*ab); |
| 659 | audit_log_task_context(*ab); | 678 | audit_log_task_context(*ab); |
| 660 | 679 | ||
| @@ -673,8 +692,7 @@ static int audit_get_feature(struct sk_buff *skb) | |||
| 673 | 692 | ||
| 674 | seq = nlmsg_hdr(skb)->nlmsg_seq; | 693 | seq = nlmsg_hdr(skb)->nlmsg_seq; |
| 675 | 694 | ||
| 676 | audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, | 695 | audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &af, sizeof(af)); |
| 677 | &af, sizeof(af)); | ||
| 678 | 696 | ||
| 679 | return 0; | 697 | return 0; |
| 680 | } | 698 | } |
| @@ -794,8 +812,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
| 794 | s.backlog = skb_queue_len(&audit_skb_queue); | 812 | s.backlog = skb_queue_len(&audit_skb_queue); |
| 795 | s.version = AUDIT_VERSION_LATEST; | 813 | s.version = AUDIT_VERSION_LATEST; |
| 796 | s.backlog_wait_time = audit_backlog_wait_time; | 814 | s.backlog_wait_time = audit_backlog_wait_time; |
| 797 | audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, | 815 | audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &s, sizeof(s)); |
| 798 | &s, sizeof(s)); | ||
| 799 | break; | 816 | break; |
| 800 | } | 817 | } |
| 801 | case AUDIT_SET: { | 818 | case AUDIT_SET: { |
| @@ -905,7 +922,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
| 905 | seq, data, nlmsg_len(nlh)); | 922 | seq, data, nlmsg_len(nlh)); |
| 906 | break; | 923 | break; |
| 907 | case AUDIT_LIST_RULES: | 924 | case AUDIT_LIST_RULES: |
| 908 | err = audit_list_rules_send(NETLINK_CB(skb).portid, seq); | 925 | err = audit_list_rules_send(skb, seq); |
| 909 | break; | 926 | break; |
| 910 | case AUDIT_TRIM: | 927 | case AUDIT_TRIM: |
| 911 | audit_trim_trees(); | 928 | audit_trim_trees(); |
| @@ -970,8 +987,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
| 970 | memcpy(sig_data->ctx, ctx, len); | 987 | memcpy(sig_data->ctx, ctx, len); |
| 971 | security_release_secctx(ctx, len); | 988 | security_release_secctx(ctx, len); |
| 972 | } | 989 | } |
| 973 | audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_SIGNAL_INFO, | 990 | audit_send_reply(skb, seq, AUDIT_SIGNAL_INFO, 0, 0, |
| 974 | 0, 0, sig_data, sizeof(*sig_data) + len); | 991 | sig_data, sizeof(*sig_data) + len); |
| 975 | kfree(sig_data); | 992 | kfree(sig_data); |
| 976 | break; | 993 | break; |
| 977 | case AUDIT_TTY_GET: { | 994 | case AUDIT_TTY_GET: { |
| @@ -983,8 +1000,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
| 983 | s.log_passwd = tsk->signal->audit_tty_log_passwd; | 1000 | s.log_passwd = tsk->signal->audit_tty_log_passwd; |
| 984 | spin_unlock(&tsk->sighand->siglock); | 1001 | spin_unlock(&tsk->sighand->siglock); |
| 985 | 1002 | ||
| 986 | audit_send_reply(NETLINK_CB(skb).portid, seq, | 1003 | audit_send_reply(skb, seq, AUDIT_TTY_GET, 0, 0, &s, sizeof(s)); |
| 987 | AUDIT_TTY_GET, 0, 0, &s, sizeof(s)); | ||
| 988 | break; | 1004 | break; |
| 989 | } | 1005 | } |
| 990 | case AUDIT_TTY_SET: { | 1006 | case AUDIT_TTY_SET: { |
| @@ -1086,7 +1102,7 @@ static void __net_exit audit_net_exit(struct net *net) | |||
| 1086 | audit_sock = NULL; | 1102 | audit_sock = NULL; |
| 1087 | } | 1103 | } |
| 1088 | 1104 | ||
| 1089 | rcu_assign_pointer(aunet->nlsk, NULL); | 1105 | RCU_INIT_POINTER(aunet->nlsk, NULL); |
| 1090 | synchronize_net(); | 1106 | synchronize_net(); |
| 1091 | netlink_kernel_release(sock); | 1107 | netlink_kernel_release(sock); |
| 1092 | } | 1108 | } |
| @@ -1818,11 +1834,11 @@ void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk) | |||
| 1818 | spin_unlock_irq(&tsk->sighand->siglock); | 1834 | spin_unlock_irq(&tsk->sighand->siglock); |
| 1819 | 1835 | ||
| 1820 | audit_log_format(ab, | 1836 | audit_log_format(ab, |
| 1821 | " ppid=%ld pid=%d auid=%u uid=%u gid=%u" | 1837 | " ppid=%d pid=%d auid=%u uid=%u gid=%u" |
| 1822 | " euid=%u suid=%u fsuid=%u" | 1838 | " euid=%u suid=%u fsuid=%u" |
| 1823 | " egid=%u sgid=%u fsgid=%u tty=%s ses=%u", | 1839 | " egid=%u sgid=%u fsgid=%u tty=%s ses=%u", |
| 1824 | sys_getppid(), | 1840 | task_ppid_nr(tsk), |
| 1825 | tsk->pid, | 1841 | task_pid_nr(tsk), |
| 1826 | from_kuid(&init_user_ns, audit_get_loginuid(tsk)), | 1842 | from_kuid(&init_user_ns, audit_get_loginuid(tsk)), |
| 1827 | from_kuid(&init_user_ns, cred->uid), | 1843 | from_kuid(&init_user_ns, cred->uid), |
| 1828 | from_kgid(&init_user_ns, cred->gid), | 1844 | from_kgid(&init_user_ns, cred->gid), |
