bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: fix cgroup ref leak in cgroup_bpf_inherit on out-of-memory
@ 2020-03-09 22:40 Andrii Nakryiko
  2020-03-09 23:18 ` Roman Gushchin
  2020-03-10  3:02 ` Alexei Starovoitov
  0 siblings, 2 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-03-09 22:40 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel, guro
  Cc: andrii.nakryiko, kernel-team, 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")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 kernel/bpf/cgroup.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 9a500fadbef5..5220a67392fc 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -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;
-- 
2.17.1


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

* Re: [PATCH bpf] bpf: fix cgroup ref leak in cgroup_bpf_inherit on out-of-memory
  2020-03-09 22:40 [PATCH bpf] bpf: fix cgroup ref leak in cgroup_bpf_inherit on out-of-memory Andrii Nakryiko
@ 2020-03-09 23:18 ` Roman Gushchin
  2020-03-10  3:02 ` Alexei Starovoitov
  1 sibling, 0 replies; 3+ messages in thread
From: Roman Gushchin @ 2020-03-09 23:18 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, netdev, ast, daniel, andrii.nakryiko, kernel-team

On Mon, Mar 09, 2020 at 03:40:17PM -0700, Andrii Nakryiko wrote:
> 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")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Acked-by: Roman Gushchin <guro@fb.com>

Thanks, Andrii!

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

* Re: [PATCH bpf] bpf: fix cgroup ref leak in cgroup_bpf_inherit on out-of-memory
  2020-03-09 22:40 [PATCH bpf] bpf: fix cgroup ref leak in cgroup_bpf_inherit on out-of-memory Andrii Nakryiko
  2020-03-09 23:18 ` Roman Gushchin
@ 2020-03-10  3:02 ` Alexei Starovoitov
  1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2020-03-10  3:02 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
	Roman Gushchin, Andrii Nakryiko, Kernel Team

On Mon, Mar 9, 2020 at 3:41 PM Andrii Nakryiko <andriin@fb.com> wrote:
>
> 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")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Applied. Thanks

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

end of thread, other threads:[~2020-03-10  3:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 22:40 [PATCH bpf] bpf: fix cgroup ref leak in cgroup_bpf_inherit on out-of-memory Andrii Nakryiko
2020-03-09 23:18 ` Roman Gushchin
2020-03-10  3:02 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).