linux-stable/kernel/cgroup
Michal Koutný 6d26630912 cgroup: Prevent double killing of css when enabling threaded cgroup
commit 3bc0bb36fa upstream.

The test_cgcore_no_internal_process_constraint_on_threads selftest when
running with subsystem controlling noise triggers two warnings:

> [  597.443115] WARNING: CPU: 1 PID: 28167 at kernel/cgroup/cgroup.c:3131 cgroup_apply_control_enable+0xe0/0x3f0
> [  597.443413] WARNING: CPU: 1 PID: 28167 at kernel/cgroup/cgroup.c:3177 cgroup_apply_control_disable+0xa6/0x160

Both stem from a call to cgroup_type_write. The first warning was also
triggered by syzkaller.

When we're switching cgroup to threaded mode shortly after a subsystem
was disabled on it, we can see the respective subsystem css dying there.

The warning in cgroup_apply_control_enable is harmless in this case
since we're not adding new subsys anyway.
The warning in cgroup_apply_control_disable indicates an attempt to kill
css of recently disabled subsystem repeatedly.

The commit prevents these situations by making cgroup_type_write wait
for all dying csses to go away before re-applying subtree controls.
When at it, the locations of WARN_ON_ONCE calls are moved so that
warning is triggered only when we are about to misuse the dying css.

Reported-by: syzbot+5493b2a54d31d6aea629@syzkaller.appspotmail.com
Reported-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-02-05 14:43:39 +00:00
..
cgroup-internal.h cgroup/tracing: Move taking of spin lock out of trace event handlers 2018-07-11 10:48:47 -07:00
cgroup-v1.c cgroup/tracing: Move taking of spin lock out of trace event handlers 2018-07-11 10:48:47 -07:00
cgroup.c cgroup: Prevent double killing of css when enabling threaded cgroup 2020-02-05 14:43:39 +00:00
cpuset.c cpuset: restore sanity to cpuset_cpus_allowed_fallback() 2019-07-10 09:53:39 +02:00
debug.c debug cgroup: use task_css_set instead of rcu_dereference 2017-11-27 11:37:33 -08:00
freezer.c
Makefile cgroup: Rename kernel/cgroup/stat.c to kernel/cgroup/rstat.c 2018-04-26 14:29:04 -07:00
namespace.c
pids.c cgroup: pids: use atomic64_t for pids->limit 2019-12-17 20:34:56 +01:00
rdma.c rdmacg: Convert to use match_string() helper 2018-05-07 09:27:26 -07:00
rstat.c cgroup, rstat: Don't flush subtree root unless necessary 2019-04-05 22:33:06 +02:00