Re: [PATCH] getrusage sucks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > > You need to wrap this with a read_lock(&tasklist_lock) to be safe, I
> > > think.
> >
>
> It will depend on the data accuracy. If the information on cpu usage is
> very accurate then it becomes a way to analyse what is happening to
> tasks you don't own - such as say cryptographic functions in the web
> server...
>
> Otherwise, or with an owner check I see no real problem with the concept


So, is the following patch right ? I've added both the lock and the owner 
check...

Do you think it may be an interesting feature to be inserted in the kernel ?

Many thanks,

                 Claudio



diff --git a/kernel/sys.c b/kernel/sys.c
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1746,9 +1746,25 @@ 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);
+        if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN) {
+                struct task_struct* tsk;
+                struct rusage r;
+                read_lock(&tasklist_lock);
+                tsk = find_task_by_pid(who);
+                if (tsk == NULL) {
+                        read_unlock(&tasklist_lock);
+                        return -EINVAL;
+                }
+                if ((current->euid != tsk->euid) &&
+                (current->euid != tsk->uid)) {
+                        read_unlock(&tasklist_lock);
+                        return -EINVAL;
+                }
+                k_getrusage(tsk, RUSAGE_SELF, &r);
+                read_unlock(&tasklist_lock);
+                return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
+        } else
+                return getrusage(current, who, ru);
 }

 asmlinkage long sys_umask(int mask)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux