From: Zheng Wang <zyytlz.wz@163.com> To: mchehab@kernel.org Cc: bin.liu@mediatek.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH] media: mtk-jpeg: Fix use after free bug due to uncanceled work Date: Thu, 2 Mar 2023 17:37:15 +0800 [thread overview] Message-ID: <20230302093715.811758-1-zyytlz.wz@163.com> (raw) 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
WARNING: multiple messages have this Message-ID (diff)
From: Zheng Wang <zyytlz.wz@163.com> To: mchehab@kernel.org Cc: bin.liu@mediatek.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH] media: mtk-jpeg: Fix use after free bug due to uncanceled work Date: Thu, 2 Mar 2023 17:37:15 +0800 [thread overview] Message-ID: <20230302093715.811758-1-zyytlz.wz@163.com> (raw) 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
next reply other threads:[~2023-03-02 9:38 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-02 9:37 Zheng Wang [this message] 2023-03-02 9:37 ` [PATCH] media: mtk-jpeg: Fix use after free bug due to uncanceled work Zheng Wang 2023-03-09 0:27 ` Guenter Roeck 2023-03-09 0:27 ` Guenter Roeck 2023-03-09 3:58 ` Zheng Hacker 2023-03-09 3:58 ` Zheng Hacker 2023-03-09 5:30 ` Guenter Roeck 2023-03-09 5:30 ` Guenter Roeck 2023-03-09 7:18 ` Zheng Hacker 2023-03-09 7:18 ` Zheng Hacker 2023-10-15 14:42 Zheng Wang 2023-10-15 14:53 ` Zheng Hacker 2023-10-15 14:47 Zheng Wang 2023-10-15 17:48 ` Greg KH 2023-10-15 14:50 Zheng Wang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230302093715.811758-1-zyytlz.wz@163.com \ --to=zyytlz.wz@163.com \ --cc=1395428693sheep@gmail.com \ --cc=alex000young@gmail.com \ --cc=angelogioacchino.delregno@collabora.com \ --cc=bin.liu@mediatek.com \ --cc=hackerzheng666@gmail.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-media@vger.kernel.org \ --cc=linux-mediatek@lists.infradead.org \ --cc=matthias.bgg@gmail.com \ --cc=mchehab@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.