]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: mtk-jpeg: Fix use after free bug due to uncanceled work
authorZheng Wang <zyytlz.wz@163.com>
Fri, 7 Jul 2023 09:24:14 +0000 (17:24 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Oct 2023 21:05:35 +0000 (23:05 +0200)
commit c677d7ae83141d390d1253abebafa49c962afb52 upstream.

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>
Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c

index 470f8f167744845a104fd17e5e849be5cacf7452..bc84274ba87aa01082d7a18fbbba15cd9c8bf44d 100644 (file)
@@ -1455,6 +1455,7 @@ static int 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);