From patchwork Fri Jul 15 17:24:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 72121 Delivered-To: patches@linaro.org Received: by 10.140.29.52 with SMTP id a49csp735130qga; Fri, 15 Jul 2016 10:24:30 -0700 (PDT) X-Received: by 10.66.126.178 with SMTP id mz18mr33999291pab.15.1468603469930; Fri, 15 Jul 2016 10:24:29 -0700 (PDT) Return-Path: Received: from mail-pf0-x230.google.com (mail-pf0-x230.google.com. [2607:f8b0:400e:c00::230]) by mx.google.com with ESMTPS id c1si10080604paz.112.2016.07.15.10.24.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jul 2016 10:24:29 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::230 as permitted sender) client-ip=2607:f8b0:400e:c00::230; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::230 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x230.google.com with SMTP id p64so9468258pfb.1 for ; Fri, 15 Jul 2016 10:24:29 -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=2vxn5qrMsUB9wa0dplZIWyW7NZf1GaSLyGhaSG7pbRI=; b=XBKgPawXNKIWG/FeZpppiWZbU87rg87Dyj+M0yXgIwvOppRCyOnFIKR0NJ3sHISDzq +U/el1l1SXPUAXz5hH0i5bbsLXipaRW/Y2ZHty0fm1PZppTMUvJWFLwn7C9RV0jATQbD iqxB8kT0e51ovg+hTDwNbXvzTkGM6AvMC1SRM= 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=2vxn5qrMsUB9wa0dplZIWyW7NZf1GaSLyGhaSG7pbRI=; b=lEStHPr5MDe3dqNesFn5hJht8IVlWoR+JYnsUNZn6Jd72LIGEJX1TqGmkzrqMEJtdb 6dqbOFM6g3BR519jgWEkNOnSuyu1UDDqX0MVYPmRIolhvjaiJKkK6Qb+73KXPOFoB/uU 5yWk6q34OTuknFs7USVxiWVpLSc0lKpGr/f12W+R75rDanMIeDWWvTlYkMS6/kMJ0BRH GvPdAt4a5PI/00jLVjEQtWjRB8szMJag26n+plJY6t8iyv+fN0EJdUPjdXnUGoFs1iBW DBG523Z83NW5ogYp9AI8r0PMQIz/QQV1Bo/slnqCJ95jPoXQmi9Q3sLWcGrZZ3WgPGyr gs2A== X-Gm-Message-State: ALyK8tLEsoosUwFC7xQ5UqlKIHmGiSIL5rDjb7pDvJcNTg20bZp6ndcKirWfqV3ztE00tAAOPO4= X-Received: by 10.98.55.1 with SMTP id e1mr23263508pfa.107.1468603469634; Fri, 15 Jul 2016 10:24:29 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-73-67-244-238.hsd1.or.comcast.net. [73.67.244.238]) by smtp.gmail.com with ESMTPSA id zk7sm6008954pac.41.2016.07.15.10.24.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Jul 2016 10:24:29 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Kees Cook , "Serge E. Hallyn" , Andrew Morton , Thomas Gleixner , Arjan van de Ven , Oren Laadan , Ruchi Kandoi , Rom Lemarchand , Todd Kjos , Colin Cross , Nick Kralevich , Dmitry Shmidt , Elliott Hughes , Android Kernel Team Subject: [RFC][PATCH 2/2 v2] security: Add task_settimerslack LSM hook Date: Fri, 15 Jul 2016 10:24:20 -0700 Message-Id: <1468603460-17034-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468603460-17034-1-git-send-email-john.stultz@linaro.org> References: <1468603460-17034-1-git-send-email-john.stultz@linaro.org> As requested, this patch implements a task_settimerslack LSM hook so that the /proc//timerslack_ns interface can have finer grained security policies applied to it. 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 Signed-off-by: John Stultz --- v2: Initial swing at adding LSM hook fs/proc/base.c | 7 +++++++ include/linux/lsm_hooks.h | 7 +++++++ include/linux/security.h | 6 ++++++ security/security.c | 7 +++++++ security/selinux/hooks.c | 6 ++++++ 5 files changed, 33 insertions(+) -- 1.9.1 diff --git a/fs/proc/base.c b/fs/proc/base.c index 8f4f8d7..7f10b37 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2284,6 +2284,12 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf, if (!p) return -ESRCH; + err = security_task_settimerslack(current, slack_ns); + if (err) { + count = err; + goto out; + } + task_lock(p); if (slack_ns == 0) p->timer_slack_ns = p->default_timer_slack_ns; @@ -2291,6 +2297,7 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf, p->timer_slack_ns = slack_ns; task_unlock(p); +out: put_task_struct(p); return count; diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 7ae3976..ed546c4 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -627,6 +627,11 @@ * 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_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 +1478,7 @@ 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_kill)(struct task_struct *p, struct siginfo *info, int sig, u32 secid); int (*task_wait)(struct task_struct *p); @@ -1732,6 +1738,7 @@ 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_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..1736e2b 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -325,6 +325,7 @@ 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_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid); int security_task_wait(struct task_struct *p); @@ -950,6 +951,11 @@ 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_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid) diff --git a/security/security.c b/security/security.c index 7095693..45f15cb 100644 --- a/security/security.c +++ b/security/security.c @@ -977,6 +977,11 @@ 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_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid) { @@ -1720,6 +1725,8 @@ 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_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..e7c04322 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3849,6 +3849,11 @@ 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_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid) { @@ -6092,6 +6097,7 @@ 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_kill, selinux_task_kill), LSM_HOOK_INIT(task_wait, selinux_task_wait), LSM_HOOK_INIT(task_to_inode, selinux_task_to_inode),