* [PATCH v2] media: cedrus: fix use after free bug in cedrus_remove due to race condition
@ 2023-03-13 16:31 Zheng Wang
2023-03-14 19:53 ` Jernej Škrabec
0 siblings, 1 reply; 3+ messages in thread
From: Zheng Wang @ 2023-03-13 16:31 UTC (permalink / raw)
To: mchehab
Cc: hverkuil, wens, jernej.skrabec, samuel, linux-media,
linux-staging, linux-arm-kernel, linux-sunxi, linux-kernel,
hackerzheng666, 1395428693sheep, alex000young, Zheng Wang
In cedrus_probe, dev->watchdog_work is bound with cedrus_watchdog function.
In cedrus_device_run, it will started by schedule_delayed_work. If there is
an unfinished work in cedrus_remove, there may be a race condition and
trigger UAF bug.
CPU0 CPU1
|cedrus_watchdog
cedrus_remove |
v4l2_m2m_release |
kfree(m2m_dev) |
|
| v4l2_m2m_get_curr_priv
| m2m_dev //use
Fix it by canceling the worker in cedrus_remove.
Fixes: 7c38a551bda1 ("media: cedrus: Add watchdog for job completion")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
v2:
- use cancel_delayed_work_sync instead and add Fixes
label suggested by Hans Verkuil
---
drivers/staging/media/sunxi/cedrus/cedrus.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c b/drivers/staging/media/sunxi/cedrus/cedrus.c
index a43d5ff66716..a50a4d0a8f71 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus.c
@@ -547,6 +547,7 @@ static int cedrus_remove(struct platform_device *pdev)
{
struct cedrus_dev *dev = platform_get_drvdata(pdev);
+ cancel_delayed_work_sync(&dev->watchdog_work);
if (media_devnode_is_registered(dev->mdev.devnode)) {
media_device_unregister(&dev->mdev);
v4l2_m2m_unregister_media_controller(dev->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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] media: cedrus: fix use after free bug in cedrus_remove due to race condition
2023-03-13 16:31 [PATCH v2] media: cedrus: fix use after free bug in cedrus_remove due to race condition Zheng Wang
@ 2023-03-14 19:53 ` Jernej Škrabec
2023-03-15 8:59 ` Zheng Hacker
0 siblings, 1 reply; 3+ messages in thread
From: Jernej Škrabec @ 2023-03-14 19:53 UTC (permalink / raw)
To: mchehab, Zheng Wang
Cc: hverkuil, wens, samuel, linux-media, linux-staging,
linux-arm-kernel, linux-sunxi, linux-kernel, hackerzheng666,
1395428693sheep, alex000young, Zheng Wang
Dne ponedeljek, 13. marec 2023 ob 17:31:20 CET je Zheng Wang napisal(a):
> In cedrus_probe, dev->watchdog_work is bound with cedrus_watchdog function.
> In cedrus_device_run, it will started by schedule_delayed_work. If there is
> an unfinished work in cedrus_remove, there may be a race condition and
> trigger UAF bug.
>
> CPU0 CPU1
>
> |cedrus_watchdog
>
> cedrus_remove |
> v4l2_m2m_release |
> kfree(m2m_dev) |
>
> | v4l2_m2m_get_curr_priv
> |
> | m2m_dev //use
>
> Fix it by canceling the worker in cedrus_remove.
>
> Fixes: 7c38a551bda1 ("media: cedrus: Add watchdog for job completion")
> Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> ---
> v2:
> - use cancel_delayed_work_sync instead and add Fixes
> label suggested by Hans Verkuil
> ---
> drivers/staging/media/sunxi/cedrus/cedrus.c | 1 +
> 1 file changed, 1 insertion(+)
>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Best regards,
Jernej
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c
> b/drivers/staging/media/sunxi/cedrus/cedrus.c index
> a43d5ff66716..a50a4d0a8f71 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus.c
> @@ -547,6 +547,7 @@ static int cedrus_remove(struct platform_device *pdev)
> {
> struct cedrus_dev *dev = platform_get_drvdata(pdev);
>
> + cancel_delayed_work_sync(&dev->watchdog_work);
> if (media_devnode_is_registered(dev->mdev.devnode)) {
> media_device_unregister(&dev->mdev);
> v4l2_m2m_unregister_media_controller(dev->m2m_dev);
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] media: cedrus: fix use after free bug in cedrus_remove due to race condition
2023-03-14 19:53 ` Jernej Škrabec
@ 2023-03-15 8:59 ` Zheng Hacker
0 siblings, 0 replies; 3+ messages in thread
From: Zheng Hacker @ 2023-03-15 8:59 UTC (permalink / raw)
To: Jernej Škrabec
Cc: mchehab, Zheng Wang, hverkuil, wens, samuel, linux-media,
linux-staging, linux-arm-kernel, linux-sunxi, linux-kernel,
1395428693sheep, alex000young
Jernej Škrabec <jernej.skrabec@gmail.com> 于2023年3月15日周三 03:53写道:
>
> Dne ponedeljek, 13. marec 2023 ob 17:31:20 CET je Zheng Wang napisal(a):
> > In cedrus_probe, dev->watchdog_work is bound with cedrus_watchdog function.
> > In cedrus_device_run, it will started by schedule_delayed_work. If there is
> > an unfinished work in cedrus_remove, there may be a race condition and
> > trigger UAF bug.
> >
> > CPU0 CPU1
> >
> > |cedrus_watchdog
> >
> > cedrus_remove |
> > v4l2_m2m_release |
> > kfree(m2m_dev) |
> >
> > | v4l2_m2m_get_curr_priv
> > |
> > | m2m_dev //use
> >
> > Fix it by canceling the worker in cedrus_remove.
> >
> > Fixes: 7c38a551bda1 ("media: cedrus: Add watchdog for job completion")
> > Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> > ---
> > v2:
> > - use cancel_delayed_work_sync instead and add Fixes
> > label suggested by Hans Verkuil
> > ---
> > drivers/staging/media/sunxi/cedrus/cedrus.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
>
> Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
>
Thanks for your review.
Best regards,
Zheng
> Best regards,
> Jernej
>
> > diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c
> > b/drivers/staging/media/sunxi/cedrus/cedrus.c index
> > a43d5ff66716..a50a4d0a8f71 100644
> > --- a/drivers/staging/media/sunxi/cedrus/cedrus.c
> > +++ b/drivers/staging/media/sunxi/cedrus/cedrus.c
> > @@ -547,6 +547,7 @@ static int cedrus_remove(struct platform_device *pdev)
> > {
> > struct cedrus_dev *dev = platform_get_drvdata(pdev);
> >
> > + cancel_delayed_work_sync(&dev->watchdog_work);
> > if (media_devnode_is_registered(dev->mdev.devnode)) {
> > media_device_unregister(&dev->mdev);
> > v4l2_m2m_unregister_media_controller(dev->m2m_dev);
>
>
>
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-15 9:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-13 16:31 [PATCH v2] media: cedrus: fix use after free bug in cedrus_remove due to race condition Zheng Wang
2023-03-14 19:53 ` Jernej Škrabec
2023-03-15 8:59 ` Zheng Hacker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).