diff options
| author | Waiman Long <[email protected]> | 2024-02-28 00:58:01 +0000 |
|---|---|---|
| committer | Tejun Heo <[email protected]> | 2024-02-28 18:02:55 +0000 |
| commit | 66f40b926dd249f74334a22162c09e7ec1ec5b07 (patch) | |
| tree | 8798d3c7165c616318877aab239b685a6892e74c | |
| parent | Merge tag 'v6.8-p5' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/... (diff) | |
| download | kernel-66f40b926dd249f74334a22162c09e7ec1ec5b07.tar.gz kernel-66f40b926dd249f74334a22162c09e7ec1ec5b07.zip | |
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: e2ffe502ba45 ("cgroup/cpuset: Add cpuset.cpus.exclusive for v2")
Reported-and-tested-by: Mirsad Todorovac <[email protected]>
Closes: https://lore.kernel.org/lkml/[email protected]
Signed-off-by: Waiman Long <[email protected]>
Signed-off-by: Tejun Heo <[email protected]>
Cc: [email protected] # v6.7+
| -rw-r--r-- | kernel/cgroup/cpuset.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index ba36c073304a..7260f095802a 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2598,9 +2598,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); @@ -2615,6 +2612,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; |
