* [PATCH] hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition
@ 2023-03-10 8:40 Zheng Wang
2023-03-10 16:34 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: Zheng Wang @ 2023-03-10 8:40 UTC (permalink / raw)
To: jdelvare
Cc: linux, linux-hwmon, linux-kernel, hackerzheng666,
1395428693sheep, alex000young, Zheng Wang
In xgene_hwmon_probe, &ctx->workq is bound with
xgene_hwmon_evt_work. Then it will be started.
If we remove the driver which will call
xgene_hwmon_remove to make cleanup, there may
be a unfinished work.
The possiblesequence is as follows:
Fix it by finishing the work before cleanup in the
xgene_hwmon_remove
CPU0 CPU1
|xgene_hwmon_evt_work
xgene_hwmon_remove |
kfifo_free(&ctx->async_msg_fifo);|
|
|kfifo_out_spinlocked
|//use &ctx->async_msg_fifo
Fixes: 2ca492e22cb7 ("hwmon: (xgene) Fix crash when alarm occurs before driver probe")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
drivers/hwmon/xgene-hwmon.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
index 5cde837bfd09..d1abea49f01b 100644
--- a/drivers/hwmon/xgene-hwmon.c
+++ b/drivers/hwmon/xgene-hwmon.c
@@ -761,6 +761,7 @@ static int xgene_hwmon_remove(struct platform_device *pdev)
{
struct xgene_hwmon_dev *ctx = platform_get_drvdata(pdev);
+ cancel_work_sync(&ctx->workq);
hwmon_device_unregister(ctx->hwmon_dev);
kfifo_free(&ctx->async_msg_fifo);
if (acpi_disabled)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition
2023-03-10 8:40 [PATCH] hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition Zheng Wang
@ 2023-03-10 16:34 ` Guenter Roeck
2023-03-10 16:54 ` Zheng Hacker
0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2023-03-10 16:34 UTC (permalink / raw)
To: Zheng Wang
Cc: jdelvare, linux-hwmon, linux-kernel, hackerzheng666,
1395428693sheep, alex000young
On Fri, Mar 10, 2023 at 04:40:07PM +0800, Zheng Wang wrote:
> In xgene_hwmon_probe, &ctx->workq is bound with
> xgene_hwmon_evt_work. Then it will be started.
>
> If we remove the driver which will call
> xgene_hwmon_remove to make cleanup, there may
> be a unfinished work.
>
> The possiblesequence is as follows:
>
> Fix it by finishing the work before cleanup in the
> xgene_hwmon_remove
>
> CPU0 CPU1
>
> |xgene_hwmon_evt_work
> xgene_hwmon_remove |
> kfifo_free(&ctx->async_msg_fifo);|
> |
> |kfifo_out_spinlocked
> |//use &ctx->async_msg_fifo
> Fixes: 2ca492e22cb7 ("hwmon: (xgene) Fix crash when alarm occurs before driver probe")
> Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/xgene-hwmon.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
> index 5cde837bfd09..d1abea49f01b 100644
> --- a/drivers/hwmon/xgene-hwmon.c
> +++ b/drivers/hwmon/xgene-hwmon.c
> @@ -761,6 +761,7 @@ static int xgene_hwmon_remove(struct platform_device *pdev)
> {
> struct xgene_hwmon_dev *ctx = platform_get_drvdata(pdev);
>
> + cancel_work_sync(&ctx->workq);
> hwmon_device_unregister(ctx->hwmon_dev);
> kfifo_free(&ctx->async_msg_fifo);
> if (acpi_disabled)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition
2023-03-10 16:34 ` Guenter Roeck
@ 2023-03-10 16:54 ` Zheng Hacker
0 siblings, 0 replies; 3+ messages in thread
From: Zheng Hacker @ 2023-03-10 16:54 UTC (permalink / raw)
To: Guenter Roeck
Cc: Zheng Wang, jdelvare, linux-hwmon, linux-kernel, 1395428693sheep,
alex000young
Guenter Roeck <linux@roeck-us.net> 于2023年3月11日周六 00:34写道:
>
> On Fri, Mar 10, 2023 at 04:40:07PM +0800, Zheng Wang wrote:
> > In xgene_hwmon_probe, &ctx->workq is bound with
> > xgene_hwmon_evt_work. Then it will be started.
> >
> > If we remove the driver which will call
> > xgene_hwmon_remove to make cleanup, there may
> > be a unfinished work.
> >
> > The possiblesequence is as follows:
> >
> > Fix it by finishing the work before cleanup in the
> > xgene_hwmon_remove
> >
> > CPU0 CPU1
> >
> > |xgene_hwmon_evt_work
> > xgene_hwmon_remove |
> > kfifo_free(&ctx->async_msg_fifo);|
> > |
> > |kfifo_out_spinlocked
> > |//use &ctx->async_msg_fifo
> > Fixes: 2ca492e22cb7 ("hwmon: (xgene) Fix crash when alarm occurs before driver probe")
> > Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
>
> Applied.
>
Thanks for your effort.
Best regards,
Zheng
>
> > ---
> > drivers/hwmon/xgene-hwmon.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
> > index 5cde837bfd09..d1abea49f01b 100644
> > --- a/drivers/hwmon/xgene-hwmon.c
> > +++ b/drivers/hwmon/xgene-hwmon.c
> > @@ -761,6 +761,7 @@ static int xgene_hwmon_remove(struct platform_device *pdev)
> > {
> > struct xgene_hwmon_dev *ctx = platform_get_drvdata(pdev);
> >
> > + cancel_work_sync(&ctx->workq);
> > hwmon_device_unregister(ctx->hwmon_dev);
> > kfifo_free(&ctx->async_msg_fifo);
> > if (acpi_disabled)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-10 16:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 8:40 [PATCH] hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition Zheng Wang
2023-03-10 16:34 ` Guenter Roeck
2023-03-10 16:54 ` Zheng Hacker
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).