mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86: dell-pc: avoid double free and invalid unregistration
@ 2024-06-04 21:41 Thomas Weißschuh
  2024-06-05  2:46 ` Lyndon Sanche
  2024-06-07 13:22 ` Ilpo Järvinen
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2024-06-04 21:41 UTC (permalink / raw)
  To: Lyndon Sanche, Hans de Goede, Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel, Thomas Weißschuh

If platform_profile_register() fails it does kfree(thermal_handler) and
leaves the pointer value around.
Any call to thermal_cleanup() will try to kfree(thermal_handler) again.
This will happen right away in dell_init().
In addition, platform_profile_remove() will be called although no
profile is registered.

NULL out the thermal_handler, so thermal_cleanup() avoids the double free.

Fixes: 996ad4129810 ("platform/x86: dell-pc: Implement platform_profile")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Currently the call to thermal_cleanup() in dell_init() is completely
unnecessary. But I guess more functionality will be handled by the
driver and then this structure makes sense.

This is untested.
---
 drivers/platform/x86/dell/dell-pc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/dell/dell-pc.c b/drivers/platform/x86/dell/dell-pc.c
index dfe09c463d03..972385ca1990 100644
--- a/drivers/platform/x86/dell/dell-pc.c
+++ b/drivers/platform/x86/dell/dell-pc.c
@@ -261,8 +261,10 @@ static int thermal_init(void)
 
 	/* Clean up if failed */
 	ret = platform_profile_register(thermal_handler);
-	if (ret)
+	if (ret) {
 		kfree(thermal_handler);
+		thermal_handler = NULL;
+	}
 
 	return ret;
 }

---
base-commit: 0da7a954480cc99978e3570c991e3779e56fc736
change-id: 20240604-dell-pc-double-free-e8cf2aa9b2fb

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


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

* Re: [PATCH] platform/x86: dell-pc: avoid double free and invalid unregistration
  2024-06-04 21:41 [PATCH] platform/x86: dell-pc: avoid double free and invalid unregistration Thomas Weißschuh
@ 2024-06-05  2:46 ` Lyndon Sanche
  2024-06-07 13:22 ` Ilpo Järvinen
  1 sibling, 0 replies; 3+ messages in thread
From: Lyndon Sanche @ 2024-06-05  2:46 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Hans de Goede, Ilpo Järvinen, platform-driver-x86, linux-kernel



On Tue, Jun 4 2024 at 11:41:24 PM +02:00:00, Thomas Weißschuh 
<linux@weissschuh.net> wrote:
> If platform_profile_register() fails it does kfree(thermal_handler) 
> and
> leaves the pointer value around.
> Any call to thermal_cleanup() will try to kfree(thermal_handler) 
> again.
> This will happen right away in dell_init().
> In addition, platform_profile_remove() will be called although no
> profile is registered.
> 
> NULL out the thermal_handler, so thermal_cleanup() avoids the double 
> free.
> 
> Fixes: 996ad4129810 ("platform/x86: dell-pc: Implement 
> platform_profile")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Currently the call to thermal_cleanup() in dell_init() is completely
> unnecessary. But I guess more functionality will be handled by the
> driver and then this structure makes sense.
> 
> This is untested.
> ---
>  drivers/platform/x86/dell/dell-pc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/dell/dell-pc.c 
> b/drivers/platform/x86/dell/dell-pc.c
> index dfe09c463d03..972385ca1990 100644
> --- a/drivers/platform/x86/dell/dell-pc.c
> +++ b/drivers/platform/x86/dell/dell-pc.c
> @@ -261,8 +261,10 @@ static int thermal_init(void)
> 
>  	/* Clean up if failed */
>  	ret = platform_profile_register(thermal_handler);
> -	if (ret)
> +	if (ret) {
>  		kfree(thermal_handler);
> +		thermal_handler = NULL;
> +	}
> 
>  	return ret;
>  }
> 
> ---
> base-commit: 0da7a954480cc99978e3570c991e3779e56fc736
> change-id: 20240604-dell-pc-double-free-e8cf2aa9b2fb
> 
> Best regards,
> --
> Thomas Weißschuh <linux@weissschuh.net>

Thank you for this patch. I was able to apply your patch and compile 
successfully. I have not had a chance to try it on my hardware.

I agree with the change, and it looks good to me.

Thanks,

Reviewed-by: Lyndon Sanche <lsanche@lyndeno.ca>



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

* Re: [PATCH] platform/x86: dell-pc: avoid double free and invalid unregistration
  2024-06-04 21:41 [PATCH] platform/x86: dell-pc: avoid double free and invalid unregistration Thomas Weißschuh
  2024-06-05  2:46 ` Lyndon Sanche
@ 2024-06-07 13:22 ` Ilpo Järvinen
  1 sibling, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2024-06-07 13:22 UTC (permalink / raw)
  To: Lyndon Sanche, Hans de Goede, Thomas Weißschuh
  Cc: platform-driver-x86, linux-kernel

On Tue, 04 Jun 2024 23:41:24 +0200, Thomas Weißschuh wrote:

> If platform_profile_register() fails it does kfree(thermal_handler) and
> leaves the pointer value around.
> Any call to thermal_cleanup() will try to kfree(thermal_handler) again.
> This will happen right away in dell_init().
> In addition, platform_profile_remove() will be called although no
> profile is registered.
> 
> [...]


Thank you for your contribution, it has been applied to my local
review-ilpo branch. Note it will show up in the public
platform-drivers-x86/review-ilpo branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: dell-pc: avoid double free and invalid unregistration
      commit: dd637f5cd5f334d2d014872544470031415cec3b

--
 i.


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

end of thread, other threads:[~2024-06-07 13:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 21:41 [PATCH] platform/x86: dell-pc: avoid double free and invalid unregistration Thomas Weißschuh
2024-06-05  2:46 ` Lyndon Sanche
2024-06-07 13:22 ` Ilpo Järvinen

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®