From: Zheng Wang <zyytlz.wz@163.com> To: ezequiel@vanguardiasur.com.ar Cc: p.zabel@pengutronix.de, mchehab@kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, hverkuil@xs4all.nl, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH v2] media: hantro: fix use after free bug in hantro_remove due to race condition Date: Mon, 13 Mar 2023 23:19:09 +0800 [thread overview] Message-ID: <20230313151909.3658925-1-zyytlz.wz@163.com> (raw) In hantro_probe, vpu->watchdog_work is bound with hantro_watchdog. Then hantro_end_prepare_run may be called to start the work. If we remove the module which will call hantro_remove to make cleanup, there may be an unfinished work. The possible sequence is as follows, which will cause a typical UAF bug. Fix it by canceling the work before cleanup in hantro_remove. CPU0 CPU1 |hantro_watchdog hantro_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> --- v2: - move the cancel-work-related code to hantro_remove suggested by Hans Verkuil --- drivers/media/platform/verisilicon/hantro_drv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index b0aeedae7b65..496024b21b51 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -1099,6 +1099,7 @@ static int hantro_remove(struct platform_device *pdev) v4l2_info(&vpu->v4l2_dev, "Removing %s\n", pdev->name); + cancel_delayed_work_sync(&vpu->watchdog_work); media_device_unregister(&vpu->mdev); hantro_remove_dec_func(vpu); hantro_remove_enc_func(vpu); -- 2.25.1 _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip
WARNING: multiple messages have this Message-ID (diff)
From: Zheng Wang <zyytlz.wz@163.com> To: ezequiel@vanguardiasur.com.ar Cc: p.zabel@pengutronix.de, mchehab@kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, hverkuil@xs4all.nl, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH v2] media: hantro: fix use after free bug in hantro_remove due to race condition Date: Mon, 13 Mar 2023 23:19:09 +0800 [thread overview] Message-ID: <20230313151909.3658925-1-zyytlz.wz@163.com> (raw) In hantro_probe, vpu->watchdog_work is bound with hantro_watchdog. Then hantro_end_prepare_run may be called to start the work. If we remove the module which will call hantro_remove to make cleanup, there may be an unfinished work. The possible sequence is as follows, which will cause a typical UAF bug. Fix it by canceling the work before cleanup in hantro_remove. CPU0 CPU1 |hantro_watchdog hantro_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> --- v2: - move the cancel-work-related code to hantro_remove suggested by Hans Verkuil --- drivers/media/platform/verisilicon/hantro_drv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index b0aeedae7b65..496024b21b51 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -1099,6 +1099,7 @@ static int hantro_remove(struct platform_device *pdev) v4l2_info(&vpu->v4l2_dev, "Removing %s\n", pdev->name); + cancel_delayed_work_sync(&vpu->watchdog_work); media_device_unregister(&vpu->mdev); hantro_remove_dec_func(vpu); hantro_remove_enc_func(vpu); -- 2.25.1
next reply other threads:[~2023-03-13 15:19 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-13 15:19 Zheng Wang [this message] 2023-03-13 15:19 ` [PATCH v2] media: hantro: fix use after free bug in hantro_remove due to race condition 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=20230313151909.3658925-1-zyytlz.wz@163.com \ --to=zyytlz.wz@163.com \ --cc=1395428693sheep@gmail.com \ --cc=alex000young@gmail.com \ --cc=ezequiel@vanguardiasur.com.ar \ --cc=hackerzheng666@gmail.com \ --cc=hverkuil@xs4all.nl \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-media@vger.kernel.org \ --cc=linux-rockchip@lists.infradead.org \ --cc=mchehab@kernel.org \ --cc=p.zabel@pengutronix.de \ /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.