From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleg Nesterov Subject: Re: Possible race between cgroup_attach_proc and de_thread, and questionable code in de_thread. Date: Sun, 14 Aug 2011 19:45:16 +0200 Message-ID: <20110814174516.GB2381__678.053338970308$1313344126$gmane$org@redhat.com> References: <20110727171101.5e32d8eb@notabene.brown> <20110727150710.GB5242@unix33.andrew.cmu.edu> <20110727234235.GA2318@linux.vnet.ibm.com> <20110728110813.7ff84b13@notabene.brown> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20110728110813.7ff84b13-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: NeilBrown Cc: Ben Blum , containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , Paul Menage , paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org List-Id: containers.vger.kernel.org On 07/28, NeilBrown wrote: > > +/* Thread group leader can change, so stop loop when we see one > + * even if it isn't 'g' */ > #define while_each_thread(g, t) \ > - while ((t = next_thread(t)) != g) > + while ((t = next_thread(t)) != g && !thread_group_leader(t)) This assumes that while_each_thread(g, t) always uses g == group_leader. > @@ -70,8 +70,13 @@ static void __unhash_process(struct task_struct *p, bool group_dead) > list_del_rcu(&p->tasks); > list_del_init(&p->sibling); > __this_cpu_dec(process_counts); > - } > - list_del_rcu(&p->thread_group); > + } else > + /* only remove members from the thread group. > + * The thread group leader must stay so that > + * while_each_thread() uses can see the end of > + * the list and stop. > + */ > + list_del_rcu(&p->thread_group); Hmm... this looks obvously wrong. This leaves the dead thread on the list. Oleg.