Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932133Ab0G3J7P (ORCPT ); Fri, 30 Jul 2010 05:59:15 -0400 Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]:64237 "EHLO mail4-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756175Ab0G3J7I (ORCPT ); Fri, 30 Jul 2010 05:59:08 -0400 X-IronPort-AV: E=Sophos;i="4.55,286,1278280800"; d="scan'208";a="67126256" From: Tomasz Buchert To: linux-kernel@vger.kernel.org, Daniel Walker , Stanislaw Gruszka , Peter Zijlstra Cc: Tomasz Buchert , Lucas Nussbaum Subject: [PATCH 3/4] posix-cpu-timers: Wider access to the thread clocks Date: Fri, 30 Jul 2010 11:57:46 +0200 Message-Id: <1280483867-6387-4-git-send-email-tomasz.buchert@inria.fr> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1280483867-6387-3-git-send-email-tomasz.buchert@inria.fr> References: <1280483867-6387-1-git-send-email-tomasz.buchert@inria.fr> <1280483867-6387-2-git-send-email-tomasz.buchert@inria.fr> <1280483867-6387-3-git-send-email-tomasz.buchert@inria.fr> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3502 Lines: 109 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 Signed-off-by: Lucas Nussbaum --- 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(¤t->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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/