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


Groups > linux.kernel > #1359169

Re: [BUG] sched: leaf_cfs_rq_list use after free

From Tejun Heo <tj@kernel.org>
Newsgroups linux.kernel
Subject Re: [BUG] sched: leaf_cfs_rq_list use after free
Date 2016-03-16 18:00 +0100
Message-ID <rdmXE-36t-3@gated-at.bofh.it> (permalink)
References <rbOv0-40C-3@gated-at.bofh.it> <rcyRc-35C-11@gated-at.bofh.it> <rcztU-3yx-27@gated-at.bofh.it> <rdkCu-1FX-3@gated-at.bofh.it> <rdlyy-2jP-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Hello, Peter.

On Wed, Mar 16, 2016 at 04:22:45PM +0100, Peter Zijlstra wrote:
> > css_online()
> > 
> > 	The css is now guaranteed to be visible for css_for_each*()
> > 	iterations.  This distinction exists because some controllers
> > 	need to propagate state changes downwards requiring a new css
> > 	to become visible before it inherits the current state from
> > 	the parent.  Conversely, there's no reason to use this
> > 	callback if there's no such requirement.
> > 
> > 	Ex: Freezer which propagates the target state downwards and
> > 	needs a new child to inherit the current state while
> > 	iteratable.
> 
> So it looks like sched uses css_online() for no particular reason
> either, I've moved all that into css_alloc().

The parings are alloc <-> free, and online <-> offline,released, so if
you do some part of shutdown in either offline or released, it
probably makes sense to the counterpart of init in online.

> None of that speaks of where Zombies live, am I to infer that Zombies
> pass css_offline() but stall css_released() ?

Yeap, zombies may remain attached to the css before css_released().

> I don't particularly care about iterating css bits, but I do need my
> parent group to still exist, this is now also guaranteed for
> css_release(), right? The above documentation also doesn't mention this;

Yeah, if you do your custom rcu protected data structures which needs
to be accessible after offline, the rules would be the same as
requiring css iteration in the same way, so css_released() would be
the right callback to use.

> in particular I require that css_release() for any group is not called
> before the css_release() of any child group.

That is guaranteed now.

>  static void cpu_cgroup_css_free(struct cgroup_subsys_state *css)
>  {
>  	struct task_group *tg = css_tg(css);
>  
> -	sched_destroy_group(tg);
> -}
> -
> -static void cpu_cgroup_css_offline(struct cgroup_subsys_state *css)
> -{
> -	struct task_group *tg = css_tg(css);
> -
> -	sched_offline_group(tg);
> +	/*
> +	 * Relies on the RCU grace period between css_released() and this.
> +	 */
> +	sched_free_group(tg);
>  }

Hmmm... I don't think it'd be safe to merge the two ops.  Nothing
guarantees that the RCU callback of cpu controller is called after the
cgroup core one and cgroup core one would do use-after-free.  Just
changing offline to released should do.

Thanks.

-- 
tejun

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [BUG] sched: leaf_cfs_rq_list use after free Kazuki Yamaguchi <k@rhe.jp> - 2016-03-12 11:00 +0100
  Re: [BUG] sched: leaf_cfs_rq_list use after free Peter Zijlstra <peterz@infradead.org> - 2016-03-12 15:00 +0100
  Re: [BUG] sched: leaf_cfs_rq_list use after free Peter Zijlstra <peterz@infradead.org> - 2016-03-14 12:30 +0100
    Re: [BUG] sched: leaf_cfs_rq_list use after free Peter Zijlstra <peterz@infradead.org> - 2016-03-14 13:10 +0100
      Re: [BUG] sched: leaf_cfs_rq_list use after free Tejun Heo <tj@kernel.org> - 2016-03-16 15:30 +0100
        Re: [BUG] sched: leaf_cfs_rq_list use after free Tejun Heo <tj@kernel.org> - 2016-03-16 15:50 +0100
        Re: [BUG] sched: leaf_cfs_rq_list use after free Peter Zijlstra <peterz@infradead.org> - 2016-03-16 16:30 +0100
          Re: [BUG] sched: leaf_cfs_rq_list use after free Tejun Heo <tj@kernel.org> - 2016-03-16 18:00 +0100
            Re: [BUG] sched: leaf_cfs_rq_list use after free Peter Zijlstra <peterz@infradead.org> - 2016-03-16 18:10 +0100
              Re: [BUG] sched: leaf_cfs_rq_list use after free Tejun Heo <tj@kernel.org> - 2016-03-16 18:50 +0100
          Re: [BUG] sched: leaf_cfs_rq_list use after free Niklas Cassel <niklas.cassel@axis.com> - 2016-03-17 09:30 +0100

csiph-web