mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 -next] thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference
@ 2023-03-29 12:26 Zhang Rui
  2023-03-29 13:57 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Rui @ 2023-03-29 12:26 UTC (permalink / raw)
  To: linux-pm, rafael.j.wysocki, daniel.lezcano; +Cc: linux-kernel

When the hwmon device node of a thermal zone device is not found,
using hwmon->device causes a kernel NULL pointer dereference.

Skip removing hwmon device for thermal zones without hwmon device, and
fix the kernel NULL pointer dereference when hwmon device is not found.

Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field")
Reported-by: Preble Adam C <adam.c.preble@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
v1 -> v2
   Add check for devices without hwmon device.
   Use pr_debug instead of dev_dbg.
---
 drivers/thermal/thermal_hwmon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index c59db17dddd6..1cdee2ee8d4d 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -226,10 +226,12 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
 	struct thermal_hwmon_device *hwmon;
 	struct thermal_hwmon_temp *temp;
 
+	if (tz->tzp && tz->tzp->no_hwmon)
+		return;
+
 	hwmon = thermal_hwmon_lookup_by_type(tz);
 	if (unlikely(!hwmon)) {
-		/* Should never happen... */
-		dev_dbg(hwmon->device, "hwmon device lookup failed!\n");
+		pr_debug("hwmon device lookup failed!\n");
 		return;
 	}
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 -next] thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference
  2023-03-29 12:26 [PATCH v2 -next] thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference Zhang Rui
@ 2023-03-29 13:57 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2023-03-29 13:57 UTC (permalink / raw)
  To: Zhang Rui; +Cc: linux-pm, rafael.j.wysocki, daniel.lezcano, linux-kernel

On Wed, Mar 29, 2023 at 2:26 PM Zhang Rui <rui.zhang@intel.com> wrote:
>
> When the hwmon device node of a thermal zone device is not found,
> using hwmon->device causes a kernel NULL pointer dereference.
>
> Skip removing hwmon device for thermal zones without hwmon device, and
> fix the kernel NULL pointer dereference when hwmon device is not found.
>
> Fixes: dec07d399cc8 ("thermal: Don't use 'device' internal thermal zone structure field")
> Reported-by: Preble Adam C <adam.c.preble@intel.com>

Do you have a link to the bug report?  I'm wondering where exactly it triggers.

> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
> ---
> v1 -> v2
>    Add check for devices without hwmon device.
>    Use pr_debug instead of dev_dbg.
> ---
>  drivers/thermal/thermal_hwmon.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
> index c59db17dddd6..1cdee2ee8d4d 100644
> --- a/drivers/thermal/thermal_hwmon.c
> +++ b/drivers/thermal/thermal_hwmon.c
> @@ -226,10 +226,12 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
>         struct thermal_hwmon_device *hwmon;
>         struct thermal_hwmon_temp *temp;
>
> +       if (tz->tzp && tz->tzp->no_hwmon)
> +               return;
> +
>         hwmon = thermal_hwmon_lookup_by_type(tz);
>         if (unlikely(!hwmon)) {
> -               /* Should never happen... */
> -               dev_dbg(hwmon->device, "hwmon device lookup failed!\n");
> +               pr_debug("hwmon device lookup failed!\n");
>                 return;
>         }
>
> --

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-29 13:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 12:26 [PATCH v2 -next] thermal/drivers/thermal_hwmon: Fix a kernel NULL pointer dereference Zhang Rui
2023-03-29 13:57 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®