public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Claudio Scordino <cloud.of.andor@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	torvalds@osdl.org, Andrew Morton <akpm@osdl.org>,
	kernel-janitors@lists.osdl.org
Subject: [PATCH] Improved getrusage
Date: Tue, 18 Apr 2006 19:37:07 +0200	[thread overview]
Message-ID: <200604181937.08224.cloud.of.andor@gmail.com> (raw)

[-- 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)

                 reply	other threads:[~2006-04-18 17:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200604181937.08224.cloud.of.andor@gmail.com \
    --to=cloud.of.andor@gmail.com \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=kernel-janitors@lists.osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox