From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: Zheng Hacker <hackerzheng666@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: Zheng Wang <zyytlz.wz@163.com>,
Kyrie.Wu@mediatek.com, bin.liu@mediatek.com, mchehab@kernel.org,
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, Irui.Wang@mediatek.com,
security@kernel.org, 1395428693sheep@gmail.com,
alex000young@gmail.com,
Collabora Kernel ML <kernel@collabora.com>
Subject: Re: [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
Date: Tue, 19 Sep 2023 21:24:25 +0300 [thread overview]
Message-ID: <4d533beb-f416-1b22-6d9d-cee7f3cfdad1@collabora.com> (raw)
In-Reply-To: <CAJedcCyn+VHxcSXH+HqP3yiXX8L0wjNao+suti5GgyQzYORcYA@mail.gmail.com>
On 8/31/23 11:18, Zheng Hacker wrote:
>> The v4l2_m2m_ctx_release() already should wait for the job_timeout_work
>> completion or for the interrupt fire. Apparently it doesn't work in
>> yours case. You'll need to debug why v4l job or job_timeout_work is
>> running after v4l2_m2m_ctx_release(), it shouldn't happen.
>>
> Yes, v4l2_m2m_cancel_job waits for m2m_ctx->job_flags to be ~TRANS_RUNNING,
> the mtk_jpeg_job_timeout_work will finally invoke v4l2_m2m_job_finish
> to trigger that.
>
> However, this is not the only path to call v4l2_m2m_job_finish. Here
> is a invoking chain:
> v4l_streamon
> ->v4l2_m2m_ioctl_streamon
> ->v4l2_m2m_streamon
> ->v4l2_m2m_try_schedule
> ->v4l2_m2m_try_run
> ->mtk_jpeg_dec_device_run
> ->schedule_delayed_work(&jpeg->job_timeout_work...
> ->error path goto dec_end
> ->v4l2_m2m_job_finish
>
> In some specific situation, it starts the worker and also calls
> v4l2_m2m_job_finish, which might
> make v4l2_m2m_cancel_job continues.
Then the error path should cancel the job_timeout_work, or better job
needs to be run after the dec/enc has been started and not before.
Looking further at the code, I'm confused by this hunk:
mtk_jpeg_dec_start(comp_jpeg[hw_id]->reg_base);
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
The job should be marked as finished when h/w has finished processing
the job and not right after the job has been started. So the job is
always completed and mtk_jpeg_job_timeout_work() doesn't work as
expected, am I missing something?
--
Best regards,
Dmitry
WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: Zheng Hacker <hackerzheng666@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: Zheng Wang <zyytlz.wz@163.com>,
Kyrie.Wu@mediatek.com, bin.liu@mediatek.com, mchehab@kernel.org,
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, Irui.Wang@mediatek.com,
security@kernel.org, 1395428693sheep@gmail.com,
alex000young@gmail.com,
Collabora Kernel ML <kernel@collabora.com>
Subject: Re: [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work
Date: Tue, 19 Sep 2023 21:24:25 +0300 [thread overview]
Message-ID: <4d533beb-f416-1b22-6d9d-cee7f3cfdad1@collabora.com> (raw)
In-Reply-To: <CAJedcCyn+VHxcSXH+HqP3yiXX8L0wjNao+suti5GgyQzYORcYA@mail.gmail.com>
On 8/31/23 11:18, Zheng Hacker wrote:
>> The v4l2_m2m_ctx_release() already should wait for the job_timeout_work
>> completion or for the interrupt fire. Apparently it doesn't work in
>> yours case. You'll need to debug why v4l job or job_timeout_work is
>> running after v4l2_m2m_ctx_release(), it shouldn't happen.
>>
> Yes, v4l2_m2m_cancel_job waits for m2m_ctx->job_flags to be ~TRANS_RUNNING,
> the mtk_jpeg_job_timeout_work will finally invoke v4l2_m2m_job_finish
> to trigger that.
>
> However, this is not the only path to call v4l2_m2m_job_finish. Here
> is a invoking chain:
> v4l_streamon
> ->v4l2_m2m_ioctl_streamon
> ->v4l2_m2m_streamon
> ->v4l2_m2m_try_schedule
> ->v4l2_m2m_try_run
> ->mtk_jpeg_dec_device_run
> ->schedule_delayed_work(&jpeg->job_timeout_work...
> ->error path goto dec_end
> ->v4l2_m2m_job_finish
>
> In some specific situation, it starts the worker and also calls
> v4l2_m2m_job_finish, which might
> make v4l2_m2m_cancel_job continues.
Then the error path should cancel the job_timeout_work, or better job
needs to be run after the dec/enc has been started and not before.
Looking further at the code, I'm confused by this hunk:
mtk_jpeg_dec_start(comp_jpeg[hw_id]->reg_base);
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
The job should be marked as finished when h/w has finished processing
the job and not right after the job has been started. So the job is
always completed and mtk_jpeg_job_timeout_work() doesn't work as
expected, am I missing something?
--
Best regards,
Dmitry
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-09-19 18:24 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
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 9:24 ` Zheng Wang
2023-07-07 14:11 ` Alexandre Mergnat
2023-07-07 14:11 ` Alexandre Mergnat
2023-07-15 16:08 ` Zheng Hacker
2023-07-15 16:08 ` Zheng Hacker
2023-07-18 3:07 ` Zheng Hacker
2023-07-18 3:07 ` Zheng Hacker
2023-07-19 10:17 ` Alexandre Mergnat
2023-07-19 10:17 ` Alexandre Mergnat
2023-07-20 3:17 ` Zheng Hacker
2023-07-20 3:17 ` Zheng Hacker
2023-07-20 3:40 ` Chen-Yu Tsai
2023-07-20 3:40 ` Chen-Yu Tsai
2023-07-20 7:45 ` AngeloGioacchino Del Regno
2023-07-20 7:45 ` AngeloGioacchino Del Regno
2023-07-25 2:39 ` Zheng Hacker
2023-08-22 18:51 ` Dmitry Osipenko
2023-08-22 18:51 ` Dmitry Osipenko
2023-08-24 8:20 ` Zheng Hacker
2023-08-24 8:20 ` Zheng Hacker
2023-08-28 2:04 ` Dmitry Osipenko
2023-08-28 2:04 ` Dmitry Osipenko
2023-08-31 8:18 ` Zheng Hacker
2023-08-31 8:18 ` Zheng Hacker
2023-09-05 4:24 ` Zheng Hacker
2023-09-05 4:24 ` Zheng Hacker
2023-09-12 9:29 ` Zheng Hacker
2023-09-12 9:29 ` Zheng Hacker
2023-09-19 18:24 ` Dmitry Osipenko [this message]
2023-09-19 18:24 ` Dmitry Osipenko
2023-09-19 18:25 ` Dmitry Osipenko
2023-09-19 18:25 ` Dmitry Osipenko
2023-10-08 9:13 ` Zheng Hacker
2023-10-08 9:13 ` Zheng Hacker
2023-10-19 19:56 ` Dmitry Osipenko
2023-10-19 19:56 ` Dmitry Osipenko
2023-10-20 2:51 ` Zheng Hacker
2023-10-20 2:51 ` 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
2023-10-11 7:32 Zheng Wang
2023-10-12 17:23 ` Greg KH
2023-10-15 10:32 ` Zheng Hacker
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=4d533beb-f416-1b22-6d9d-cee7f3cfdad1@collabora.com \
--to=dmitry.osipenko@collabora.com \
--cc=1395428693sheep@gmail.com \
--cc=Irui.Wang@mediatek.com \
--cc=Kyrie.Wu@mediatek.com \
--cc=alex000young@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bin.liu@mediatek.com \
--cc=hackerzheng666@gmail.com \
--cc=kernel@collabora.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 \
--cc=security@kernel.org \
--cc=zyytlz.wz@163.com \
/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: link
Be 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.