Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (scmi) Fix potential buffer overflow in scmi_hwmon_probe()

SMATCH detected a potential buffer overflow in the manipulation of
hwmon_attributes array inside the scmi_hwmon_probe function:

drivers/hwmon/scmi-hwmon.c:226
scmi_hwmon_probe() error: buffer overflow 'hwmon_attributes' 6 <= 9

Fix it by statically declaring the size of the array as the maximum
possible as defined by hwmon_max define.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Link: https://lore.kernel.org/r/20200715121338.GA18761@e119603-lin.cambridge.arm.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Cristian Marussi and committed by
Guenter Roeck
3ce17cd2 8a03746c

+1 -1
+1 -1
drivers/hwmon/scmi-hwmon.c
··· 147 147 [ENERGY] = hwmon_energy, 148 148 }; 149 149 150 - static u32 hwmon_attributes[] = { 150 + static u32 hwmon_attributes[hwmon_max] = { 151 151 [hwmon_chip] = HWMON_C_REGISTER_TZ, 152 152 [hwmon_temp] = HWMON_T_INPUT | HWMON_T_LABEL, 153 153 [hwmon_in] = HWMON_I_INPUT | HWMON_I_LABEL,