From: Oleg Nesterov <oleg@redhat.com>
To: Ben Blum <bblum@andrew.cmu.edu>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
fweisbec@gmail.com, neilb@suse.de, paul@paulmenage.org,
paulmck@linux.vnet.ibm.com
Subject: Re: + cgroups-more-safe-tasklist-locking-in-cgroup_attach_proc.patch added to -mm tree
Date: Thu, 8 Sep 2011 19:35:59 +0200 [thread overview]
Message-ID: <20110908173559.GA26492@redhat.com> (raw)
In-Reply-To: <20110907235931.GA22545@unix33.andrew.cmu.edu>
On 09/07, Ben Blum wrote:
>
> On Fri, Sep 02, 2011 at 05:55:34PM +0200, Oleg Nesterov wrote:
> > On 09/02, Ben Blum wrote:
> > >
> > > But I don't think the check becomes pointless? If a sub-thread execs
> > > right before read_lock(&tasklist_lock) (but after the find_task_by_vpid
> > > in attach_task_by_pid), that causes the case that the comment refers to.
> >
> > How so? The comment says:
> >
> > * a race with de_thread from another thread's exec() may strip
> > * us of our leadership, making while_each_thread unsafe
> >
> > This is not true.
>
> Sorry, the comment is unclear.
No, the comment is clear. In fact it was me who pointed out we can't
do while_each_thread() blindly. And now I am tried to confuse you ;)
So, sorry for noise, and thanks for correcting me. Somehow I forgot
this is not safe even under tasklist.
Partly I was confused because I was thinking about the patch I suggested,
if we use ->siglock we are safe. If lock_task_sighand(task) succeeds,
this task should be on list.
Anyway, I was wrong, sorry.
Oleg.
--- x/kernel/cgroup.c
+++ x/kernel/cgroup.c
@@ -2000,6 +2000,7 @@ int cgroup_attach_proc(struct cgroup *cg
/* threadgroup list cursor and array */
struct task_struct *tsk;
struct flex_array *group;
+ unsigned long flags;
/*
* we need to make sure we have css_sets for all the tasks we're
* going to move -before- we actually start moving them, so that in
@@ -2027,19 +2028,10 @@ int cgroup_attach_proc(struct cgroup *cg
goto out_free_group_list;
/* prevent changes to the threadgroup list while we take a snapshot. */
- rcu_read_lock();
- if (!thread_group_leader(leader)) {
- /*
- * a race with de_thread from another thread's exec() may strip
- * us of our leadership, making while_each_thread unsafe to use
- * on this task. if this happens, there is no choice but to
- * throw this task away and try again (from cgroup_procs_write);
- * this is "double-double-toil-and-trouble-check locking".
- */
- rcu_read_unlock();
- retval = -EAGAIN;
+ retval = -EAGAIN;
+ if (!lock_task_sighand(leader, &flags))
goto out_free_group_list;
- }
+
/* take a reference on each task in the group to go in the array. */
tsk = leader;
i = 0;
@@ -2055,9 +2047,9 @@ int cgroup_attach_proc(struct cgroup *cg
BUG_ON(retval != 0);
i++;
} while_each_thread(leader, tsk);
+ unlock_task_sighand(leader, &flags);
/* remember the number of threads in the array for later. */
group_size = i;
- rcu_read_unlock();
/*
* step 1: check that we can legitimately attach to the cgroup.
next prev parent reply other threads:[~2011-09-08 23:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-01 21:08 + cgroups-more-safe-tasklist-locking-in-cgroup_attach_proc.patch added to -mm tree akpm
2011-09-02 12:37 ` Oleg Nesterov
2011-09-02 14:00 ` Oleg Nesterov
2011-09-02 14:15 ` Ben Blum
2011-09-02 15:55 ` Oleg Nesterov
2011-09-07 23:59 ` Ben Blum
2011-09-08 17:35 ` Oleg Nesterov [this message]
2011-09-08 18:58 ` Ben Blum
2011-09-08 21:31 ` Oleg Nesterov
2011-09-09 2:11 ` Ben Blum
2011-09-09 16:41 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110908173559.GA26492@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bblum@andrew.cmu.edu \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@suse.de \
--cc=paul@paulmenage.org \
--cc=paulmck@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.