cgroups: fix pid namespace bug

The bug was introduced by commit cc31edceee
("cgroups: convert tasks file to use a seq_file with shared pid array").

We cache a pid array for all threads that are opening the same "tasks"
file, but the pids in the array are always from the namespace of the
last process that opened the file, so all other threads will read pids
from that namespace instead of their own namespaces.

To fix it, we maintain a list of pid arrays, which is keyed by pid_ns.
The list will be of length 1 at most time.

Reported-by: Paul Menage <menage@google.com>
Idea-by: Paul Menage <menage@google.com>
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Reviewed-by: Serge Hallyn <serue@us.ibm.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Li Zefan
2009-07-29 15:04:04 -07:00
committed by Linus Torvalds
parent b317c83321
commit 096b7fe012
2 changed files with 76 additions and 31 deletions

View File

@@ -179,14 +179,11 @@ struct cgroup {
*/
struct list_head release_list;
/* pids_mutex protects the fields below */
/* pids_mutex protects pids_list and cached pid arrays. */
struct rw_semaphore pids_mutex;
/* Array of process ids in the cgroup */
pid_t *tasks_pids;
/* How many files are using the current tasks_pids array */
int pids_use_count;
/* Length of the current tasks_pids array */
int pids_length;
/* Linked list of struct cgroup_pids */
struct list_head pids_list;
/* For RCU-protected deletion */
struct rcu_head rcu_head;