hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition
authorZheng Wang <zyytlz.wz@163.com>
Fri, 10 Mar 2023 08:40:07 +0000 (16:40 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 12 Mar 2023 18:13:25 +0000 (11:13 -0700)
commitcb090e64cf25602b9adaf32d5dfc9c8bec493cd1
treeed7617f114d00d6be710a8dc48296a885208aa2e
parent48e8186870d9d0902e712d601ccb7098cb220688
hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition

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>
drivers/hwmon/xgene-hwmon.c