public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Attaching PID 0 to a cgroup
@ 2008-07-01  9:45 Dhaval Giani
  2008-07-01  9:47 ` Dhaval Giani
  0 siblings, 1 reply; 10+ messages in thread
From: Dhaval Giani @ 2008-07-01  9:45 UTC (permalink / raw)
  To: Paul Menage; +Cc: Andrew Morton, Balbir Singh, Sudhir Kumar, lkml, containers

Hi Paul,

Attaching PID 0 to a cgroup caused the current task to be attached to
the cgroup. Looking at the code,

        if (pid) {
                rcu_read_lock();
                tsk = find_task_by_vpid(pid);
                if (!tsk || tsk->flags & PF_EXITING) {
                        rcu_read_unlock();
                        return -ESRCH;
                }
                get_task_struct(tsk);
                rcu_read_unlock();

                if ((current->euid) && (current->euid != tsk->uid)
                    && (current->euid != tsk->suid)) {
                        put_task_struct(tsk);
                        return -EACCES;
                }
        } else {
                tsk = current;
                get_task_struct(tsk);
        }

I was wondering, why this was done. It seems to be unexpected behavior.
Wouldn't something like the following be a better response? (I've used
EINVAL, but I can change it to ESRCH if that is better.)

---
cgroups: Don't allow PID 0 to be attached to a group

Currently when one trys to attach PID 0 to a cgroup, it attaches
the current task. That is not expected behavior. It should return
an error instead.

Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>

Index: linux-2.6/kernel/cgroup.c
===================================================================
--- linux-2.6.orig/kernel/cgroup.c
+++ linux-2.6/kernel/cgroup.c
@@ -1309,8 +1309,7 @@ static int attach_task_by_pid(struct cgr
 			return -EACCES;
 		}
 	} else {
-		tsk = current;
-		get_task_struct(tsk);
+			return -EINVAL;
 	}
 
 	ret = cgroup_attach_task(cgrp, tsk);
-- 
regards,
Dhaval

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

end of thread, other threads:[~2008-07-03 22:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-01  9:45 Attaching PID 0 to a cgroup Dhaval Giani
2008-07-01  9:47 ` Dhaval Giani
2008-07-01 10:28   ` Li Zefan
2008-07-01 10:51     ` Dhaval Giani
2008-07-01 18:54     ` Paul Jackson
2008-07-01 19:01     ` Paul Menage
2008-07-01 21:48     ` Andrea Righi
2008-07-01 21:54       ` Dhaval Giani
2008-07-03 21:59         ` Matt Helsley
2008-07-03 22:03           ` Paul Menage

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