linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] media:exynos4-is: Fix a use after free in isp_video_release
@ 2021-04-27  6:02 Lv Yunlong
  2021-04-27 10:36 ` Sylwester Nawrocki
  0 siblings, 1 reply; 3+ messages in thread
From: Lv Yunlong @ 2021-04-27  6:02 UTC (permalink / raw)
  To: s.nawrocki, mchehab, krzk
  Cc: linux-media, linux-arm-kernel, linux-samsung-soc, linux-kernel,
	Lv Yunlong

In isp_video_release, file->private_data is freed via
_vb2_fop_release()->v4l2_fh_release(). But the freed
file->private_data is still used in v4l2_fh_is_singular_file()
->v4l2_fh_is_singular(file->private_data), which is a use
after free bug.

My patch set file->private_data to NULL after _vb2_fop_release()
to avoid the use after free.

Fixes: 34947b8aebe3f ("[media] exynos4-is: Add the FIMC-IS ISP capture DMA driver")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 drivers/media/platform/exynos4-is/fimc-isp-video.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 612b9872afc8..2e04589068b4 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -315,7 +315,8 @@ static int isp_video_release(struct file *file)
 	}
 
 	_vb2_fop_release(file, NULL);
-
+	file->private_data = NULL;
+
 	if (v4l2_fh_is_singular_file(file)) {
 		fimc_pipeline_call(&ivc->ve, close);
 
-- 
2.25.1



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

* Re: [PATCH v2] media:exynos4-is: Fix a use after free in isp_video_release
  2021-04-27  6:02 [PATCH v2] media:exynos4-is: Fix a use after free in isp_video_release Lv Yunlong
@ 2021-04-27 10:36 ` Sylwester Nawrocki
  2021-04-27 13:29   ` lyl2019
  0 siblings, 1 reply; 3+ messages in thread
From: Sylwester Nawrocki @ 2021-04-27 10:36 UTC (permalink / raw)
  To: Lv Yunlong
  Cc: linux-media, linux-arm-kernel, linux-samsung-soc, linux-kernel,
	s.nawrocki, mchehab, krzk

On 27.04.2021 08:02, Lv Yunlong wrote:
> In isp_video_release, file->private_data is freed via
> _vb2_fop_release()->v4l2_fh_release(). But the freed
> file->private_data is still used in v4l2_fh_is_singular_file()
> ->v4l2_fh_is_singular(file->private_data), which is a use
> after free bug.
> 
> My patch set file->private_data to NULL after _vb2_fop_release()
> to avoid the use after free.
> 
> Fixes: 34947b8aebe3f ("[media] exynos4-is: Add the FIMC-IS ISP capture DMA driver")
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> ---
>   drivers/media/platform/exynos4-is/fimc-isp-video.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 612b9872afc8..2e04589068b4 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -315,7 +315,8 @@ static int isp_video_release(struct file *file)
>   	}
>   
>   	_vb2_fop_release(file, NULL);
> -
> +	file->private_data = NULL;

>   	if (v4l2_fh_is_singular_file(file)) {
>   		fimc_pipeline_call(&ivc->ve, close);
>   

Thank you for the patch. To ensure the pipeline stop call is done
only when the last file handle is released we would need something
as below.

--------8<---------
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c 
b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 612b9872afc8..3335fec509cb 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -306,17 +306,20 @@ static int isp_video_release(struct file *file)
         struct fimc_is_video *ivc = &isp->video_capture;
         struct media_entity *entity = &ivc->ve.vdev.entity;
         struct media_device *mdev = entity->graph_obj.mdev;
+       bool is_singular_file;

         mutex_lock(&isp->video_lock);

-       if (v4l2_fh_is_singular_file(file) && ivc->streaming) {
+       is_singular_file = v4l2_fh_is_singular_file(file);
+
+       if (is_singular_file && ivc->streaming) {
                 media_pipeline_stop(entity);
                 ivc->streaming = 0;
         }

         _vb2_fop_release(file, NULL);

-       if (v4l2_fh_is_singular_file(file)) {
+       if (is_singular_file) {
                 fimc_pipeline_call(&ivc->ve, close);

                 mutex_lock(&mdev->graph_mutex);
--------8<---------

Regards,
Sylwester

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

* Re: Re: [PATCH v2] media:exynos4-is: Fix a use after free in isp_video_release
  2021-04-27 10:36 ` Sylwester Nawrocki
@ 2021-04-27 13:29   ` lyl2019
  0 siblings, 0 replies; 3+ messages in thread
From: lyl2019 @ 2021-04-27 13:29 UTC (permalink / raw)
  To: Sylwester Nawrocki
  Cc: linux-media, linux-arm-kernel, linux-samsung-soc, linux-kernel,
	s.nawrocki, mchehab, krzk




> -----原始邮件-----
> 发件人: "Sylwester Nawrocki" <snawrocki@kernel.org>
> 发送时间: 2021-04-27 18:36:48 (星期二)
> 收件人: "Lv Yunlong" <lyl2019@mail.ustc.edu.cn>
> 抄送: linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, s.nawrocki@samsung.com, mchehab@kernel.org, krzk@kernel.org
> 主题: Re: [PATCH v2] media:exynos4-is: Fix a use after free in isp_video_release
> 
> On 27.04.2021 08:02, Lv Yunlong wrote:
> > In isp_video_release, file->private_data is freed via
> > _vb2_fop_release()->v4l2_fh_release(). But the freed
> > file->private_data is still used in v4l2_fh_is_singular_file()
> > ->v4l2_fh_is_singular(file->private_data), which is a use
> > after free bug.
> > 
> > My patch set file->private_data to NULL after _vb2_fop_release()
> > to avoid the use after free.
> > 
> > Fixes: 34947b8aebe3f ("[media] exynos4-is: Add the FIMC-IS ISP capture DMA driver")
> > Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> > ---
> >   drivers/media/platform/exynos4-is/fimc-isp-video.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > index 612b9872afc8..2e04589068b4 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -315,7 +315,8 @@ static int isp_video_release(struct file *file)
> >   	}
> >   
> >   	_vb2_fop_release(file, NULL);
> > -
> > +	file->private_data = NULL;
> 
> >   	if (v4l2_fh_is_singular_file(file)) {
> >   		fimc_pipeline_call(&ivc->ve, close);
> >   
> 
> Thank you for the patch. To ensure the pipeline stop call is done
> only when the last file handle is released we would need something
> as below.
> 
> --------8<---------
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c 
> b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 612b9872afc8..3335fec509cb 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -306,17 +306,20 @@ static int isp_video_release(struct file *file)
>          struct fimc_is_video *ivc = &isp->video_capture;
>          struct media_entity *entity = &ivc->ve.vdev.entity;
>          struct media_device *mdev = entity->graph_obj.mdev;
> +       bool is_singular_file;
> 
>          mutex_lock(&isp->video_lock);
> 
> -       if (v4l2_fh_is_singular_file(file) && ivc->streaming) {
> +       is_singular_file = v4l2_fh_is_singular_file(file);
> +
> +       if (is_singular_file && ivc->streaming) {
>                  media_pipeline_stop(entity);
>                  ivc->streaming = 0;
>          }
> 
>          _vb2_fop_release(file, NULL);
> 
> -       if (v4l2_fh_is_singular_file(file)) {
> +       if (is_singular_file) {
>                  fimc_pipeline_call(&ivc->ve, close);
> 
>                  mutex_lock(&mdev->graph_mutex);
> --------8<---------
> 
> Regards,
> Sylwester

Ok, thanks for your review and help.
I have corrected my patch and sent the PATCH v3 for you review again.

Thanks.

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

end of thread, other threads:[~2021-04-27 13:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27  6:02 [PATCH v2] media:exynos4-is: Fix a use after free in isp_video_release Lv Yunlong
2021-04-27 10:36 ` Sylwester Nawrocki
2021-04-27 13:29   ` lyl2019

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).