[patch 1/2] cpusets: disallow attaching kthreadd

From: David Rientjes
Date: Thu Apr 05 2012 - 03:14:57 EST


From: Mike Galbraith <efault@xxxxxx>

A worker thread spawned by kthreadd may acquire PF_THREAD_BOUND and never
be able to leave a cpuset, rending the cpuset immortal. Save the user
some unexpected trouble, just say no.

Acked-by: Paul Menage <paul@xxxxxxxxxxxxxx>
Signed-off-by: Mike Galbraith <efault@xxxxxx>
Signed-off-by: David Rientjes <rientjes@xxxxxxxxxx>
---
kernel/cpuset.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -53,6 +53,7 @@
#include <linux/time.h>
#include <linux/backing-dev.h>
#include <linux/sort.h>
+#include <linux/kthread.h>

#include <asm/uaccess.h>
#include <linux/atomic.h>
@@ -1389,9 +1390,11 @@ static int cpuset_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
* unnecessary. Thus, cpusets are not applicable for such
* threads. This prevents checking for success of
* set_cpus_allowed_ptr() on all attached tasks before
- * cpus_allowed may be changed.
+ * cpus_allowed may be changed. We also disallow attaching
+ * kthreadd to prevent a child from becoming trapped should it
+ * later acquire PF_THREAD_BOUND.
*/
- if (task->flags & PF_THREAD_BOUND)
+ if (task->flags & PF_THREAD_BOUND || task == kthreadd_task)
return -EINVAL;
if ((ret = security_task_setscheduler(task)))
return ret;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/