All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netprio_cgroup: Fix unlimited memory leak of v2 cgroup
@ 2020-05-09  3:19 ` Zefan Li
  0 siblings, 0 replies; 12+ messages in thread
From: Zefan Li @ 2020-05-09  3:19 UTC (permalink / raw)
  To: Tejun Heo, David Miller
  Cc: yangyingliang, Kefeng Wang, huawei.libin, guofan5, linux-kernel,
	cgroups, Linux Kernel Network Developers

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: bd1060a1d671("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>
---
 net/core/netprio_cgroup.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index b905747..2397866 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -240,6 +240,8 @@ static void net_prio_attach(struct cgroup_taskset *tset)
 	struct task_struct *p;
 	struct cgroup_subsys_state *css;
 
+	cgroup_sk_alloc_disable();
+
 	cgroup_taskset_for_each(p, css, tset) {
 		void *v = (void *)(unsigned long)css->cgroup->id;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-05-22  3:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09  3:19 [PATCH] netprio_cgroup: Fix unlimited memory leak of v2 cgroup Zefan Li
2020-05-09  3:19 ` Zefan Li
2020-05-09  3:32 ` [PATCH v2] netprio_cgroup: Fix unlimited memory leak of v2 cgroups Zefan Li
2020-05-09  3:32   ` Zefan Li
2020-05-09  5:58   ` Jakub Kicinski
2020-05-09  5:58     ` Jakub Kicinski
2020-05-10  4:02     ` Jakub Kicinski
2020-05-10  4:02       ` Jakub Kicinski
2020-05-21 21:14       ` John Fastabend
2020-05-22  3:26         ` Zefan Li
2020-05-22  3:26           ` Zefan Li
2020-05-09 22:57   ` Tejun Heo

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.