Skip to contentSkip to conversation

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

PATCH Applied Waiman Long 3 participants 4 messages Feb 28, 2024

Subsystems (2)
lore
Share & tools
lore

Waiman Long

author maintainer
#0 lore raw

PATCH 1/1 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")
---
 kernel/cgroup/cpuset.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/cgroup/cpuset.c +3 -3
index ba36c073304a..7260f095802a 100644
@@ -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;
Signature · 1 line
2.39.3
Tested-by on v1 1/1
#1 lore raw

Hi,

Quoted 27 lines · Waiman Long

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")
---
  kernel/cgroup/cpuset.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
kernel/cgroup/cpuset.c +0 -3
index ba36c073304a..7260f095802a 100644
@@ -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);
 

kernel/cgroup/cpuset.c static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs, · line 2620

Quoted 9 lines
kernel/cgroup/cpuset.c +3 -0
@@ -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;Great work at such a short notice! (I failed to find the culprit myself.)

The leak is no longer present.

Please feel free to add:

Best regards, Mirsad Todorovac

P.S. APologies for the previous email accidentally sent as HTML.

author maintainer
#2 lore raw
Quoted 40 lines · Mirsad Todorovac

Hi,

Quoted 26 lines · Waiman Long

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")

---
  kernel/cgroup/cpuset.c | 6 +++---

  1 file changed, 3 insertions(+), 3 deletions(-)
kernel/cgroup/cpuset.c +0 -2
index ba36c073304a..7260f095802a 100644
@@ -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,

Quoted 8 lines

      if (retval)
          return retval;
  +    if (alloc_cpumasks(NULL, &tmp))
+        return -ENOMEM;
+
      if (old_prs) {
          if (cpumask_empty(trialcs->effective_xcpus)) {
              invalidate = true;Great work at such a short notice! (I failed to find the culprit myself.)

The leak is no longer present.

Quoted 7 lines

Please feel free to add:

Best regards, Mirsad Todorovac

P.S. APologies for the previous email accidentally sent as HTML.

Thanks for verifying the fix.

Cheers,
Longman

maintainer Applied
#3 lore raw
In reply to Waiman Long

Hello,

Quoted 8 lines · Waiman Long

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")

Applied to cgroup/for-6.8-fixes with stable cc'd. Depending on when v6.9 gets cut, this might go in together with for-6.9 during rc1.

Thanks.

Signature · 1 line
tejun