Skip to contentSkip to conversation

hwmon: (amd_energy) fix allocation of hwmon_channel_info config

PATCH Applied David Arcari 3 participants 5 messages Jan 7, 2021 – Jan 8, 2021

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

PATCH 1/1 hwmon: (amd_energy) fix allocation of hwmon_channel_info config

hwmon, specifically hwmon_num_channel_attrs, expects the config array in the hwmon_channel_info structure to be terminated by a zero entry. amd_energy does not honor this convention. As result, a KASAN warning is possible. Fix this by adding an additional entry and setting it to zero.

Fixes 8abee9566b7e ("hwmon: Add amd_energy driver to report energy counters")
Cc Naveen Krishna Chatradhi <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Guenter Roeck <[email protected]>
---
 drivers/hwmon/amd_energy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/amd_energy.c +2 -1
index 9b306448b7a0..822c2e74b98d 100644
@@ -222,7 +222,7 @@ static int amd_create_sensor(struct device *dev,
 	 */
 	cpus = num_present_cpus() / num_siblings;
 
-	s_config = devm_kcalloc(dev, cpus + sockets,
+	s_config = devm_kcalloc(dev, cpus + sockets + 1,
 				sizeof(u32), GFP_KERNEL);
 	if (!s_config)
 		return -ENOMEM;
@@ -254,6 +254,7 @@ static int amd_create_sensor(struct device *dev,
 			scnprintf(label_l[i], 10, "Esocket%u", (i - cpus));
 	}
 
+	s_config[i] = 0;
 	return 0;
 }
 
Signature · 1 line
2.18.1
#1 lore raw

[AMD Official Use Only - Approved for External Use]

Hi David,

Thank you for noticing and submitting a fix. You may use

Regards,
Naveenk

-----Original Message-----
From: David Arcari <[email protected]>
Sent: Thursday, January 7, 2021 8:17 PM
To: [email protected]
Cc: David Arcari <[email protected]>; Chatradhi, Naveen Krishna <[email protected]>; Jean Delvare <[email protected]>; Guenter Roeck <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] hwmon: (amd_energy) fix allocation of hwmon_channel_info config

[CAUTION: External Email]

hwmon, specifically hwmon_num_channel_attrs, expects the config array in the hwmon_channel_info structure to be terminated by a zero entry. amd_energy does not honor this convention. As result, a KASAN warning is possible. Fix this by adding an additional entry and setting it to zero.

Fixes 8abee9566b7e ("hwmon: Add amd_energy driver to report energy counters")
Cc Naveen Krishna Chatradhi <[email protected]>

[naveenk:] Signed-off-by: Naveen Krishna Chatradhi <[email protected]>
Cc: Jean Delvare <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/hwmon/amd_energy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/amd_energy.c +2 -1
@@ -222,7 +222,7 @@ static int amd_create_sensor(struct device *dev,
         */
        cpus = num_present_cpus() / num_siblings;
 
-       s_config = devm_kcalloc(dev, cpus + sockets,
+       s_config = devm_kcalloc(dev, cpus + sockets + 1,
                                sizeof(u32), GFP_KERNEL);
        if (!s_config)
                return -ENOMEM;
@@ -254,6 +254,7 @@ static int amd_create_sensor(struct device *dev,
                        scnprintf(label_l[i], 10, "Esocket%u", (i - cpus));
        }
 
+       s_config[i] = 0;
        return 0;
 }
 

--
2.18.1

maintainer
#2 lore raw
Quoted 7 lines · Naveen Krishna

[AMD Official Use Only - Approved for External Use]

Hi David,

Thank you for noticing and submitting a fix. You may use

No, because you are not in the approval path (you did not send the patch to me). Reviewed-by: or Acked-by: would be more appropriate.

Genter

Quoted 50 lines

Regards,
Naveenk

-----Original Message-----
From: David Arcari <[email protected]>
Sent: Thursday, January 7, 2021 8:17 PM
To: [email protected]
Cc: David Arcari <[email protected]>; Chatradhi, Naveen Krishna <[email protected]>; Jean Delvare <[email protected]>; Guenter Roeck <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] hwmon: (amd_energy) fix allocation of hwmon_channel_info config

[CAUTION: External Email]

hwmon, specifically hwmon_num_channel_attrs, expects the config array in the hwmon_channel_info structure to be terminated by a zero entry. amd_energy does not honor this convention. As result, a KASAN warning is possible. Fix this by adding an additional entry and setting it to zero.

Fixes 8abee9566b7e ("hwmon: Add amd_energy driver to report energy counters")
Cc Naveen Krishna Chatradhi <[email protected]>

[naveenk:] Signed-off-by: Naveen Krishna Chatradhi <[email protected]>
Cc: Jean Delvare <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 drivers/hwmon/amd_energy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/amd_energy.c +2 -2
@@ -222,7 +222,7 @@ static int amd_create_sensor(struct device *dev,
         */
        cpus = num_present_cpus() / num_siblings;
 
-       s_config = devm_kcalloc(dev, cpus + sockets,
+       s_config = devm_kcalloc(dev, cpus + sockets + 1,
                                sizeof(u32), GFP_KERNEL);
        if (!s_config)
                return -ENOMEM;
@@ -254,6 +254,7 @@ static int amd_create_sensor(struct device *dev,
                        scnprintf(label_l[i], 10, "Esocket%u", (i - cpus));
        }
 
+       s_config[i] = 0;
        return 0;
 }
 
--

2.18.1

Acked-by Naveen Krishna Chatradhi
#3 lore raw

[AMD Official Use Only - Approved for External Use]

Hi Guenter,

Quoted 1 line
Quoted 1 line

No, because you are not in the approval path (you did not send the patch to me). Reviewed-by: or Acked-by: would be more appropriate.

Got it, my mistake, please use

Regards,
Naveenk

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Friday, January 8, 2021 11:47 AM
To: Chatradhi, Naveen Krishna <[email protected]>; David Arcari <[email protected]>; [email protected]
Cc: Jean Delvare <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] hwmon: (amd_energy) fix allocation of hwmon_channel_info config

[CAUTION: External Email]

Quoted 7 lines · Naveen Krishna

[AMD Official Use Only - Approved for External Use]

Hi David,

Thank you for noticing and submitting a fix. You may use

No, because you are not in the approval path (you did not send the patch to me). Reviewed-by: or Acked-by: would be more appropriate.

Genter

Quoted 56 lines

Regards,
Naveenk

-----Original Message-----
From: David Arcari <[email protected]>
Sent: Thursday, January 7, 2021 8:17 PM
To: [email protected]
Cc: David Arcari <[email protected]>; Chatradhi, Naveen Krishna <[email protected]>; Jean Delvare <[email protected]>; Guenter Roeck <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] hwmon: (amd_energy) fix allocation of hwmon_channel_info config

[CAUTION: External Email]

hwmon, specifically hwmon_num_channel_attrs, expects the config array in the hwmon_channel_info structure to be terminated by a zero entry. amd_energy does not honor this convention. As result, a KASAN warning is possible. Fix this by adding an additional entry and setting it to zero.

Fixes 8abee9566b7e ("hwmon: Add amd_energy driver to report energy

counters")

Cc Naveen Krishna Chatradhi <[email protected]> [naveenk:]
Cc Jean Delvare <[email protected]>
Cc Guenter Roeck <[email protected]>
---
 drivers/hwmon/amd_energy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/amd_energy.c +2 -2
index 9b306448b7a0..822c2e74b98d 100644
@@ -222,7 +222,7 @@ static int amd_create_sensor(struct device *dev,
         */
        cpus = num_present_cpus() / num_siblings;
 
-       s_config = devm_kcalloc(dev, cpus + sockets,
+       s_config = devm_kcalloc(dev, cpus + sockets + 1,
                                sizeof(u32), GFP_KERNEL);
        if (!s_config)
                return -ENOMEM;
@@ -254,6 +254,7 @@ static int amd_create_sensor(struct device *dev,
                        scnprintf(label_l[i], 10, "Esocket%u", (i - cpus));
        }
 
+       s_config[i] = 0;
        return 0;
 }
 
--

2.18.1

maintainer Applied
#4 lore raw
In reply to David Arcari
Quoted 8 lines · David Arcari

hwmon, specifically hwmon_num_channel_attrs, expects the config array in the hwmon_channel_info structure to be terminated by a zero entry. amd_energy does not honor this convention. As result, a KASAN warning is possible. Fix this by adding an additional entry and setting it to zero.

Fixes 8abee9566b7e ("hwmon: Add amd_energy driver to report energy counters")
Quoted 8 lines

Applied.

Thanks,
Guenter