Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
@ 2023-10-11  3:17 Zheng Wang
  2023-10-11  4:51 ` kernel test robot
  0 siblings, 1 reply; 5+ messages in thread
From: Zheng Wang @ 2023-10-11  3:17 UTC (permalink / raw)
  To: stable
  Cc: hackerzheng666, sashal, gregkh, patches, amergnat, wenst,
	angelogioacchino.delregno, hverkuil-cisco, Zheng Wang

This is a security bug that has been reported to google.
It affected all platforms on chrome-os. Please apply this
patch to 4.14 4.19 5.4 5.10 and 5.15.

[ Upstream commit c677d7ae83141d390d1253abebafa49c962afb52 ]

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: Sasha Levin <sashal@kernel.org>
---
- 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] 5+ messages in thread

* Re: [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
  2023-10-11  3:17 Zheng Wang
@ 2023-10-11  4:51 ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2023-10-11  4:51 UTC (permalink / raw)
  To: Zheng Wang; +Cc: stable, oe-kbuild-all

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Rule: add the tag "Cc: stable@vger.kernel.org" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
Link: https://lore.kernel.org/stable/20231011031740.982735-1-zyytlz.wz%40163.com

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki




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

* [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
@ 2023-10-11  7:32 Zheng Wang
  2023-10-12 17:23 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Zheng Wang @ 2023-10-11  7:32 UTC (permalink / raw)
  To: stable
  Cc: hackerzheng666, sashal, gregkh, patches, amergnat, wenst,
	angelogioacchino.delregno, hverkuil-cisco, Zheng Wang

This is a security bug that has been reported to google.
It affected all platforms on chrome-os. Please apply this
patch to 4.14 4.19 5.4 5.10 and 5.15.

[ Upstream commit c677d7ae83141d390d1253abebafa49c962afb52 ]

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: Sasha Levin <sashal@kernel.org>
Cc: stable@vger.kernel.org
---
- 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] 5+ messages in thread

* Re: [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
  2023-10-11  7:32 [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work Zheng Wang
@ 2023-10-12 17:23 ` Greg KH
  2023-10-15 10:32   ` Zheng Hacker
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2023-10-12 17:23 UTC (permalink / raw)
  To: Zheng Wang
  Cc: stable, hackerzheng666, sashal, patches, amergnat, wenst,
	angelogioacchino.delregno, hverkuil-cisco

On Wed, Oct 11, 2023 at 03:32:04PM +0800, Zheng Wang wrote:
> This is a security bug that has been reported to google.
> It affected all platforms on chrome-os. Please apply this
> patch to 4.14 4.19 5.4 5.10 and 5.15.
> 
> [ Upstream commit c677d7ae83141d390d1253abebafa49c962afb52 ]

Did you try to apply this?  The file:

>  drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 1 +

Is not in the kernels you asked for this patch to be applied to.

How did you test this?

confused,

greg k-h

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

* Re: [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
  2023-10-12 17:23 ` Greg KH
@ 2023-10-15 10:32   ` Zheng Hacker
  0 siblings, 0 replies; 5+ messages in thread
From: Zheng Hacker @ 2023-10-15 10:32 UTC (permalink / raw)
  To: Greg KH
  Cc: Zheng Wang, stable, sashal, patches, amergnat, wenst,
	angelogioacchino.delregno, hverkuil-cisco

Greg KH <gregkh@linuxfoundation.org> 于2023年10月13日周五 01:23写道:

>
> On Wed, Oct 11, 2023 at 03:32:04PM +0800, Zheng Wang wrote:
> > This is a security bug that has been reported to google.
> > It affected all platforms on chrome-os. Please apply this
> > patch to 4.14 4.19 5.4 5.10 and 5.15.
> >
> > [ Upstream commit c677d7ae83141d390d1253abebafa49c962afb52 ]
>
> Did you try to apply this?  The file:
>
> >  drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 1 +
>
> Is not in the kernels you asked for this patch to be applied to.

Sorry I did't check the file. After reviewing the code, I found the
Directory Structure has been changed.
I'll write another patch for them.

Best Regards,
Zheng Wang
>
> How did you test this?
>
> confused,
>
> greg k-h

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

end of thread, other threads:[~2023-10-15 10:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11  7:32 [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work Zheng Wang
2023-10-12 17:23 ` Greg KH
2023-10-15 10:32   ` Zheng Hacker
  -- strict thread matches above, loose matches on Subject: below --
2023-10-11  3:17 Zheng Wang
2023-10-11  4:51 ` kernel test robot

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