public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
* [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
@ 2023-07-07  9:24 Zheng Wang
  2023-07-07 14:11 ` Alexandre Mergnat
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Zheng Wang @ 2023-07-07  9:24 UTC (permalink / raw)
  To: Kyrie.Wu
  Cc: bin.liu, mchehab, matthias.bgg, angelogioacchino.delregno,
	linux-media, linux-kernel, linux-arm-kernel, linux-mediatek,
	Irui.Wang, security, hackerzheng666, 1395428693sheep,
	alex000young, Zheng Wang

In mtk_jpeg_probe, &jpeg->job_timeout_work is bound with
mtk_jpeg_job_timeout_work. Then mtk_jpeg_dec_device_run
and mtk_jpeg_enc_device_run may be called to start the
work.
If we remove the module which will call mtk_jpeg_remove
to make cleanup, there may be a unfinished work. The
possible sequence is as follows, which will cause a
typical UAF bug.

Fix it by canceling the work before cleanup in the mtk_jpeg_remove

CPU0                  CPU1

                    |mtk_jpeg_job_timeout_work
mtk_jpeg_remove     |
  v4l2_m2m_release  |
    kfree(m2m_dev); |
                    |
                    | v4l2_m2m_get_curr_priv
                    |   m2m_dev->curr_ctx //use
Fixes: b2f0d2724ba4 ("[media] vcodec: mediatek: Add Mediatek JPEG Decoder Driver")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
- v2: use cancel_delayed_work_sync instead of cancel_delayed_work suggested by Kyrie.
---
 drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 0051f372a66c..6069ecf420b0 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1816,6 +1816,7 @@ static void mtk_jpeg_remove(struct platform_device *pdev)
 {
 	struct mtk_jpeg_dev *jpeg = platform_get_drvdata(pdev);
 
+	cancel_delayed_work_sync(&jpeg->job_timeout_work);
 	pm_runtime_disable(&pdev->dev);
 	video_unregister_device(jpeg->vdev);
 	v4l2_m2m_release(jpeg->m2m_dev);
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2023-10-20  2:51 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-07  9:24 [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work Zheng Wang
2023-07-07 14:11 ` Alexandre Mergnat
2023-07-15 16:08   ` Zheng Hacker
2023-07-18  3:07     ` Zheng Hacker
2023-07-19 10:17       ` Alexandre Mergnat
2023-07-20  3:17         ` Zheng Hacker
2023-07-20  3:40 ` Chen-Yu Tsai
2023-07-20  7:45 ` AngeloGioacchino Del Regno
2023-07-25  2:39   ` Zheng Hacker
2023-08-22 18:51 ` Dmitry Osipenko
2023-08-24  8:20   ` Zheng Hacker
2023-08-28  2:04     ` Dmitry Osipenko
2023-08-31  8:18       ` Zheng Hacker
2023-09-05  4:24         ` Zheng Hacker
2023-09-12  9:29           ` Zheng Hacker
2023-09-19 18:24         ` Dmitry Osipenko
2023-09-19 18:25           ` Dmitry Osipenko
2023-10-08  9:13           ` Zheng Hacker
2023-10-19 19:56             ` Dmitry Osipenko
2023-10-20  2:51               ` Zheng Hacker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox