From: Zheng Wang Date: Fri, 10 Mar 2023 08:40:07 +0000 (+0800) Subject: hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition X-Git-Tag: baikal/mips/sdk6.1~108 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=c53e796605304158314b1dd9000df0116a501c8f;p=kernel.git hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition [ Upstream commit 9e728fdb4526ea1b4679b4fefa1bc551b414fedc ] 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 clean up, there may be unfinished work. The possible sequence is as follows: Fix it by finishing the work before cleanup in 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: d99fa72f98cb ("hwmon: (xgene) Fix crash when alarm occurs before driver probe") Signed-off-by: Zheng Wang Link: https://lore.kernel.org/r/20230310084007.1403388-1-zyytlz.wz@163.com Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c index 5cde837bfd094..d1abea49f01be 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)