Skip to contentSkip to conversation

hwmon: (asus_wmi_ec_sensors) fix array overflow

PATCH Applied Dan Carpenter 2 participants 4 messages Nov 30, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hwmon: (asus_wmi_ec_sensors) fix array overflow

Smatch detected an array out of bounds error:

drivers/hwmon/asus_wmi_ec_sensors.c:562 asus_wmi_ec_configure_sensor_setup()
error: buffer overflow 'hwmon_attributes' 8 <= 9

The hwmon_attributes[] array needs to be declared with "hwmon_max" elements.

Fixes c04c7f7bfcbe ("hwmon: (asus_wmi_ec_sensors) Support B550 Asus WMI.")
---
 drivers/hwmon/asus_wmi_ec_sensors.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/asus_wmi_ec_sensors.c +1 -1
index f612abc66c89..22a1459305a7 100644
@@ -41,7 +41,7 @@
 #define ASUSWMI_MAX_BUF_LEN		128
 #define SENSOR_LABEL_LEN		16
 
-static u32 hwmon_attributes[] = {
+static u32 hwmon_attributes[hwmon_max] = {
 	[hwmon_chip]	= HWMON_C_REGISTER_TZ,
 	[hwmon_temp]	= HWMON_T_INPUT | HWMON_T_LABEL,
 	[hwmon_in]	= HWMON_I_INPUT | HWMON_I_LABEL,
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 hwmon: (asus_wmi_sensors) fix an array overflow

Smatch detects this array overflow:

drivers/hwmon/asus_wmi_sensors.c:569 asus_wmi_configure_sensor_setup()
error: buffer overflow 'hwmon_attributes' 8 <= 9

The hwmon_attributes[] array should have "hwmon_max" so that it gets larger when more attributes are added.

Fixes 9d07e54a25b8 ("hwmon: (asus_wmi_sensors) Support X370 Asus WMI.")
---
 drivers/hwmon/asus_wmi_sensors.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/asus_wmi_sensors.c +1 -1
index 67af15d99396..c80eee874b6c 100644
@@ -125,7 +125,7 @@ static enum hwmon_sensor_types asus_data_types[] = {
 	[WATER_FLOW]	= hwmon_fan,
 };
 
-static u32 hwmon_attributes[] = {
+static u32 hwmon_attributes[hwmon_max] = {
 	[hwmon_chip]	= HWMON_C_REGISTER_TZ,
 	[hwmon_temp]	= HWMON_T_INPUT | HWMON_T_LABEL,
 	[hwmon_in]	= HWMON_I_INPUT | HWMON_I_LABEL,
Signature · 1 line
2.20.1
maintainer Applied
#2 lore raw

Re: [PATCH 2/2] hwmon: (asus_wmi_sensors) fix an array overflow

Quoted 10 lines · Dan Carpenter

Smatch detects this array overflow:

drivers/hwmon/asus_wmi_sensors.c:569 asus_wmi_configure_sensor_setup()
error: buffer overflow 'hwmon_attributes' 8 <= 9

The hwmon_attributes[] array should have "hwmon_max" so that it gets larger when more attributes are added.

Fixes 9d07e54a25b8 ("hwmon: (asus_wmi_sensors) Support X370 Asus WMI.")

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 drivers/hwmon/asus_wmi_sensors.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/asus_wmi_sensors.c +1 -1
index 67af15d99396..c80eee874b6c 100644
@@ -125,7 +125,7 @@ static enum hwmon_sensor_types asus_data_types[] = {
 	[WATER_FLOW]	= hwmon_fan,
 };
 
-static u32 hwmon_attributes[] = {
+static u32 hwmon_attributes[hwmon_max] = {
 	[hwmon_chip]	= HWMON_C_REGISTER_TZ,
 	[hwmon_temp]	= HWMON_T_INPUT | HWMON_T_LABEL,
 	[hwmon_in]	= HWMON_I_INPUT | HWMON_I_LABEL,
maintainer Applied
#3 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter

Smatch detected an array out of bounds error:

drivers/hwmon/asus_wmi_ec_sensors.c:562 asus_wmi_ec_configure_sensor_setup()
error: buffer overflow 'hwmon_attributes' 8 <= 9

The hwmon_attributes[] array needs to be declared with "hwmon_max" elements.

Fixes c04c7f7bfcbe ("hwmon: (asus_wmi_ec_sensors) Support B550 Asus WMI.")

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 drivers/hwmon/asus_wmi_ec_sensors.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/asus_wmi_ec_sensors.c +1 -1
index f612abc66c89..22a1459305a7 100644
@@ -41,7 +41,7 @@
 #define ASUSWMI_MAX_BUF_LEN		128
 #define SENSOR_LABEL_LEN		16
 
-static u32 hwmon_attributes[] = {
+static u32 hwmon_attributes[hwmon_max] = {
 	[hwmon_chip]	= HWMON_C_REGISTER_TZ,
 	[hwmon_temp]	= HWMON_T_INPUT | HWMON_T_LABEL,
 	[hwmon_in]	= HWMON_I_INPUT | HWMON_I_LABEL,