[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190905120539.888798188@linutronix.de>
Date: Thu, 05 Sep 2019 14:03:42 +0200
From: Thomas Gleixner <tglx@...utronix.de>
To: LKML <linux-kernel@...r.kernel.org>
Cc: Peter Zijlstra <peterz@...radead.org>,
Frederic Weisbecker <fweisbec@...il.com>,
Oleg Nesterov <oleg@...hat.com>,
Ingo Molnar <mingo@...nel.org>,
Kees Cook <keescook@...omium.org>
Subject: [patch 3/6] posix-cpu-timers: Restrict timer_create() permissions
Right now there is no restriction at all to attach a Posix CPU timer to any
process in the system. Per thread CPU timers are limited to be created by
threads in the same thread group.
Timers can be used to observe activity of tasks and also impose overhead on
the process to which they are attached because that process needs to do the
fine grained CPU time accounting.
Limit the ability to attach timers to a process by checking whether the
task which is creating the timer has permissions to attach ptrace on the
target process.
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
---
kernel/time/posix-cpu-timers.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -6,6 +6,7 @@
#include <linux/sched/signal.h>
#include <linux/sched/cputime.h>
#include <linux/posix-timers.h>
+#include <linux/ptrace.h>
#include <linux/errno.h>
#include <linux/math64.h>
#include <linux/uaccess.h>
@@ -78,7 +79,22 @@ static struct task_struct *lookup_task(c
/*
* For processes require that p is group leader.
*/
- return has_group_leader_pid(p) ? p : NULL;
+ if (!has_group_leader_pid(p))
+ return NULL;
+
+ /*
+ * Avoid the ptrace overhead when this is current's process
+ */
+ if (same_thread_group(p, current))
+ return p;
+
+ /*
+ * Creating timers on processes which cannot be ptraced is not
+ * permitted:
+ */
+ if (!ptrace_may_access(p, PTRACE_MODE_ATTACH_REALCREDS))
+ return NULL;
+ return p;
}
static struct task_struct *__get_task_for_clock(const clockid_t clock,
Powered by blists - more mailing lists