From patchwork Mon Jul 18 20:11:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 9235209 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 CF08B600CB for ; Mon, 18 Jul 2016 20:17:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDCC620499 for ; Mon, 18 Jul 2016 20:17:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B20B620410; Mon, 18 Jul 2016 20:17:23 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (emsm-gh1-uea10.nsa.gov [8.44.101.8]) (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 6AF2C20410 for ; Mon, 18 Jul 2016 20:17:22 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.28,385,1464652800"; d="scan'208";a="15686987" IronPort-PHdr: =?us-ascii?q?9a23=3ABGhBgR84sfjCfP9uRHKM819IXTAuvvDOBiVQ1KB7?= =?us-ascii?q?0escTK2v8tzYMVDF4r011RmSDN2dt6MP0raN+4nbGkU4qa6bt34DdJEeHzQksu?= =?us-ascii?q?4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2WVTerzWI4CIIHV2nbEwu?= =?us-ascii?q?d7yzRt+Z1pjsn8mJuLTrKz1SgzS8Zb4gZD6Xli728vcsvI15N6wqwQHIqHYbM8?= =?us-ascii?q?5fxGdvOE7B102kvpT41NdZ/i9Ro/Ms8dJbGeW/JvxgDO9lFjBuD0QZrI2u7EGC?= =?us-ascii?q?HkOy4GABWDAWjgZQUU+C9Av9W5rtsibnrax83iedJsD9C6wlUjSlqaFgUxSujS?= =?us-ascii?q?YDcDsw8WXSg8o3i7pHoRWnvFtkzorVZpyFZ8d4Zb7XKNYTRG5dWZRKWihABJ6s?= =?us-ascii?q?KpECFvcMJvpws5j2p1xIqwC3QwarGrT01zVKi3TqiLA8yPkrCgrc3QYtTO4J5X?= =?us-ascii?q?DXqdG9YKMTV/2liarF1zPOa9tI1jrnrovFaBYspbeLR70mIuTLzkx6NQTFiB2r?= =?us-ascii?q?tZHhIyHdguYKs27d9PZ9Uf69o2omrQhrpX6o3Mh62dqBvZ4c1l2RrXYx+40yP9?= =?us-ascii?q?DtDRciOdM=3D?= X-IPAS-Result: =?us-ascii?q?A2EkAQBDN41X/wHyM5BbHAEBgyGBUrQwhVEFUR+HOUwBAQE?= =?us-ascii?q?BAQECAmIngjIEAQERAYITAgEDAQIPFRMGAQEECAIeCwECAwECBgEBFykICAMBL?= =?us-ascii?q?QMBBQELEQYICwUYBAGIDqJVgTE+MYpUhSoBAQWBAIg1AQEBAQEBBAEBAQEbCBC?= =?us-ascii?q?ED4ILiF8RAYV3jwWJXUeBXo0BAolAJYVOAkiOFzCBY4F+DRwXgVVOhi2BNQEBA?= =?us-ascii?q?Q?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 18 Jul 2016 20:17:18 +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 u6IKCU5O010212; Mon, 18 Jul 2016 16:13:35 -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 u6IKBnR9218866 for ; Mon, 18 Jul 2016 16:11:49 -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 u6IKBl5P010131 for ; Mon, 18 Jul 2016 16:11:49 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BiAAADN41XhincVdFbHAEBhHO0MIImgysFWYYaAoE0TAEBAQEBARMBAQEICwsJIYUMAgEDEhUZAQE3AQ9RNAEFARwGEyKIDqJUgTE+MYpUhSoBAQWBAIg1AQEBAQEBAQMBAQEBARoIEIQPgguLVguDB48FiV1HgV6NAQKJQIVzAkiOFzCBD4JSDRELgWxOh2IBAQE X-IPAS-Result: A1BiAAADN41XhincVdFbHAEBhHO0MIImgysFWYYaAoE0TAEBAQEBARMBAQEICwsJIYUMAgEDEhUZAQE3AQ9RNAEFARwGEyKIDqJUgTE+MYpUhSoBAQWBAIg1AQEBAQEBAQMBAQEBARoIEIQPgguLVguDB48FiV1HgV6NAQKJQIVzAkiOFzCBD4JSDRELgWxOh2IBAQE X-IronPort-AV: E=Sophos;i="5.28,385,1464667200"; d="scan'208";a="5587906" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 18 Jul 2016 16:11:18 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3Aw//NYxTu4FKzCA3EUCJ4/jFj8Npsv+yvbD5Q0YIu?= =?us-ascii?q?jvd0So/mwa64YxeN2/xhgRfzUJnB7Loc0qyN4vimBT1LuMra+Fk5M7V0Hycfjs?= =?us-ascii?q?sXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aJBzzOEJP?= =?us-ascii?q?K/jvHcaK1oLshrj0p8yYOlkTzBOGIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu?= =?us-ascii?q?5NznlpL1/A1zz158O34YIxu38I46Fp34d6XK77Z6U1S6BDRHRjajhtpZ6jiR6W?= =?us-ascii?q?SQiK4jNIVmQQjwoNAAXf6hz+don+vzG8tedn3iSee8rsQuZndy6l6vJJTx/uwB?= =?us-ascii?q?wbKjol4imDiMtwiuRAvA+luw5Xx4/SaZuScv1kcfWOLpshWWNdU5MJBGR6CYSm?= =?us-ascii?q?Yt5KVrJZMA=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0GrAAADN41XhincVdFbHQGEc7QwgiaDK?= =?us-ascii?q?wVZhhoCgTRMAQEBAQEBAgIPAQEBCAsLCSEvgjIEARIBB0kBAQEBAQEBAQFMAg1?= =?us-ascii?q?fAgEDEhUZAQE3AQ9RNAEFARwGEyKIDqJUgTE+MYpUhSoBAQWBAIg1AQEBAQEBA?= =?us-ascii?q?QMBAQEBARoIEIQPgguLVguDB48FiV1HgV6NAQKJQIVzAkiOFzCBD4JSDRELgWx?= =?us-ascii?q?Oh2IBAQE?= X-IPAS-Result: =?us-ascii?q?A0GrAAADN41XhincVdFbHQGEc7QwgiaDKwVZhhoCgTRMAQE?= =?us-ascii?q?BAQEBAgIPAQEBCAsLCSEvgjIEARIBB0kBAQEBAQEBAQFMAg1fAgEDEhUZAQE3A?= =?us-ascii?q?Q9RNAEFARwGEyKIDqJUgTE+MYpUhSoBAQWBAIg1AQEBAQEBAQMBAQEBARoIEIQ?= =?us-ascii?q?PgguLVguDB48FiV1HgV6NAQKJQIVzAkiOFzCBD4JSDRELgWxOh2IBAQE?= X-IronPort-AV: E=Sophos;i="5.28,385,1464652800"; d="scan'208";a="17737261" Received: from mail-pa0-f41.google.com ([209.85.220.41]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/AES128-GCM-SHA256; 18 Jul 2016 20:11:17 +0000 Received: by mail-pa0-f41.google.com with SMTP id fi15so60495362pac.1 for ; Mon, 18 Jul 2016 13:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=t4b4PD+x05NbAZFKSUymsBWDKWZxbUlOwk6n5+r/eUw=; b=Vd8eHOSNRlhMnV4QYwDZfbhzBwHZYL1c/mJBWCZGxq2I09hOWXo3vCZaZxnObf9q2Q Yns+A+vSZAVf5mZV4BmKPqQrAlccSY3guMH30U6zOBWlS97eXvhsENJLZOgWfieSgPEZ 8k5UHzcCu2BcfOj96EfHHE9KFYFnGg0wFscSs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=t4b4PD+x05NbAZFKSUymsBWDKWZxbUlOwk6n5+r/eUw=; b=Tt79RjP33FOEPEP4FjrFUS5erJiDnvo81m6GgcOj23ITnZet/QBGnDhYUm+aWcxflW g57wpCJbXdCUSMQfq7rtNDOjcYL9B4txFx/uETiy5xWxruuMqNUqyJ1sbodjmhqij2sj pg1n+4tg3Hvbg8V5UtR7tbMR8FfM1AA1f+S9DwbJ7Ljm+wGuOehWbrv90wdZfZABba+k fLTQ2s5cBvKcePsD8TWLgrmhVcTyZ9E7jOwuE64wag8v8DTlWn3LFXPWg6UfXG0rQkYM gD1wW1SMjbi+dOX2QGY3WCJ4IC3Wb9cAO+NREMUnJLi7yFy/Qb3/CPYwzdgCAous/SEM FZEg== X-Gm-Message-State: ALyK8tJ1ZokgiDiU9kp22M0v8DkZ/4RgUXsI3oj3GucbXAvvvHkpnAoBeCnaVDgYGy4OWVhb X-Received: by 10.66.86.103 with SMTP id o7mr59273826paz.5.1468872676440; Mon, 18 Jul 2016 13:11:16 -0700 (PDT) Received: from localhost.localdomain (c-73-67-244-238.hsd1.or.comcast.net. [73.67.244.238]) by smtp.gmail.com with ESMTPSA id 132sm6970435pfu.6.2016.07.18.13.11.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jul 2016 13:11:15 -0700 (PDT) From: John Stultz To: lkml Subject: [RFC][PATCH 2/2 v3] security: Add task_settimerslack/task_gettimerslack LSM hook Date: Mon, 18 Jul 2016 13:11:11 -0700 Message-Id: <1468872671-9002-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468872671-9002-1-git-send-email-john.stultz@linaro.org> References: <1468872671-9002-1-git-send-email-john.stultz@linaro.org> X-Mailman-Approved-At: Mon, 18 Jul 2016 16:12:30 -0400 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Elliott Hughes , Kees Cook , Android Kernel Team , Rom Lemarchand , linux-security-module@vger.kernel.org, Oren Laadan , Ruchi Kandoi , Dmitry Shmidt , John Stultz , selinux@tycho.nsa.gov, Colin Cross , Andrew Morton , Todd Kjos , Arjan van de Ven , Thomas Gleixner MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP As requested, this patch implements a task_settimerslack and task_gettimerslack LSM hooks so that the /proc//timerslack_ns interface can have finer grained security policies applied to it. I've kept the CAP_SYS_NICE check in the timerslack_ns_write/show functions, as hiding it in the LSM hook seems too opaque, and doesn't seem like a widely enough adopted practice. Don't really know what I'm doing here, so close review would be appreciated! Cc: Kees Cook Cc: "Serge E. Hallyn" Cc: Andrew Morton Cc: Thomas Gleixner CC: Arjan van de Ven Cc: Oren Laadan Cc: Ruchi Kandoi Cc: Rom Lemarchand Cc: Todd Kjos Cc: Colin Cross Cc: Nick Kralevich Cc: Dmitry Shmidt Cc: Elliott Hughes Cc: Android Kernel Team Cc: linux-security-module@vger.kernel.org Cc: selinux@tycho.nsa.gov Signed-off-by: John Stultz Reviewed-by: Nick Kralevich Acked-by: Serge Hallyn Acked-by: Kees Cook --- v2: * Initial swing at adding settimerslack LSM hook v3: * Fix current/p switchup bug noted by NickK * Add gettimerslack hook suggested by NickK fs/proc/base.c | 10 ++++++++++ include/linux/lsm_hooks.h | 13 +++++++++++++ include/linux/security.h | 12 ++++++++++++ security/security.c | 14 ++++++++++++++ security/selinux/hooks.c | 12 ++++++++++++ 5 files changed, 61 insertions(+) diff --git a/fs/proc/base.c b/fs/proc/base.c index c94abae..cc66aa8 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2286,6 +2286,12 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf, goto out; } + err = security_task_settimerslack(p, slack_ns); + if (err) { + count = err; + goto out; + } + task_lock(p); if (slack_ns == 0) p->timer_slack_ns = p->default_timer_slack_ns; @@ -2314,6 +2320,10 @@ static int timerslack_ns_show(struct seq_file *m, void *v) goto out; } + ret = security_task_gettimerslack(p); + if (ret) + goto out; + task_lock(p); seq_printf(m, "%llu\n", p->timer_slack_ns); task_unlock(p); diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 7ae3976..290483e 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -627,6 +627,15 @@ * Check permission before moving memory owned by process @p. * @p contains the task_struct for process. * Return 0 if permission is granted. + * @task_settimerslack: + * Check permission before setting timerslack value of @p to @slack. + * @p contains the task_struct of a process. + * @slack contains the new slack value. + * Return 0 if permission is granted. + * @task_gettimerslack: + * Check permission before returning the timerslack value of @p. + * @p contains the task_struct of a process. + * Return 0 if permission is granted. * @task_kill: * Check permission before sending signal @sig to @p. @info can be NULL, * the constant 1, or a pointer to a siginfo structure. If @info is 1 or @@ -1473,6 +1482,8 @@ union security_list_options { int (*task_setscheduler)(struct task_struct *p); int (*task_getscheduler)(struct task_struct *p); int (*task_movememory)(struct task_struct *p); + int (*task_settimerslack)(struct task_struct *p, u64 slack); + int (*task_gettimerslack)(struct task_struct *p); int (*task_kill)(struct task_struct *p, struct siginfo *info, int sig, u32 secid); int (*task_wait)(struct task_struct *p); @@ -1732,6 +1743,8 @@ struct security_hook_heads { struct list_head task_setscheduler; struct list_head task_getscheduler; struct list_head task_movememory; + struct list_head task_settimerslack; + struct list_head task_gettimerslack; struct list_head task_kill; struct list_head task_wait; struct list_head task_prctl; diff --git a/include/linux/security.h b/include/linux/security.h index 14df373..ab70f47 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -325,6 +325,8 @@ int security_task_setrlimit(struct task_struct *p, unsigned int resource, int security_task_setscheduler(struct task_struct *p); int security_task_getscheduler(struct task_struct *p); int security_task_movememory(struct task_struct *p); +int security_task_settimerslack(struct task_struct *p, u64 slack); +int security_task_gettimerslack(struct task_struct *p); int security_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid); int security_task_wait(struct task_struct *p); @@ -950,6 +952,16 @@ static inline int security_task_movememory(struct task_struct *p) return 0; } +static inline int security_task_settimerslack(struct task_struct *p, u64 slack) +{ + return 0; +} + +static inline int security_task_gettimerslack(struct task_struct *p) +{ + return 0; +} + static inline int security_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid) diff --git a/security/security.c b/security/security.c index 7095693..4ced236 100644 --- a/security/security.c +++ b/security/security.c @@ -977,6 +977,16 @@ int security_task_movememory(struct task_struct *p) return call_int_hook(task_movememory, 0, p); } +int security_task_settimerslack(struct task_struct *p, u64 slack) +{ + return call_int_hook(task_settimerslack, 0, p, slack); +} + +int security_task_gettimerslack(struct task_struct *p) +{ + return call_int_hook(task_gettimerslack, 0, p); +} + int security_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid) { @@ -1720,6 +1730,10 @@ struct security_hook_heads security_hook_heads = { LIST_HEAD_INIT(security_hook_heads.task_getscheduler), .task_movememory = LIST_HEAD_INIT(security_hook_heads.task_movememory), + .task_settimerslack = + LIST_HEAD_INIT(security_hook_heads.task_settimerslack), + .task_gettimerslack = + LIST_HEAD_INIT(security_hook_heads.task_gettimerslack), .task_kill = LIST_HEAD_INIT(security_hook_heads.task_kill), .task_wait = LIST_HEAD_INIT(security_hook_heads.task_wait), .task_prctl = LIST_HEAD_INIT(security_hook_heads.task_prctl), diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index a86d537..aac9599 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3849,6 +3849,16 @@ static int selinux_task_movememory(struct task_struct *p) return current_has_perm(p, PROCESS__SETSCHED); } +static int selinux_task_settimerslack(struct task_struct *p, u64 slack) +{ + return current_has_perm(p, PROCESS__SETSCHED); +} + +static int selinux_task_gettimerslack(struct task_struct *p) +{ + return current_has_perm(p, PROCESS__GETSCHED); +} + static int selinux_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid) { @@ -6092,6 +6102,8 @@ static struct security_hook_list selinux_hooks[] = { LSM_HOOK_INIT(task_setscheduler, selinux_task_setscheduler), LSM_HOOK_INIT(task_getscheduler, selinux_task_getscheduler), LSM_HOOK_INIT(task_movememory, selinux_task_movememory), + LSM_HOOK_INIT(task_settimerslack, selinux_task_settimerslack), + LSM_HOOK_INIT(task_gettimerslack, selinux_task_gettimerslack), LSM_HOOK_INIT(task_kill, selinux_task_kill), LSM_HOOK_INIT(task_wait, selinux_task_wait), LSM_HOOK_INIT(task_to_inode, selinux_task_to_inode),