Commit 61f5006b authored by Waiman Long's avatar Waiman Long Committed by Chen Ridong
Browse files

cgroup/cpuset: Fix a memory leak in update_exclusive_cpumask()

mainline inclusion
from mainline-v6.8-rc1
commit 66f40b926dd249f74334a22162c09e7ec1ec5b07
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I93ZFV
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=66f40b926dd249f74334a22162c09e7ec1ec5b07



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

Fix a possible memory leak in update_exclusive_cpumask() by moving the
alloc_cpumasks() down after the validate_change() check which can fail
and still before the temporary cpumasks are needed.

Fixes: e2ffe502ba45 ("cgroup/cpuset: Add cpuset.cpus.exclusive for v2")
Reported-and-tested-by: default avatarMirsad Todorovac <mirsad.todorovac@alu.hr>
Closes: https://lore.kernel.org/lkml/14915689-27a3-4cd8-80d2-9c30d0c768b6@alu.unizg.hr


Signed-off-by: default avatarWaiman Long <longman@redhat.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: stable@vger.kernel.org # v6.7+
Signed-off-by: default avatarChen Ridong <chenridong@huawei.com>
parent 1b6baaba
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -2609,9 +2609,6 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
	if (cpumask_equal(cs->exclusive_cpus, trialcs->exclusive_cpus))
		return 0;

	if (alloc_cpumasks(NULL, &tmp))
		return -ENOMEM;

	if (*buf)
		compute_effective_exclusive_cpumask(trialcs, NULL);

@@ -2626,6 +2623,9 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
	if (retval)
		return retval;

	if (alloc_cpumasks(NULL, &tmp))
		return -ENOMEM;

	if (old_prs) {
		if (cpumask_empty(trialcs->effective_xcpus)) {
			invalidate = true;