Commit a5801758 authored by Chen Ridong's avatar Chen Ridong
Browse files

cgroup/bpf: only cgroup v2 can be attached by bpf programs

stable inclusion
from stable-v6.6.64
commit 9e67b054198f220b528238ecc6fd812d2baca112
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBA6RL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9e67b054198f220b528238ecc6fd812d2baca112

--------------------------------

[ Upstream commit 2190df6c91373fdec6db9fc07e427084f232f57e ]

Only cgroup v2 can be attached by bpf programs, so this patch introduces
that cgroup_bpf_inherit and cgroup_bpf_offline can only be called in
cgroup v2, and this can fix the memleak mentioned by commit 04f8ef56
("cgroup: Fix memory leak caused by missing cgroup_bpf_offline"), which
has been reverted.

Fixes: 2b0d3d3e ("percpu_ref: reduce memory footprint of percpu_ref in fast path")
Fixes: 4bfc0bb2 ("bpf: decouple the lifetime of cgroup_bpf from cgroup itself")
Link: https://lore.kernel.org/cgroups/aka2hk5jsel5zomucpwlxsej6iwnfw4qu5jkrmjhyfhesjlfdw@46zxhg5bdnr7/


Signed-off-by: default avatarChen Ridong <chenridong@huawei.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
parent c76f0a33
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -2113,8 +2113,10 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
	if (ret)
		goto exit_stats;

	if (root == &cgrp_dfl_root) {
		ret = cgroup_bpf_inherit(root_cgrp);
		WARN_ON_ONCE(ret);
	}

	trace_cgroup_setup_root(root);

@@ -5725,9 +5727,11 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
	if (ret)
		goto out_kernfs_remove;

	if (cgrp->root == &cgrp_dfl_root) {
		ret = cgroup_bpf_inherit(cgrp);
		if (ret)
			goto out_psi_free;
	}

	/*
	 * New cgroup inherits effective freeze counter, and
@@ -6055,6 +6059,7 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)

	cgroup1_check_for_release(parent);

	if (cgrp->root == &cgrp_dfl_root)
		cgroup_bpf_offline(cgrp);

	/* put the base reference */