Messages in this thread Patch in this message | | | Date | Mon, 23 Sep 2019 16:54:36 +0200 | From | Thomas Gleixner <> | Subject | [patch V2 1/6] posix-cpu-timers: Restrict timer_create() permissions |
| |
From: Thomas Gleixner <tglx@linutronix.de>
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@linutronix.de> Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
--- kernel/time/posix-cpu-timers.c | 16 +++++++++++++++- 1 file changed, 15 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> @@ -82,7 +83,20 @@ 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: + */ + return ptrace_may_access(p, PTRACE_MODE_ATTACH_REALCREDS) ? p : NULL; } static struct task_struct *__get_task_for_clock(const clockid_t clock,
| |