All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Scordino <cloud.of.andor@gmail.com>
To: Peter Chubb <peterc@gelato.unsw.edu.au>
Cc: Chris Wright <chrisw@osdl.org>,
	dean gaudet <dean-list-linux-kernel@arctic.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	"Magnus Naeslund(f)" <mag@fbab.net>,
	"Hua Zhong (hzhong)" <hzhong@cisco.com>,
	linux-kernel@vger.kernel.org, kernelnewbies@nl.linux.org,
	David Wagner <daw@cs.berkeley.edu>,
	Lee Revell <rlrevell@joe-job.com>
Subject: Re: [PATCH] getrusage sucks
Date: Tue, 15 Nov 2005 17:56:07 +0100	[thread overview]
Message-ID: <200511151756.09397.cloud.of.andor@gmail.com> (raw)
In-Reply-To: <20051112011006.GD7991@shell0.pdx.osdl.net>

On Tuesday 15 November 2005 02:08, Peter Chubb wrote:
> >> You need to wrap this with a read_lock(&tasklist_lock) to be safe,
> >> I think.
>
> Claudio> Right. Probably this was the meaning also of Hua's
> Claudio> mail. Sorry, but I didn't get it immediately.
>
> Claudio> So, what if I do as follows ? Do you see any problem with
> Claudio> this solution ?
>
> You should probably restrict the ability to read a process's usage to
> a suitably privileged user -- i.e., effective uid same as the task's,
> or capable(CAP_SYS_RESOURCE) or maybe capable(CAP_SYS_ADMIN)

So, is CAP_SYS_PTRACE (as done in the patch below) not enough ?

Honestly, I don't see any problem in allowing any user to know usage 
information about _his_ processes...

Many thanks,

            Claudio

Signed-off-by: Claudio Scordino <cloud.of.andor@gmail.com>

diff --git a/kernel/sys.c b/kernel/sys.c
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1746,9 +1746,29 @@ int getrusage(struct task_struct *p, int
 
 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)


  parent reply	other threads:[~2005-11-15 16:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-10 23:47 [PATCH] getrusage sucks Hua Zhong (hzhong)
2005-11-11  0:23 ` Claudio Scordino
2005-11-11  0:32   ` Magnus Naeslund(f)
2005-11-11  1:11     ` Claudio Scordino
2005-11-11 13:30       ` Alan Cox
2005-11-11 22:38         ` Claudio Scordino
2005-11-11 23:23           ` Alan Cox
2005-11-11 23:02             ` Chris Wright
2005-11-11 23:44               ` David Wagner
2005-11-12  0:53                 ` Chris Wright
2005-11-12  6:37                   ` David Wagner
2005-11-11 23:58               ` Alan Cox
2005-11-11 23:43                 ` Claudio Scordino
2005-11-11 23:49                   ` dean gaudet
2005-11-12  1:10                     ` Chris Wright
2005-11-12 15:10                       ` making makefile for 2.6 kernel anil dahiya
2005-11-12 15:16                       ` anil dahiya
2005-11-12 22:19                         ` Sam Ravnborg
2005-11-13  1:34                       ` [PATCH] getrusage sucks Claudio Scordino
2005-11-15 16:56                       ` Claudio Scordino [this message]
2005-11-15 17:00                       ` New getrusage Claudio Scordino
2005-11-11 23:08             ` [PATCH] getrusage sucks Claudio Scordino
2005-11-11 23:41           ` David Wagner
2005-11-15  1:08       ` Peter Chubb
  -- strict thread matches above, loose matches on Subject: below --
2005-11-15 18:25 linux
2005-11-11 23:49 Hua Zhong (hzhong)
2005-11-10 22:34 Claudio Scordino
2005-11-11  5:06 ` David Wagner
2005-11-11 19:09   ` Lee Revell
2005-11-11 19:13     ` David Wagner

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=200511151756.09397.cloud.of.andor@gmail.com \
    --to=cloud.of.andor@gmail.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=chrisw@osdl.org \
    --cc=daw@cs.berkeley.edu \
    --cc=dean-list-linux-kernel@arctic.org \
    --cc=hzhong@cisco.com \
    --cc=kernelnewbies@nl.linux.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mag@fbab.net \
    --cc=peterc@gelato.unsw.edu.au \
    --cc=rlrevell@joe-job.com \
    /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 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.