Skip to contentSkip to conversation

x86/resctrl: Fix potential memory leak

PATCH Superseded Shakeel Butt 3 participants 4 messages Dec 20, 2019 – Jan 2, 2020

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/resctrl: Fix potential memory leak

The set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. However at the moment, this function is called with only valid levels but to make it more robust and future proof, we should be handling the error path gracefully.

Fixes 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG")

---
Changes since v1:
- Updated the commit message

 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -1
index 2e3b06d6bbc6..a0c279c7f4b9 100644
@@ -1748,8 +1748,10 @@ static int set_cache_qos_cfg(int level, bool enable)
 		update = l3_qos_cfg_update;
 	else if (level == RDT_RESOURCE_L2)
 		update = l2_qos_cfg_update;
-	else
+	else {
+		free_cpumask_var(cpu_mask);
 		return -EINVAL;
+	}
 
 	r_l = &rdt_resources_all[level];
 	list_for_each_entry(d, &r_l->domains, list) {
Signature · 1 line
2.24.1.735.g03f4e72817-goog
maintainer Acked-by on v2 1/1
#1 lore raw

Hi Shakeel,

Quoted 11 lines · Shakeel Butt

The set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. However at the moment, this function is called with only valid levels but to make it more robust and future proof, we should be handling the error path gracefully.

Fixes 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG")

---
Changes since v1:
- Updated the commit message

Thank you.

Reinette

maintainer
#2 lore raw
In reply to Shakeel Butt
Quoted 21 lines · Shakeel Butt

The set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. However at the moment, this function is called with only valid levels but to make it more robust and future proof, we should be handling the error path gracefully.

Fixes 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG")

---
Changes since v1:
- Updated the commit message

 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 2e3b06d6bbc6..a0c279c7f4b9 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int set_cache_qos_cfg(int level, bool enable) · line 1754

Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -1
@@ -1748,8 +1748,10 @@ static int set_cache_qos_cfg(int level, bool enable)
 		update = l3_qos_cfg_update;
 	else if (level == RDT_RESOURCE_L2)
 		update = l2_qos_cfg_update;
-	else
+	else {
+		free_cpumask_var(cpu_mask);
 		return -EINVAL;
+	}

And why can't the level check happen first and the allocation second, thus needing to allocate the cpu mask only when the level is valid?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw
Quoted 18 lines · Borislav Petkov
Quoted 16 lines · Shakeel Butt

The set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. However at the moment, this function is called with only valid levels but to make it more robust and future proof, we should be handling the error path gracefully.

Fixes 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG")

---
Changes since v1:
- Updated the commit message

 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 17 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int set_cache_qos_cfg(int level, bool enable) · line 1754

Quoted 13 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -1
index 2e3b06d6bbc6..a0c279c7f4b9 100644
@@ -1748,8 +1748,10 @@ static int set_cache_qos_cfg(int level, bool enable)
              update = l3_qos_cfg_update;
      else if (level == RDT_RESOURCE_L2)
              update = l2_qos_cfg_update;
-     else
+     else {
+             free_cpumask_var(cpu_mask);
              return -EINVAL;
+     }

And why can't the level check happen first and the allocation second, thus needing to allocate the cpu mask only when the level is valid?

We definitely can. Will send the v3 patch.

Shakeel