lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1279735436-8254-4-git-send-email-tomasz.buchert@inria.fr>
Date:	Wed, 21 Jul 2010 20:03:55 +0200
From:	Tomasz Buchert <tomasz.buchert@...ia.fr>
To:	linux-kernel@...r.kernel.org,
	Daniel Walker <dwalker@...eaurora.org>,
	Stanislaw Gruszka <sgruszka@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>
Cc:	Tomasz Buchert <tomasz.buchert@...ia.fr>,
	Lucas Nussbaum <lucas.nussbaum@...ia.fr>
Subject: [PATCH 3/4] posix-cpu-timers: Wider access to the thread clocks

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@...ia.fr>
Signed-off-by: Lucas Nussbaum <lucas.nussbaum@...ia.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ