public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Improved getrusage
@ 2006-04-18 17:37 Claudio Scordino
  0 siblings, 0 replies; only message in thread
From: Claudio Scordino @ 2006-04-18 17:37 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alan Cox, torvalds, Andrew Morton, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 425 bytes --]

Hi all!

A couple of months ago we discussed the possibility of improving the getrusage 
syscall to read usage information about tasks belonging to the same owner 
(not just about current and children).

After an extensive discussion on the mailing list, some of us agreed about the 
following patch. Some others, instead, said that it is too permissive. 

Should we definitely drop this idea ??

Thanks,

           Claudio

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1093 bytes --]

Signed-off-by: Claudio Scordino <cloud.of.andor@gmail.com>
--- sys.c	2006-04-18 12:54:38.000000000 -0400
+++ sys.new.c	2006-04-18 12:58:41.000000000 -0400
@@ -1767,9 +1767,29 @@
 
 asmlinkage long sys_getrusage(int who, struct rusage __user *ru)
 {
-	if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
-		return -EINVAL;
-	return getrusage(current, who, ru);
+	struct rusage r;
+	struct task_struct* tsk = current;
+	read_lock(&tasklist_lock);
+	if ((who != RUSAGE_SELF) && (who != RUSAGE_CHILDREN)) {
+		tsk = find_task_by_pid(who);
+		if ((tsk == NULL) || (who <=0)) 
+			goto bad;
+		if (((current->uid != tsk->euid) ||
+			(current->uid != tsk->suid) ||
+			(current->uid != tsk->uid) ||
+			(current->gid != tsk->egid) ||
+			(current->gid != tsk->sgid) ||
+			(current->gid != tsk->gid)) && !capable(CAP_SYS_PTRACE))
+				goto bad;
+		who = RUSAGE_SELF;
+	}
+	k_getrusage(tsk, who, &r);
+	read_unlock(&tasklist_lock);
+	return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
+
+bad:
+	read_unlock(&tasklist_lock);
+	return tsk ? -EPERM : -EINVAL;
 }
 
 asmlinkage long sys_umask(int mask)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-04-18 17:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-18 17:37 [PATCH] Improved getrusage Claudio Scordino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox