All of lore.kernel.org
 help / color / mirror / Atom feed
* [KJ] [PATCH] Extending getrusage
@ 2006-04-20 15:21 ` Claudio Scordino
  0 siblings, 0 replies; 11+ messages in thread
From: Claudio Scordino @ 2006-04-20 15:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Alan Cox, torvalds, Andrew Morton,
	kernel-janitors

For the people who missed the beginning of the discussion, the
following patch is an extension of the existing getrusage syscall()
and it applies to the 2.6.16.9 kernel.

It allows a task to read usage information about another task. The argument
who can be equal to RUSAGE_SELF, to RUSAGE_CHILDREN or to a valid pid.

The permissions are checked through security_ptrace() as suggested by Andy.

Any other comment ?

Thanks,

           Claudio


Signed-off-by: Claudio Scordino <cloud.of.andor@gmail.com>
--- sys.old.c	2006-04-19 02:10:14.000000000 -0400
+++ sys.c	2006-04-20 10:53:16.000000000 -0400
@@ -1765,11 +1765,30 @@ int getrusage(struct task_struct *p, int
 	return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
 }

+/* who can be RUSAGE_SELF, RUSAGE_CHILDREN or a valid pid */
 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)) {
+		if (who <= 0)
+			goto bad;
+		tsk = find_task_by_pid(who);
+		if (tsk = NULL)
+			goto bad;
+		if ((tsk != current) && security_ptrace(current, tsk))
+			goto bad;
+		/* current can get info about tsk */
+		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)

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-04-22 20:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-20 15:21 [KJ] [PATCH] Extending getrusage Claudio Scordino
2006-04-20 15:21 ` Claudio Scordino
2006-04-20 23:21 ` [KJ] " Andrew Morton
2006-04-20 23:21   ` Andrew Morton
2006-04-21  7:41   ` [KJ] " bert hubert
2006-04-21  7:41     ` bert hubert
2006-04-21 10:05     ` [KJ] " Claudio Scordino
2006-04-21 10:05       ` Claudio Scordino
2006-04-21 14:32       ` [KJ] " Ulrich Drepper
2006-04-21 14:32         ` Ulrich Drepper
2006-04-22 10:25         ` Claudio Scordino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.