* [PATCH v2] media: hantro: fix use after free bug in hantro_remove due to race condition
@ 2023-03-13 15:19 Zheng Wang
0 siblings, 0 replies; only message in thread
From: Zheng Wang @ 2023-03-13 15:19 UTC (permalink / raw)
To: ezequiel
Cc: p.zabel, mchehab, linux-media, linux-rockchip, linux-kernel,
hackerzheng666, 1395428693sheep, alex000young, hverkuil,
Zheng Wang
In hantro_probe, vpu->watchdog_work is bound with
hantro_watchdog. Then hantro_end_prepare_run may
be called to start the work.
If we remove the module which will call hantro_remove
to make cleanup, there may be an unfinished work.
The possible sequence is as follows, which will
cause a typical UAF bug.
Fix it by canceling the work before cleanup in hantro_remove.
CPU0 CPU1
|hantro_watchdog
hantro_remove |
v4l2_m2m_release |
kfree(m2m_dev); |
|
| v4l2_m2m_get_curr_priv
| m2m_dev->curr_ctx //use
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
v2:
- move the cancel-work-related code to hantro_remove suggested by Hans Verkuil
---
drivers/media/platform/verisilicon/hantro_drv.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
index b0aeedae7b65..496024b21b51 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -1099,6 +1099,7 @@ static int hantro_remove(struct platform_device *pdev)
v4l2_info(&vpu->v4l2_dev, "Removing %s\n", pdev->name);
+ cancel_delayed_work_sync(&vpu->watchdog_work);
media_device_unregister(&vpu->mdev);
hantro_remove_dec_func(vpu);
hantro_remove_enc_func(vpu);
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-13 15:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13 15:19 [PATCH v2] media: hantro: fix use after free bug in hantro_remove due to race condition Zheng Wang
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).