Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH] media: mtk-jpeg: Fix use after free bug due to uncanceled work
@ 2023-03-06  6:26 Zheng Wang
  2023-03-07  9:27 ` Zheng Hacker
  0 siblings, 1 reply; 19+ messages in thread
From: Zheng Wang @ 2023-03-06  6:26 UTC (permalink / raw)
  To: mchehab
  Cc: bin.liu, matthias.bgg, angelogioacchino.delregno, linux-media,
	linux-kernel, linux-arm-kernel, linux-mediatek, 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

Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 969516a940ba..364513e7897e 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1793,7 +1793,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
 static int mtk_jpeg_remove(struct platform_device *pdev)
 {
 	struct mtk_jpeg_dev *jpeg = platform_get_drvdata(pdev);
-
+	cancel_delayed_work(&jpeg->job_timeout_work);
 	pm_runtime_disable(&pdev->dev);
 	video_unregister_device(jpeg->vdev);
 	v4l2_m2m_release(jpeg->m2m_dev);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-06-25  2:39 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-06  6:26 [RESEND PATCH] media: mtk-jpeg: Fix use after free bug due to uncanceled work Zheng Wang
2023-03-07  9:27 ` Zheng Hacker
2023-03-07  9:49   ` AngeloGioacchino Del Regno
2023-03-07 10:12     ` Irui Wang (王瑞)
2023-03-07 15:03       ` Zheng Hacker
2023-03-08  1:41         ` Kyrie Wu (吴晗)
2023-03-08  2:20           ` Zheng Hacker
2023-03-08  3:32             ` Kyrie Wu (吴晗)
2023-03-08  4:32               ` Zheng Hacker
2023-03-08  6:10               ` Zheng Hacker
2023-03-08  7:38                 ` Kyrie Wu (吴晗)
2023-03-08  9:11                   ` Zheng Hacker
2023-03-09  7:31                     ` Zheng Hacker
2023-03-14  2:49                       ` Kyrie Wu (吴晗)
2023-03-14  3:37                         ` Zheng Hacker
     [not found]                           ` <94ff8d75d88c7ab356949ad319c3085e45ac2488.camel@mediatek.com>
     [not found]                             ` <CAJedcCwgVTLJsYTncnt5ab6yAqbrJ7oGf9Ftak1vCoemeQz16w@mail.gmail.com>
2023-06-15  2:40                               ` Kyrie Wu (吴晗)
2023-06-15  2:58                                 ` Zheng Hacker
2023-06-25  2:38                                   ` Zheng Hacker
2023-03-07 14:59   ` Zheng Hacker

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