Skip to contentSkip to conversation

bpf: fix cgroup ref leak in cgroup_bpf_inherit on out-of-memory

PATCH Applied Andrii Nakryiko 3 participants 3 messages Mar 9, 2020 – Mar 10, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: fix cgroup ref leak in cgroup_bpf_inherit on out-of-memory

There is no compensating cgroup_bpf_put() for each ancestor cgroup in cgroup_bpf_inherit(). If compute_effective_progs returns error, those cgroups won't be freed ever. Fix it by putting them in cleanup code path.

Fixes e10360f815ca ("bpf: cgroup: prevent out-of-order release of cgroup bpf")
---
 kernel/bpf/cgroup.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/bpf/cgroup.c +3 -0
index 9a500fadbef5..5220a67392fc 100644
@@ -227,6 +227,9 @@ int cgroup_bpf_inherit(struct cgroup *cgrp)
 	for (i = 0; i < NR; i++)
 		bpf_prog_array_free(arrays[i]);
 
+	for (p = cgroup_parent(cgrp); p; p = cgroup_parent(p))
+		cgroup_bpf_put(p);
+
 	percpu_ref_exit(&cgrp->bpf.refcnt);
 
 	return -ENOMEM;
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Andrii Nakryiko

There is no compensating cgroup_bpf_put() for each ancestor cgroup in cgroup_bpf_inherit(). If compute_effective_progs returns error, those cgroups won't be freed ever. Fix it by putting them in cleanup code path.

Fixes e10360f815ca ("bpf: cgroup: prevent out-of-order release of cgroup bpf")

Thanks, Andrii!

#2 lore raw
In reply to Andrii Nakryiko
Quoted 7 lines · Andrii Nakryiko

There is no compensating cgroup_bpf_put() for each ancestor cgroup in cgroup_bpf_inherit(). If compute_effective_progs returns error, those cgroups won't be freed ever. Fix it by putting them in cleanup code path.

Fixes e10360f815ca ("bpf: cgroup: prevent out-of-order release of cgroup bpf")

Applied. Thanks