Commit bfcf3e92 authored by Thomas Gleixner's avatar Thomas Gleixner

posix-cpu-timers: Use common permission check in posix_cpu_clock_get()

Replace the next slightly different copy of permission checks. That also
removes the necessarity to check the return value of the sample functions
because the clock id is already validated.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Link: https://lkml.kernel.org/r/20190821192919.414813172@linutronix.de
parent 6ae40e3f
...@@ -289,53 +289,24 @@ static int cpu_clock_sample_group(const clockid_t which_clock, ...@@ -289,53 +289,24 @@ static int cpu_clock_sample_group(const clockid_t which_clock,
return 0; return 0;
} }
static int posix_cpu_clock_get_task(struct task_struct *tsk, static int posix_cpu_clock_get(const clockid_t clock, struct timespec64 *tp)
const clockid_t which_clock,
struct timespec64 *tp)
{ {
int err = -EINVAL; const clockid_t clkid = CPUCLOCK_WHICH(clock);
u64 rtn; struct task_struct *tsk;
u64 t;
if (CPUCLOCK_PERTHREAD(which_clock)) {
if (same_thread_group(tsk, current))
err = cpu_clock_sample(which_clock, tsk, &rtn);
} else {
if (tsk == current || thread_group_leader(tsk))
err = cpu_clock_sample_group(which_clock, tsk, &rtn);
}
if (!err)
*tp = ns_to_timespec64(rtn);
return err;
}
static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec64 *tp) tsk = get_task_for_clock(clock);
{ if (!tsk)
const pid_t pid = CPUCLOCK_PID(which_clock); return -EINVAL;
int err = -EINVAL;
if (pid == 0) { if (CPUCLOCK_PERTHREAD(clock))
/* cpu_clock_sample(clkid, tsk, &t);
* Special case constant value for our own clocks. else
* We don't have to do any lookup to find ourselves. cpu_clock_sample_group(clkid, tsk, &t);
*/ put_task_struct(tsk);
err = posix_cpu_clock_get_task(current, which_clock, tp);
} else {
/*
* Find the given PID, and validate that the caller
* should be able to see it.
*/
struct task_struct *p;
rcu_read_lock();
p = find_task_by_vpid(pid);
if (p)
err = posix_cpu_clock_get_task(p, which_clock, tp);
rcu_read_unlock();
}
return err; *tp = ns_to_timespec64(t);
return 0;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment