Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1723296 > unrolled thread

[PATCH] cgroup: Fix potential race between cgroup_exit and cpuset_attach

Started byNeeraj Upadhyay <neeraju@codeaurora.org>
First post2017-08-30 15:00 +0200
Last post2017-08-31 03:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] cgroup: Fix potential race between cgroup_exit and cpuset_attach Neeraj Upadhyay <neeraju@codeaurora.org> - 2017-08-30 15:00 +0200
    Re: [PATCH] cgroup: Fix potential race between cgroup_exit and  cpuset_attach Tejun Heo <tj@kernel.org> - 2017-08-31 03:20 +0200

#1723296 — [PATCH] cgroup: Fix potential race between cgroup_exit and cpuset_attach

FromNeeraj Upadhyay <neeraju@codeaurora.org>
Date2017-08-30 15:00 +0200
Subject[PATCH] cgroup: Fix potential race between cgroup_exit and cpuset_attach
Message-ID<ukaL9-8rd-61@gated-at.bofh.it>
There is a potential race between cgroup_exit() and the taskset
migration path. This race happens when all tasks associated
with the cg_list entries in mg_tasks, detach themselves
before the tasks can be attached to the destination cpuset in
cpuset_attach(). Below is the sequence where race is observed:

cpuset_hotplug_workfn()
  cgroup_transfer_tasks()
    cgroup_migrate()
      cgroup_migrate_execute()
          <TASK EXIT>
          list_del_init(&task->cg_list)
        cpuset_attach()
          cgroup_taskset_first(tset, &css) // css is not set
          guarantee_online_mems(cs, ...) // data abort

Fix this by adding a checking to verify that css is set from
cgroup_taskset_first(), before proceeding.

Signed-off-by: Neeraj Upadhyay <neeraju@codeaurora.org>
---
Hi,

We observed this issue for cgroup code corresponding to stable
v4.4.85 snapshot 3144d81 ("cgroup, kthread: close race window where
new kthreads can be migrated to non-root cgroups"). Can you please
tell us, if there are any patches in latest code, which
fixes these issue?

 kernel/cgroup/cpuset.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 87a1213..7e245f26 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1510,11 +1510,17 @@ static void cpuset_attach(struct cgroup_taskset *tset)
 	static nodemask_t cpuset_attach_nodemask_to;
 	struct task_struct *task;
 	struct task_struct *leader;
-	struct cgroup_subsys_state *css;
+	struct cgroup_subsys_state *css = NULL;
 	struct cpuset *cs;
 	struct cpuset *oldcs = cpuset_attach_old_cs;
 
 	cgroup_taskset_first(tset, &css);
+	/* If all mg_tasks detached (from cgroup_exit())
+	 * before we started scanning the mg_tasks in
+	 * cgroup_taskset_next().
+	 */
+	if (css == NULL)
+		return;
 	cs = css_cs(css);
 
 	mutex_lock(&cpuset_mutex);
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation

[toc] | [next] | [standalone]


#1723763 — Re: [PATCH] cgroup: Fix potential race between cgroup_exit and cpuset_attach

FromTejun Heo <tj@kernel.org>
Date2017-08-31 03:20 +0200
SubjectRe: [PATCH] cgroup: Fix potential race between cgroup_exit and cpuset_attach
Message-ID<ukmjg-7nc-3@gated-at.bofh.it>
In reply to#1723296
Hello,

On Wed, Aug 30, 2017 at 06:23:50PM +0530, Neeraj Upadhyay wrote:
> cpuset_hotplug_workfn()
>   cgroup_transfer_tasks()
>     cgroup_migrate()
>       cgroup_migrate_execute()
>           <TASK EXIT>
>           list_del_init(&task->cg_list)
>         cpuset_attach()
>           cgroup_taskset_first(tset, &css) // css is not set
>           guarantee_online_mems(cs, ...) // data abort

I don't think this can happen anymore.  We lock out task exits during
migration and don't call migration callbacks if there's no tasks to
migrate.

Thanks.

-- 
tejun

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web