platform/x86: dell-pc: avoid double free and invalid unregistration
Subsystems (2)
PATCH 1/1 platform/x86: dell-pc: avoid double free and invalid unregistration
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.
---
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(-)
drivers/platform/x86/dell/dell-pc.c +3 -1
@@ -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,
Signature · 1 line
Thomas Weißschuh <[email protected]>
Quoted 42 lines · Thomas Weißschuh
If
platform_profile_register()fails it doeskfree(thermal_handler)and leaves the pointer value around.
Any call tothermal_cleanup()will try tokfree(thermal_handler)again. This will happen right away indell_init().
In addition,platform_profile_remove()will be called although no profile is registered.NULL out the
thermal_handler, sothermal_cleanup()avoids the double free.Fixes 996ad4129810 ("platform/x86: dell-pc: Implement platform_profile")Signed-off-by Thomas Weißschuh <[email protected]>---
Currently the call tothermal_cleanup()indell_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(-)drivers/platform/x86/dell/dell-pc.c +3
-2@@ -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
Quoted 3 lines
Best regards,
--
Thomas Weißschuh <[email protected]>
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,
Ilpo Järvinen
maintainerQuoted 8 lines · Thomas Weißschuh
If
platform_profile_register()fails it doeskfree(thermal_handler)and leaves the pointer value around.
Any call tothermal_cleanup()will try tokfree(thermal_handler)again. This will happen right away indell_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.