Skip to content

Commit 4e440ab

Browse files
zhang-ruigroeck
authored andcommitted
hwmon: (coretemp) Fix out-of-bounds memory access
Fix a bug that pdata->cpu_map[] is set before out-of-bounds check. The problem might be triggered on systems with more than 128 cores per package. Fixes: 7108b80 ("hwmon/coretemp: Handle large core ID value") Signed-off-by: Zhang Rui <rui.zhang@intel.com> Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/r/20240202092144.71180-2-rui.zhang@intel.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 1168491 commit 4e440ab

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

drivers/hwmon/coretemp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,18 +509,14 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu,
509509
if (pkg_flag) {
510510
attr_no = PKG_SYSFS_ATTR_NO;
511511
} else {
512-
index = ida_alloc(&pdata->ida, GFP_KERNEL);
512+
index = ida_alloc_max(&pdata->ida, NUM_REAL_CORES - 1, GFP_KERNEL);
513513
if (index < 0)
514514
return index;
515+
515516
pdata->cpu_map[index] = topology_core_id(cpu);
516517
attr_no = index + BASE_SYSFS_ATTR_NO;
517518
}
518519

519-
if (attr_no > MAX_CORE_DATA - 1) {
520-
err = -ERANGE;
521-
goto ida_free;
522-
}
523-
524520
tdata = init_temp_data(cpu, pkg_flag);
525521
if (!tdata) {
526522
err = -ENOMEM;

0 commit comments

Comments
 (0)