[Devel] [PATCH rh7 2/6] cgroup: make cgroup_kernel_attach safe against cgroup removal

Vladimir Davydov vdavydov at parallels.com
Sun Jun 7 04:57:14 PDT 2015


Currently, this function is only safe to call if the cgroup is pinned
(e.g. was open using cgroup_kernel_open). In a following patch, I need
to be able to pass a cgroup that could have already been removed there,
so make it safe against dead cgroups.

Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
 kernel/cgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index cca5b961ef37..c5d7362afed8 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -5625,7 +5625,8 @@ int cgroup_kernel_attach(struct cgroup *cgrp, struct task_struct *tsk)
 {
 	int ret;
 
-	mutex_lock(&cgroup_mutex);
+	if (!cgroup_lock_live_group(cgrp))
+		return -ENODEV;
 	ret = cgroup_attach_task(cgrp, tsk, true);
 	mutex_unlock(&cgroup_mutex);
 	return ret;
-- 
2.1.4




More information about the Devel mailing list