2023-09-15 11:40:22

by Ma Ke

[permalink] [raw]
Subject: [PATCH] media: verisilicon: fix use after free bug in hantro_remove due to race condition

In hantro_probe, vpu->watchdog_work is bound with hantro_watchdog function. In
hantro_end_prepare_run, it will started by schedule_delayed_work. If there is an
unfinished work in hantro_remove, there may be a race condition and trigger UAF
bug.

Signed-off-by: Ma Ke <[email protected]>
---
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 423fc85d79ee..1a5b3a85c520 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -1187,6 +1187,7 @@ static void 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.37.2


2023-09-15 18:51:00

by Ezequiel Garcia

[permalink] [raw]
Subject: Re: [PATCH] media: verisilicon: fix use after free bug in hantro_remove due to race condition

Hi Ma,

This was already discussed:

https://patchwork.kernel.org/project/linux-media/patch/[email protected]/

Thanks,
Ezequiel

On Fri, Sep 15, 2023 at 8:51 AM Ma Ke <[email protected]> wrote:
>
> In hantro_probe, vpu->watchdog_work is bound with hantro_watchdog function. In
> hantro_end_prepare_run, it will started by schedule_delayed_work. If there is an
> unfinished work in hantro_remove, there may be a race condition and trigger UAF
> bug.
>
> Signed-off-by: Ma Ke <[email protected]>
> ---
> 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 423fc85d79ee..1a5b3a85c520 100644
> --- a/drivers/media/platform/verisilicon/hantro_drv.c
> +++ b/drivers/media/platform/verisilicon/hantro_drv.c
> @@ -1187,6 +1187,7 @@ static void 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.37.2
>