summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZheng Wang <zyytlz.wz@163.com>2023-03-10 11:40:07 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-03-22 15:28:07 +0300
commit26c176ce902861a45f8d699e057245ed7e0bcdf2 (patch)
treecb5cc2dbc0037e9120a8c0139bb7ef2d4d1d9eb0
parent13efd488d398d9858380fbb4df628c858464aae4 (diff)
downloadlinux-26c176ce902861a45f8d699e057245ed7e0bcdf2.tar.xz
hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition
[ Upstream commit cb090e64cf25602b9adaf32d5dfc9c8bec493cd1 ] 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: 2ca492e22cb7 ("hwmon: (xgene) Fix crash when alarm occurs before driver probe") Signed-off-by: Zheng Wang <zyytlz.wz@163.com> Link: https://lore.kernel.org/r/20230310084007.1403388-1-zyytlz.wz@163.com Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/hwmon/xgene-hwmon.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
index f2a5af239c95..f5d3cf86753f 100644
--- a/drivers/hwmon/xgene-hwmon.c
+++ b/drivers/hwmon/xgene-hwmon.c
@@ -768,6 +768,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)