Patch "x86/resctrl: Avoid overflow in MB settings in bw_validate()" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    x86/resctrl: Avoid overflow in MB settings in bw_validate()

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     x86-resctrl-avoid-overflow-in-mb-settings-in-bw_vali.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 8883d7371e8312733c30b4559a9683d5d83bfab6
Author: Martin Kletzander <nert.pinx@xxxxxxxxx>
Date:   Tue Oct 1 13:43:56 2024 +0200

    x86/resctrl: Avoid overflow in MB settings in bw_validate()
    
    [ Upstream commit 2b5648416e47933939dc310c4ea1e29404f35630 ]
    
    The resctrl schemata file supports specifying memory bandwidth associated with
    the Memory Bandwidth Allocation (MBA) feature via a percentage (this is the
    default) or bandwidth in MiBps (when resctrl is mounted with the "mba_MBps"
    option).
    
    The allowed range for the bandwidth percentage is from
    /sys/fs/resctrl/info/MB/min_bandwidth to 100, using a granularity of
    /sys/fs/resctrl/info/MB/bandwidth_gran. The supported range for the MiBps
    bandwidth is 0 to U32_MAX.
    
    There are two issues with parsing of MiBps memory bandwidth:
    
    * The user provided MiBps is mistakenly rounded up to the granularity
      that is unique to percentage input.
    
    * The user provided MiBps is parsed using unsigned long (thus accepting
      values up to ULONG_MAX), and then assigned to u32 that could result in
      overflow.
    
    Do not round up the MiBps value and parse user provided bandwidth as the u32
    it is intended to be. Use the appropriate kstrtou32() that can detect out of
    range values.
    
    Fixes: 8205a078ba78 ("x86/intel_rdt/mba_sc: Add schemata support")
    Fixes: 6ce1560d35f6 ("x86/resctrl: Switch over to the resctrl mbps_val list")
    Co-developed-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
    Signed-off-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
    Signed-off-by: Martin Kletzander <nert.pinx@xxxxxxxxx>
    Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
    Reviewed-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
    Reviewed-by: Tony Luck <tony.luck@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 000e1467b4cde..d00909428b435 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -27,10 +27,10 @@
  * hardware. The allocated bandwidth percentage is rounded to the next
  * control step available on the hardware.
  */
-static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
+static bool bw_validate(char *buf, u32 *data, struct rdt_resource *r)
 {
-	unsigned long bw;
 	int ret;
+	u32 bw;
 
 	/*
 	 * Only linear delay values is supported for current Intel SKUs.
@@ -40,16 +40,21 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
 		return false;
 	}
 
-	ret = kstrtoul(buf, 10, &bw);
+	ret = kstrtou32(buf, 10, &bw);
 	if (ret) {
-		rdt_last_cmd_printf("Non-decimal digit in MB value %s\n", buf);
+		rdt_last_cmd_printf("Invalid MB value %s\n", buf);
 		return false;
 	}
 
-	if ((bw < r->membw.min_bw || bw > r->default_ctrl) &&
-	    !is_mba_sc(r)) {
-		rdt_last_cmd_printf("MB value %ld out of range [%d,%d]\n", bw,
-				    r->membw.min_bw, r->default_ctrl);
+	/* Nothing else to do if software controller is enabled. */
+	if (is_mba_sc(r)) {
+		*data = bw;
+		return true;
+	}
+
+	if (bw < r->membw.min_bw || bw > r->default_ctrl) {
+		rdt_last_cmd_printf("MB value %u out of range [%d,%d]\n",
+				    bw, r->membw.min_bw, r->default_ctrl);
 		return false;
 	}
 
@@ -62,7 +67,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
 {
 	struct resctrl_staged_config *cfg;
 	struct rdt_resource *r = s->res;
-	unsigned long bw_val;
+	u32 bw_val;
 
 	cfg = &d->staged_config[s->conf_type];
 	if (cfg->have_new_ctrl) {




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux