Skip to contentSkip to conversation

x86/resctrl: Fix potential memory leak

PATCH Superseded Shakeel Butt 3 participants 5 messages Dec 19, 2019 – Dec 20, 2019

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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. Fix that.

Fixes 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG")
---
 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
#2 lore raw
In reply to Shakeel Butt

Hi Shakeel,

Quoted 2 lines · Shakeel Butt

The set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. Fix that.

I think it would be valuable to those considering whether they need to backport to know that RDT_RESOURCE_L3 and RDT_RESOURCE_L2 are currently the only possible levels with which this function is called. It is thus not currently possible for this leak to occur. Indeed a valuable safety to add in case this code may change in the future. Thank you very much.

Quoted 14 lines
Fixes 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG")
---
 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
@@ -1748,8 +1748,10 @@ static int set_cache_qos_cfg(int level, bool enable)
 		update = l3_qos_cfg_update;

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

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -1
 	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) {

Reinette

#3 lore raw
Quoted 4 lines · Reinette Chatre

Hi Shakeel,

On 12/19/2019 2:38 PM, Shakeel Butt wrote:

Quoted 9 lines
Quoted 2 lines

The set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. Fix that.

I think it would be valuable to those considering whether they need to backport to know that RDT_RESOURCE_L3 and RDT_RESOURCE_L2 are currently the only possible levels with which this function is called. It is thus not currently possible for this leak to occur. Indeed a valuable safety to add in case this code may change in the future. Thank you very much.

Do you want me to add that info the commit and resend the v2 of the patch?

maintainer
#4 lore raw

Hi Shakeel,

Quoted 6 lines · Shakeel Butt
Quoted 4 lines · Reinette Chatre
Quoted 2 lines · Shakeel Butt

The set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. Fix that.

Quoted 9 lines
Quoted 6 lines

I think it would be valuable to those considering whether they need to backport to know that RDT_RESOURCE_L3 and RDT_RESOURCE_L2 are currently the only possible levels with which this function is called. It is thus not currently possible for this leak to occur. Indeed a valuable safety to add in case this code may change in the future. Thank you very much.

Do you want me to add that info the commit and resend the v2 of the patch?

Yes please.

Thank you very much

Reinette