Attaching PID 0 to a cgroup

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Dhaval Giani
Date: Tuesday, July 1, 2008 - 2:45 am

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
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Attaching PID 0 to a cgroup, Dhaval Giani, (Tue Jul 1, 2:45 am)
Re: Attaching PID 0 to a cgroup, Dhaval Giani, (Tue Jul 1, 2:47 am)
Re: Attaching PID 0 to a cgroup, Li Zefan, (Tue Jul 1, 3:28 am)
Re: Attaching PID 0 to a cgroup, Dhaval Giani, (Tue Jul 1, 3:51 am)
Re: Attaching PID 0 to a cgroup, Paul Jackson, (Tue Jul 1, 11:54 am)
Re: Attaching PID 0 to a cgroup, Paul Menage, (Tue Jul 1, 12:01 pm)
Re: Attaching PID 0 to a cgroup, Andrea Righi, (Tue Jul 1, 2:48 pm)
Re: Attaching PID 0 to a cgroup, Dhaval Giani, (Tue Jul 1, 2:54 pm)
Re: Attaching PID 0 to a cgroup, Matt Helsley, (Thu Jul 3, 2:59 pm)
Re: Attaching PID 0 to a cgroup, Paul Menage, (Thu Jul 3, 3:03 pm)