Skip to content

Commit

Permalink
cgroup/cpuset: Fix a memory leak in update_exclusive_cpumask()
Browse files Browse the repository at this point in the history
commit 66f40b9 upstream.

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: e2ffe50 ("cgroup/cpuset: Add cpuset.cpus.exclusive for v2")
Reported-and-tested-by: Mirsad Todorovac <mirsad.todorovac@alu.hr>
Closes: https://lore.kernel.org/lkml/14915689-27a3-4cd8-80d2-9c30d0c768b6@alu.unizg.hr
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: stable@vger.kernel.org # v6.7+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Waiman Long authored and gregkh committed Apr 3, 2024
1 parent 2972735 commit 3b033f7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kernel/cgroup/cpuset.c
Expand Up @@ -2502,9 +2502,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);

Expand All @@ -2519,6 +2516,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;
Expand Down

0 comments on commit 3b033f7

Please sign in to comment.