linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal/int340x_thermal: Prevent page fault on .set_mode() op
@ 2020-07-08 13:46 Bartosz Szczepanek
  2020-07-09  9:36 ` Bartosz Szczepanek
  2020-07-09 17:00 ` Srinivas Pandruvada
  0 siblings, 2 replies; 3+ messages in thread
From: Bartosz Szczepanek @ 2020-07-08 13:46 UTC (permalink / raw)
  To: Matthew Garrett, Zhang Rui, Pandruvada Srinivas, linux-pm, linux-kernel
  Cc: Daniel Lezcano, Amit Kucheria, Radoslaw Biernacki, Alex Levin,
	Bartosz Szczepanek

Starting from commit "thermal/int340x_thermal: Don't require IDSP to
exist", priv->current_uuid_index is initialized to -1. This value may
be passed to int3400_thermal_run_osc() from int3400_thermal_set_mode,
contributing to page fault when accessing int3400_thermal_uuids array
at index -1.

This commit adds a check on uuid value to int3400_thermal_run_osc.

Signed-off-by: Bartosz Szczepanek <bsz@semihalf.com>
---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
index 0b3a62655843..12448ccd27f1 100644
--- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
@@ -216,11 +216,16 @@ static int int3400_thermal_run_osc(acpi_handle handle,
 	acpi_status status;
 	int result = 0;
 	struct acpi_osc_context context = {
-		.uuid_str = int3400_thermal_uuids[uuid],
+		.uuid_str = NULL,
 		.rev = 1,
 		.cap.length = 8,
 	};
 
+	if (uuid < 0 || uuid >= INT3400_THERMAL_MAXIMUM_UUID)
+		return -EINVAL;
+
+	context.uuid_str = int3400_thermal_uuids[uuid];
+
 	buf[OSC_QUERY_DWORD] = 0;
 	buf[OSC_SUPPORT_DWORD] = enable;
 
-- 
2.17.1


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

* Re: [PATCH] thermal/int340x_thermal: Prevent page fault on .set_mode() op
  2020-07-08 13:46 [PATCH] thermal/int340x_thermal: Prevent page fault on .set_mode() op Bartosz Szczepanek
@ 2020-07-09  9:36 ` Bartosz Szczepanek
  2020-07-09 17:00 ` Srinivas Pandruvada
  1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Szczepanek @ 2020-07-09  9:36 UTC (permalink / raw)
  To: Matthew Garrett, Zhang Rui, Pandruvada Srinivas, linux-pm,
	Linux Kernel Mailing List
  Cc: Daniel Lezcano, Amit Kucheria, Radoslaw Biernacki, Alex Levin

Hi Rui, Matthew,

I think this regression should be corrected still in the 5.8 release
cycle. It may cause kernel panic if .set_mode() is called before
current_uuid_store(), and from what I see both operations can be
triggered from sysfs. What I'm not 100% sure about is if we should
apply the above fix, or rather revert the driver to its default
behaviour of using uuid=0 if it wasn't set from userspace (this is how
it was before Matthew's commit). What do you think?

Best regards,
Bartosz


On Wed, Jul 8, 2020 at 3:46 PM Bartosz Szczepanek <bsz@semihalf.com> wrote:
>
> Starting from commit "thermal/int340x_thermal: Don't require IDSP to
> exist", priv->current_uuid_index is initialized to -1. This value may
> be passed to int3400_thermal_run_osc() from int3400_thermal_set_mode,
> contributing to page fault when accessing int3400_thermal_uuids array
> at index -1.
>
> This commit adds a check on uuid value to int3400_thermal_run_osc.
>
> Signed-off-by: Bartosz Szczepanek <bsz@semihalf.com>
> ---
>  drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> index 0b3a62655843..12448ccd27f1 100644
> --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> @@ -216,11 +216,16 @@ static int int3400_thermal_run_osc(acpi_handle handle,
>         acpi_status status;
>         int result = 0;
>         struct acpi_osc_context context = {
> -               .uuid_str = int3400_thermal_uuids[uuid],
> +               .uuid_str = NULL,
>                 .rev = 1,
>                 .cap.length = 8,
>         };
>
> +       if (uuid < 0 || uuid >= INT3400_THERMAL_MAXIMUM_UUID)
> +               return -EINVAL;
> +
> +       context.uuid_str = int3400_thermal_uuids[uuid];
> +
>         buf[OSC_QUERY_DWORD] = 0;
>         buf[OSC_SUPPORT_DWORD] = enable;
>
> --
> 2.17.1
>

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

* Re: [PATCH] thermal/int340x_thermal: Prevent page fault on .set_mode() op
  2020-07-08 13:46 [PATCH] thermal/int340x_thermal: Prevent page fault on .set_mode() op Bartosz Szczepanek
  2020-07-09  9:36 ` Bartosz Szczepanek
@ 2020-07-09 17:00 ` Srinivas Pandruvada
  1 sibling, 0 replies; 3+ messages in thread
From: Srinivas Pandruvada @ 2020-07-09 17:00 UTC (permalink / raw)
  To: Bartosz Szczepanek, Matthew Garrett, Zhang Rui, linux-pm, linux-kernel
  Cc: Daniel Lezcano, Amit Kucheria, Radoslaw Biernacki, Alex Levin

On Wed, 2020-07-08 at 15:46 +0200, Bartosz Szczepanek wrote:
> Starting from commit "thermal/int340x_thermal: Don't require IDSP to
> exist", priv->current_uuid_index is initialized to -1. This value may
> be passed to int3400_thermal_run_osc() from int3400_thermal_set_mode,
> contributing to page fault when accessing int3400_thermal_uuids array
> at index -1.
> 
> This commit adds a check on uuid value to int3400_thermal_run_osc.
> 
> Signed-off-by: Bartosz Szczepanek <bsz@semihalf.com>
Reviewed-by: Pandruvada, Srinivas <srinivas.pandruvada@linux.intel.com>

> ---
>  drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> index 0b3a62655843..12448ccd27f1 100644
> --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> @@ -216,11 +216,16 @@ static int int3400_thermal_run_osc(acpi_handle
> handle,
>  	acpi_status status;
>  	int result = 0;
>  	struct acpi_osc_context context = {
> -		.uuid_str = int3400_thermal_uuids[uuid],
> +		.uuid_str = NULL,
>  		.rev = 1,
>  		.cap.length = 8,
>  	};
>  
> +	if (uuid < 0 || uuid >= INT3400_THERMAL_MAXIMUM_UUID)
> +		return -EINVAL;
> +
> +	context.uuid_str = int3400_thermal_uuids[uuid];
> +
>  	buf[OSC_QUERY_DWORD] = 0;
>  	buf[OSC_SUPPORT_DWORD] = enable;
>  


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

end of thread, other threads:[~2020-07-09 17:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 13:46 [PATCH] thermal/int340x_thermal: Prevent page fault on .set_mode() op Bartosz Szczepanek
2020-07-09  9:36 ` Bartosz Szczepanek
2020-07-09 17:00 ` Srinivas Pandruvada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).