lkml.org 
[lkml]   [2010]   [Jul]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 3/4] posix-cpu-timers: Wider access to the thread clocks
    Date
    Per-thread clocks are so far accessible only within
    the same thread group. This patch makes it possible to get
    this information for any thread of the same user and for
    a user with CAP_SYS_ADMIN capability.

    same_thread_group is not used anymore because if the thread is in
    the same thread group as 'current' then they will have the same
    owner anyway.

    Signed-off-by: Tomasz Buchert <tomasz.buchert@inria.fr>
    Signed-off-by: Lucas Nussbaum <lucas.nussbaum@loria.fr>
    ---
    kernel/posix-cpu-timers.c | 34 +++++++++++++++++++++++++++-------
    1 files changed, 27 insertions(+), 7 deletions(-)

    diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
    index 78ad536..04f49ce 100644
    --- a/kernel/posix-cpu-timers.c
    +++ b/kernel/posix-cpu-timers.c
    @@ -25,6 +25,26 @@ void update_rlimit_cpu(unsigned long rlim_new)
    spin_unlock_irq(&current->sighand->siglock);
    }

    +/* RCU lock needed */
    +static int thread_clock_allowed(struct task_struct *p)
    +{
    + const struct cred *cred, *pcred;
    +
    + if (unlikely(capable(CAP_SYS_ADMIN)))
    + return 1;
    + cred = current_cred();
    + pcred = __task_cred(p);
    +
    + return (cred->euid == pcred->euid ||
    + cred->euid == pcred->uid);
    +}
    +
    +/* RCU read lock needed */
    +static inline int process_clock_allowed(struct task_struct *p)
    +{
    + return thread_group_leader(p);
    +}
    +
    static int check_task_clock(const clockid_t which_clock)
    {
    int error = 0;
    @@ -37,7 +57,7 @@ static int check_task_clock(const clockid_t which_clock)
    rcu_read_lock();
    p = find_task_by_vpid(pid);
    if (!p || !(POSIX_CLOCK_PERTHREAD(which_clock) ?
    - same_thread_group(p, current) : thread_group_leader(p))) {
    + thread_clock_allowed(p) : process_clock_allowed(p))) {
    error = -EINVAL;
    }
    rcu_read_unlock();
    @@ -68,9 +88,9 @@ static int get_start_time(clockid_t which_clock, struct timespec *start)
    find_task_by_vpid(POSIX_CLOCK_PID(which_clock));
    if (p && (
    (POSIX_CLOCK_PERTHREAD(which_clock) &&
    - same_thread_group(p, current)) ||
    + thread_clock_allowed(p)) ||
    (!POSIX_CLOCK_PERTHREAD(which_clock) &&
    - thread_group_leader(p) && p->sighand))) {
    + process_clock_allowed(p) && p->sighand))) {
    *start = p->start_time;
    return 0;
    }
    @@ -529,13 +549,13 @@ int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
    p = find_task_by_vpid(pid);
    if (p) {
    if (POSIX_CLOCK_PERTHREAD(which_clock)) {
    - if (same_thread_group(p, current)) {
    + if (thread_clock_allowed(p)) {
    error = cpu_clock_sample(which_clock,
    p, &rtn);
    }
    } else {
    read_lock(&tasklist_lock);
    - if (thread_group_leader(p) && p->sighand) {
    + if (process_clock_allowed(p) && p->sighand) {
    error =
    cpu_clock_sample_group(which_clock,
    p, &rtn);
    @@ -575,7 +595,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
    p = current;
    } else {
    p = find_task_by_vpid(pid);
    - if (p && !same_thread_group(p, current))
    + if (p && !thread_clock_allowed(p))
    p = NULL;
    }
    } else {
    @@ -583,7 +603,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
    p = current->group_leader;
    } else {
    p = find_task_by_vpid(pid);
    - if (p && !thread_group_leader(p))
    + if (p && !process_clock_allowed(p))
    p = NULL;
    }
    }
    --
    1.6.3.3


    \
     
     \ /
      Last update: 2010-07-30 12:03    [W:2.925 / U:0.400 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site