Skip to content

Commit 66f40b9

Browse files
Waiman-Longhtejun
authored andcommitted
cgroup/cpuset: Fix a memory leak in update_exclusive_cpumask()
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+
1 parent e326df5 commit 66f40b9

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

kernel/cgroup/cpuset.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,9 +2598,6 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
25982598
if (cpumask_equal(cs->exclusive_cpus, trialcs->exclusive_cpus))
25992599
return 0;
26002600

2601-
if (alloc_cpumasks(NULL, &tmp))
2602-
return -ENOMEM;
2603-
26042601
if (*buf)
26052602
compute_effective_exclusive_cpumask(trialcs, NULL);
26062603

@@ -2615,6 +2612,9 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs,
26152612
if (retval)
26162613
return retval;
26172614

2615+
if (alloc_cpumasks(NULL, &tmp))
2616+
return -ENOMEM;
2617+
26182618
if (old_prs) {
26192619
if (cpumask_empty(trialcs->effective_xcpus)) {
26202620
invalidate = true;

0 commit comments

Comments
 (0)