lkml.org 
[lkml]   [2019]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[patch V2 2/6] posix-cpu-timers: Restrict clock_gettime() permissions
From: Thomas Gleixner <tglx@linutronix.de>

Similar to creating timers on a process there is no restriction at all to
read the Posix CPU clocks of any process in the system. Per thread CPU
clock access is limited to threads in the same thread group.

The per process CPU clocks can be used to observe activity of tasks and
reading them can affect the execution of the process to which they are
attached as reading can require to lock sighand lock and sum up the fine
grained accounting for all threads in the process.

Restrict it by checking ptrace MODE_READ permissions of the reader 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 | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -76,8 +76,19 @@ static struct task_struct *lookup_task(c
* Timers need the group leader because they take a
* reference on it and store the task pointer until the
* timer is destroyed.
+ *
+ * current can obviously access it's own process, so spare
+ * the ptrace check below.
*/
- return (p == current || thread_group_leader(p)) ? p : NULL;
+ if (p == current)
+ return p;
+
+ if (!thread_group_leader(p))
+ return NULL;
+
+ if (!ptrace_may_access(p, PTRACE_MODE_READ_REALCREDS))
+ return NULL;
+ return p;
}

/*

\
 
 \ /
  Last update: 2019-09-23 16:57    [W:0.052 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site