From patchwork Tue Aug 30 21:13:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Moore X-Patchwork-Id: 9306103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CE342601C0 for ; Tue, 30 Aug 2016 21:15:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B786A28D67 for ; Tue, 30 Aug 2016 21:15:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A863928D6A; Tue, 30 Aug 2016 21:15:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from emsm-gh1-uea11.nsa.gov (emsm-gh1-uea11.nsa.gov [8.44.101.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AD4B28D67 for ; Tue, 30 Aug 2016 21:15:13 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.30,258,1470700800"; d="scan'208";a="18878590" IronPort-PHdr: =?us-ascii?q?9a23=3AZ0Mv6xy+3g/ddCXXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0OkWIJqq85mqBkHD//Il1AaPBtSCra4awLOL4uigATVGusfZ9ihaMdRlbFwssY?= =?us-ascii?q?0uhQsuAcqIWwXQDcXBSGgEJvlET0Jv5HqhMEJYS47UblzWpWCuv3ZJQk2sfTR8?= =?us-ascii?q?Kum9IIPOlcP/j7n0oMyKJVkWz2PgMPsydEzw9lSJ8JFOwMNLEeUY8lPxuHxGeu?= =?us-ascii?q?BblytDBGm4uFLC3Pq254Np6C9KuvgspIZqWKT+eLkkH/QDVGx1e0h83sDgtAHC?= =?us-ascii?q?QA2T/TNcFzxOylsbPhLBpC3ect+x93Ki97k15C7PH8D4Q/gKUDKu4r0jcwPvhT?= =?us-ascii?q?9PYzw0/m/JosN3i61frVSqoBkph8bQYYeIJL93Y6/cYfsASGZBV9oXXCtEUa2m?= =?us-ascii?q?aI5aN+McOa59qI7nqhNatR65AhOhLPnixj9Bmjn92qhsgLdpKh3PwAF1R4FGi3?= =?us-ascii?q?/Tttigcf5LCe0=3D?= X-IPAS-Result: =?us-ascii?q?A2GZAAB89sVX/wHyM5BcGQEBAQEBAQEBAQEBFAEBAQEBAQE?= =?us-ascii?q?BAQEBgwoBAQEBAR6BU7liBVAghX8DgWhMAQEBAQEBAQECAQJbJ4IyBAEVAQSCG?= =?us-ascii?q?AIkExQgCwMDCQIXCCEICAMBLRUXAQcLBRgEiCO+KQEKAQEBASKGLoIAhl8RAYV?= =?us-ascii?q?4BZlQmQkXhWMCSI95VIJHHIFpVIRNX4FAAQEB?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP; 30 Aug 2016 21:15:10 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u7ULDtoh018004; Tue, 30 Aug 2016 17:14:28 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u7ULDXu8109590 for ; Tue, 30 Aug 2016 17:13:33 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u7ULDWqB017966 for ; Tue, 30 Aug 2016 17:13:32 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BqAAB89sVXhxy3hNFcGgEBAQECAQEBAYMpAQEBAQGBcaUGkSiDNAVXFIYJgWZMAQIBAQEBAQITAQEBCgsJCRmFOgRSMAUCJgJJFgESiESvBY8kAQEIAiWBA4UrggCKD4JaBZlQmQmFegJIj3mDGxELgWkgNIZsAQEB X-IPAS-Result: A1BqAAB89sVXhxy3hNFcGgEBAQECAQEBAYMpAQEBAQGBcaUGkSiDNAVXFIYJgWZMAQIBAQEBAQITAQEBCgsJCRmFOgRSMAUCJgJJFgESiESvBY8kAQEIAiWBA4UrggCKD4JaBZlQmQmFegJIj3mDGxELgWkgNIZsAQEB X-IronPort-AV: E=Sophos;i="5.30,258,1470715200"; d="scan'208";a="5673778" Received: from emsm-gh1-uea10.corp.nsa.gov (HELO emsm-gh1-uea10.nsa.gov) ([10.208.41.36]) by goalie.tycho.ncsc.mil with ESMTP; 30 Aug 2016 17:13:28 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3Arw9WWx2YGskOUZmesmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?sekXLPad9pjvdHbS+e9qxAeQG96KsrQY1aGP7vuoGTRZp83Q6DZaKN0EfiRGoP?= =?us-ascii?q?1epxYnDs+BBB+zB9/RRAt+Iv5/UkR49WqwK0lfFZW2TVTTpnqv8WxaQU2nZkJL?= =?us-ascii?q?L+j4UrTfk96wn7jrvcaCOkMU2nHkPOg6bE3v616A7o9O2coqA51y4yOBmmFPde?= =?us-ascii?q?VSyDEgDnOotDG42P2N+oV++T9bofMr+p0Ie6z7e6MlUe4QV2x+YCgdrffmvhjb?= =?us-ascii?q?TAaJ+mBUEiBPykIJUED560TYU5n/+hXzsOZwwmGhIcr7VfhgWzms4blDRxjvhy?= =?us-ascii?q?MKcTU+9TeTwshxir9L5Ru8qx1j65TZbIGcKLx1eaaOU8kdQD95V9tVHwlGBZmx?= =?us-ascii?q?J98XCu0GJ+twtYTxp1IS6xC5AF//V6vU1jZUiyqujuUB2OM7HFSDhVR4Eg=3D?= =?us-ascii?q?=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0FxAAB89sVXhxy3hNFcGgEBAQECAQEBA?= =?us-ascii?q?RUBAQEBAgEBAQGDCgEBAQEBgXGlBpEogzQFVxSGCYFmTAEBAQEBAQEBAgECEAE?= =?us-ascii?q?BAQoLCQkZL4IyBAEVAQSCOgRSMAUCJgJJFgESiESvBY8kAQEIAgEkgQOFK4IAi?= =?us-ascii?q?g+CWgWZUJkJhXoCSI95gxsRC4FpIDSFLIFAAQEB?= X-IPAS-Result: =?us-ascii?q?A0FxAAB89sVXhxy3hNFcGgEBAQECAQEBARUBAQEBAgEBAQG?= =?us-ascii?q?DCgEBAQEBgXGlBpEogzQFVxSGCYFmTAEBAQEBAQEBAgECEAEBAQoLCQkZL4IyB?= =?us-ascii?q?AEVAQSCOgRSMAUCJgJJFgESiESvBY8kAQEIAgEkgQOFK4IAig+CWgWZUJkJhXo?= =?us-ascii?q?CSI95gxsRC4FpIDSFLIFAAQEB?= X-IronPort-AV: E=Sophos;i="5.30,258,1470700800"; d="scan'208";a="17100684" Received: from mx1.redhat.com ([209.132.183.28]) by emsm-gh1-uea10.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Aug 2016 21:13:24 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3165281F07; Tue, 30 Aug 2016 21:13:23 +0000 (UTC) Received: from [127.0.0.1] (ovpn-116-116.phx2.redhat.com [10.3.116.116]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7ULDM6F031197; Tue, 30 Aug 2016 17:13:22 -0400 Subject: [PATCH] audit: consistently record PIDs with task_tgid_nr() From: Paul Moore To: Jeff Vander Stoep , linux-audit@redhat.com Date: Tue, 30 Aug 2016 17:13:21 -0400 Message-ID: <147259160184.15526.16504125805093739705.stgit@localhost> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 30 Aug 2016 21:13:23 +0000 (UTC) X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: Cc: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Moore Unfortunately we record PIDs in audit records using a variety of methods despite the correct way being the use of task_tgid_nr(). This patch converts all of these callers, except for the case of AUDIT_SET in audit_receive_msg() (see the comment in the code). Reported-by: Jeff Vander Stoep Signed-off-by: Paul Moore --- kernel/audit.c | 8 +++++++- kernel/auditsc.c | 12 ++++++------ security/lsm_audit.c | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/kernel/audit.c b/kernel/audit.c index 8d528f9..02bde12 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -877,6 +877,12 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) return err; } if (s.mask & AUDIT_STATUS_PID) { + /* NOTE: we are using task_tgid_vnr() below because + * the s.pid value is relative to the namespace + * of the caller; at present this doesn't matter + * much since you can really only run auditd + * from the initial pid namespace, but something + * to keep in mind if this changes */ int new_pid = s.pid; pid_t requesting_pid = task_tgid_vnr(current); @@ -1917,7 +1923,7 @@ void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk) " euid=%u suid=%u fsuid=%u" " egid=%u sgid=%u fsgid=%u tty=%s ses=%u", task_ppid_nr(tsk), - task_pid_nr(tsk), + task_tgid_nr(tsk), from_kuid(&init_user_ns, audit_get_loginuid(tsk)), from_kuid(&init_user_ns, cred->uid), from_kgid(&init_user_ns, cred->gid), diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 2672d10..3824b1b 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -455,7 +455,7 @@ static int audit_filter_rules(struct task_struct *tsk, switch (f->type) { case AUDIT_PID: - pid = task_pid_nr(tsk); + pid = task_tgid_nr(tsk); result = audit_comparator(pid, f->op, f->val); break; case AUDIT_PPID: @@ -1993,7 +1993,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid, loginuid = from_kuid(&init_user_ns, kloginuid), tty = audit_get_tty(current); - audit_log_format(ab, "pid=%d uid=%u", task_pid_nr(current), uid); + audit_log_format(ab, "pid=%d uid=%u", task_tgid_nr(current), uid); audit_log_task_context(ab); audit_log_format(ab, " old-auid=%u auid=%u tty=%s old-ses=%u ses=%u res=%d", oldloginuid, loginuid, tty ? tty_name(tty) : "(none)", @@ -2220,7 +2220,7 @@ void __audit_ptrace(struct task_struct *t) { struct audit_context *context = current->audit_context; - context->target_pid = task_pid_nr(t); + context->target_pid = task_tgid_nr(t); context->target_auid = audit_get_loginuid(t); context->target_uid = task_uid(t); context->target_sessionid = audit_get_sessionid(t); @@ -2245,7 +2245,7 @@ int __audit_signal_info(int sig, struct task_struct *t) if (audit_pid && t->tgid == audit_pid) { if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1 || sig == SIGUSR2) { - audit_sig_pid = task_pid_nr(tsk); + audit_sig_pid = task_tgid_nr(tsk); if (uid_valid(tsk->loginuid)) audit_sig_uid = tsk->loginuid; else @@ -2345,7 +2345,7 @@ int __audit_log_bprm_fcaps(struct linux_binprm *bprm, void __audit_log_capset(const struct cred *new, const struct cred *old) { struct audit_context *context = current->audit_context; - context->capset.pid = task_pid_nr(current); + context->capset.pid = task_tgid_nr(current); context->capset.cap.effective = new->cap_effective; context->capset.cap.inheritable = new->cap_effective; context->capset.cap.permitted = new->cap_permitted; @@ -2377,7 +2377,7 @@ static void audit_log_task(struct audit_buffer *ab) from_kgid(&init_user_ns, gid), sessionid); audit_log_task_context(ab); - audit_log_format(ab, " pid=%d comm=", task_pid_nr(current)); + audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current)); audit_log_untrustedstring(ab, get_task_comm(comm, current)); audit_log_d_path_exe(ab, current->mm); } diff --git a/security/lsm_audit.c b/security/lsm_audit.c index cccbf30..45d927a 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c @@ -220,7 +220,7 @@ static void dump_common_audit_data(struct audit_buffer *ab, */ BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); - audit_log_format(ab, " pid=%d comm=", task_pid_nr(current)); + audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current)); audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm))); switch (a->type) { @@ -294,7 +294,7 @@ static void dump_common_audit_data(struct audit_buffer *ab, case LSM_AUDIT_DATA_TASK: { struct task_struct *tsk = a->u.tsk; if (tsk) { - pid_t pid = task_pid_nr(tsk); + pid_t pid = task_tgid_nr(tsk); if (pid) { char comm[sizeof(tsk->comm)]; audit_log_format(ab, " opid=%d ocomm=", pid);