Commit 2bd1103
cgroup: always put cset in cgroup_css_set_put_fork
A successful call to cgroup_css_set_fork() will always have taken
a ref on kargs->cset (regardless of CLONE_INTO_CGROUP), so always
do a corresponding put in cgroup_css_set_put_fork().
Without this, a cset and its contained css structures will be
leaked for some fork failures. The following script reproduces
the leak for a fork failure due to exceeding pids.max in the
pids controller. A similar thing can happen if we jump to the
bad_fork_cancel_cgroup label in copy_process().
[ -z "$1" ] && echo "Usage $0 pids-root" && exit 1
PID_ROOT=$1
CGROUP=$PID_ROOT/foo
[ -e $CGROUP ] && rmdir -f $CGROUP
mkdir $CGROUP
echo 5 > $CGROUP/pids.max
echo $$ > $CGROUP/cgroup.procs
fork_bomb()
{
set -e
for i in $(seq 10); do
/bin/sleep 3600 &
done
}
(fork_bomb) &
wait
echo $$ > $PID_ROOT/cgroup.procs
kill $(cat $CGROUP/cgroup.procs)
rmdir $CGROUP
Fixes: ef2c41c ("clone3: allow spawning processes into cgroups")
Cc: stable@vger.kernel.org # v5.7+
Signed-off-by: John Sperbeck <jsperbeck@google.com>
Signed-off-by: Tejun Heo <tj@kernel.org>1 parent ab1de7e commit 2bd1103
1 file changed
Lines changed: 8 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6486 | 6486 | | |
6487 | 6487 | | |
6488 | 6488 | | |
| 6489 | + | |
| 6490 | + | |
| 6491 | + | |
6489 | 6492 | | |
6490 | 6493 | | |
6491 | | - | |
6492 | | - | |
6493 | | - | |
| 6494 | + | |
| 6495 | + | |
| 6496 | + | |
| 6497 | + | |
6494 | 6498 | | |
| 6499 | + | |
6495 | 6500 | | |
6496 | | - | |
6497 | | - | |
6498 | | - | |
6499 | | - | |
6500 | | - | |
6501 | | - | |
6502 | 6501 | | |
6503 | 6502 | | |
6504 | 6503 | | |
| |||
0 commit comments