]> git.baikalelectronics.ru Git - kernel.git/commit
netprio_cgroup: Fix unlimited memory leak of v2 cgroups
authorZefan Li <lizefan@huawei.com>
Sat, 9 May 2020 03:32:10 +0000 (11:32 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sun, 10 May 2020 03:59:21 +0000 (20:59 -0700)
commitdd17751a691cc1f39400a2394e6bb71cca28c4e0
tree9d671586e4a3fa487a2f084c0e1fc16d08bcfbd0
parent536c4ecae8284465cafe18b93cd3e6afd0fdfe28
netprio_cgroup: Fix unlimited memory leak of v2 cgroups

If systemd is configured to use hybrid mode which enables the use of
both cgroup v1 and v2, systemd will create new cgroup on both the default
root (v2) and netprio_cgroup hierarchy (v1) for a new session and attach
task to the two cgroups. If the task does some network thing then the v2
cgroup can never be freed after the session exited.

One of our machines ran into OOM due to this memory leak.

In the scenario described above when sk_alloc() is called
cgroup_sk_alloc() thought it's in v2 mode, so it stores
the cgroup pointer in sk->sk_cgrp_data and increments
the cgroup refcnt, but then sock_update_netprioidx()
thought it's in v1 mode, so it stores netprioidx value
in sk->sk_cgrp_data, so the cgroup refcnt will never be freed.

Currently we do the mode switch when someone writes to the ifpriomap
cgroup control file. The easiest fix is to also do the switch when
a task is attached to a new cgroup.

Fixes: 588b947267eb ("sock, cgroup: add sock->sk_cgroup")
Reported-by: Yang Yingliang <yangyingliang@huawei.com>
Tested-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Zefan Li <lizefan@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/netprio_cgroup.c