linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release
@ 2021-04-27 13:27 ` Lv Yunlong
  2021-04-27 13:48   ` Sylwester Nawrocki
  2021-05-05  9:31   ` Hans Verkuil
  0 siblings, 2 replies; 5+ messages in thread
From: Lv Yunlong @ 2021-04-27 13:27 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 sets file->private_data to NULL after _vb2_fop_release()
to avoid the use after free, and uses a variable 'is_singular_file'
to keep the original function unchanged.

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 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 612b9872afc8..c07dcb0bccc2 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -306,17 +306,21 @@ 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);
+	file->private_data = NULL;
 
-	if (v4l2_fh_is_singular_file(file)) {
+	if (is_singular_file) {
 		fimc_pipeline_call(&ivc->ve, close);
 
 		mutex_lock(&mdev->graph_mutex);
-- 
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] 5+ messages in thread

* Re: [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release
  2021-04-27 13:27 ` [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release Lv Yunlong
@ 2021-04-27 13:48   ` Sylwester Nawrocki
  2021-05-05  9:31   ` Hans Verkuil
  1 sibling, 0 replies; 5+ messages in thread
From: Sylwester Nawrocki @ 2021-04-27 13:48 UTC (permalink / raw)
  To: Lv Yunlong
  Cc: linux-media, linux-arm-kernel, linux-samsung-soc, linux-kernel,
	mchehab, krzk

On 27.04.2021 15:27, 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 sets file->private_data to NULL after _vb2_fop_release()
> to avoid the use after free, and uses a variable 'is_singular_file'
> to keep the original function unchanged.
> 
> Fixes: 34947b8aebe3f ("[media] exynos4-is: Add the FIMC-IS ISP capture DMA driver")
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>

Thanks,

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>

_______________________________________________
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] 5+ messages in thread

* Re: [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release
  2021-04-27 13:27 ` [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release Lv Yunlong
  2021-04-27 13:48   ` Sylwester Nawrocki
@ 2021-05-05  9:31   ` Hans Verkuil
  2021-05-06  7:19     ` lyl2019
  1 sibling, 1 reply; 5+ messages in thread
From: Hans Verkuil @ 2021-05-05  9:31 UTC (permalink / raw)
  To: Lv Yunlong, s.nawrocki, mchehab, krzk
  Cc: linux-media, linux-arm-kernel, linux-samsung-soc, linux-kernel

Hi Lv Yunlong,

On 27/04/2021 15:27, 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 sets file->private_data to NULL after _vb2_fop_release()
> to avoid the use after free, and uses a variable 'is_singular_file'
> to keep the original function unchanged.

Actually, it is the use of 'is_singular_file' that fixes the bug,
the 'file->private_data = NULL;' is unnecessary here.

That said, it would be a really good idea if in a separate patch you
make v4l2_fh_release() more robust by setting filp->private_data to
NULL after the kfree(fh).

Regards,

	Hans

> 
> 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 | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 612b9872afc8..c07dcb0bccc2 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -306,17 +306,21 @@ 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);
> +	file->private_data = NULL;
>  
> -	if (v4l2_fh_is_singular_file(file)) {
> +	if (is_singular_file) {
>  		fimc_pipeline_call(&ivc->ve, close);
>  
>  		mutex_lock(&mdev->graph_mutex);
> 


_______________________________________________
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] 5+ messages in thread

* Re: Re: [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release
  2021-05-05  9:31   ` Hans Verkuil
@ 2021-05-06  7:19     ` lyl2019
  2021-05-06  7:23       ` Hans Verkuil
  0 siblings, 1 reply; 5+ messages in thread
From: lyl2019 @ 2021-05-06  7:19 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: s.nawrocki, mchehab, krzk, linux-media, linux-arm-kernel,
	linux-samsung-soc, linux-kernel




> -----原始邮件-----
> 发件人: "Hans Verkuil" <hverkuil@xs4all.nl>
> 发送时间: 2021-05-05 17:31:04 (星期三)
> 收件人: "Lv Yunlong" <lyl2019@mail.ustc.edu.cn>, s.nawrocki@samsung.com, mchehab@kernel.org, krzk@kernel.org
> 抄送: linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org
> 主题: Re: [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release
> 
> Hi Lv Yunlong,
> 
> On 27/04/2021 15:27, 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 sets file->private_data to NULL after _vb2_fop_release()
> > to avoid the use after free, and uses a variable 'is_singular_file'
> > to keep the original function unchanged.
> 
> Actually, it is the use of 'is_singular_file' that fixes the bug,
> the 'file->private_data = NULL;' is unnecessary here.
> 
> That said, it would be a really good idea if in a separate patch you
> make v4l2_fh_release() more robust by setting filp->private_data to
> NULL after the kfree(fh).
> 
> Regards,
> 
> 	Hans
> 
> > 
> > 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 | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > index 612b9872afc8..c07dcb0bccc2 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> > @@ -306,17 +306,21 @@ 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);
> > +	file->private_data = NULL;
> >  
> > -	if (v4l2_fh_is_singular_file(file)) {
> > +	if (is_singular_file) {
> >  		fimc_pipeline_call(&ivc->ve, close);
> >  
> >  		mutex_lock(&mdev->graph_mutex);
> > 
> 


Ok, thanks for your suggestion.

Do you means i need submit a new path to set filp->private_data = NULL
after kfree(fh) in v4l2_fh_release() ?

Lv Yunlong
_______________________________________________
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] 5+ messages in thread

* Re: [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release
  2021-05-06  7:19     ` lyl2019
@ 2021-05-06  7:23       ` Hans Verkuil
  0 siblings, 0 replies; 5+ messages in thread
From: Hans Verkuil @ 2021-05-06  7:23 UTC (permalink / raw)
  To: lyl2019
  Cc: s.nawrocki, mchehab, krzk, linux-media, linux-arm-kernel,
	linux-samsung-soc, linux-kernel

On 06/05/2021 09:19, lyl2019@mail.ustc.edu.cn wrote:
> 
> 
> 
>> -----原始邮件-----
>> 发件人: "Hans Verkuil" <hverkuil@xs4all.nl>
>> 发送时间: 2021-05-05 17:31:04 (星期三)
>> 收件人: "Lv Yunlong" <lyl2019@mail.ustc.edu.cn>, s.nawrocki@samsung.com, mchehab@kernel.org, krzk@kernel.org
>> 抄送: linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org
>> 主题: Re: [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release
>>
>> Hi Lv Yunlong,
>>
>> On 27/04/2021 15:27, 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 sets file->private_data to NULL after _vb2_fop_release()
>>> to avoid the use after free, and uses a variable 'is_singular_file'
>>> to keep the original function unchanged.
>>
>> Actually, it is the use of 'is_singular_file' that fixes the bug,
>> the 'file->private_data = NULL;' is unnecessary here.
>>
>> That said, it would be a really good idea if in a separate patch you
>> make v4l2_fh_release() more robust by setting filp->private_data to
>> NULL after the kfree(fh).
>>
>> Regards,
>>
>> 	Hans
>>
>>>
>>> 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 | 8 ++++++--
>>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
>>> index 612b9872afc8..c07dcb0bccc2 100644
>>> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
>>> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
>>> @@ -306,17 +306,21 @@ 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);
>>> +	file->private_data = NULL;
>>>  
>>> -	if (v4l2_fh_is_singular_file(file)) {
>>> +	if (is_singular_file) {
>>>  		fimc_pipeline_call(&ivc->ve, close);
>>>  
>>>  		mutex_lock(&mdev->graph_mutex);
>>>
>>
> 
> 
> Ok, thanks for your suggestion.
> 
> Do you means i need submit a new path to set filp->private_data = NULL
> after kfree(fh) in v4l2_fh_release() ?

Yes, so one updated patch for fimc-isp-video.c and a second patch for v4l2-fh.c.

Regards,

	Hans

> 
> Lv Yunlong
> 


_______________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2021-05-06  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210427132754eucas1p21042e4e176135e7b3f7b540dc9aadfbb@eucas1p2.samsung.com>
2021-04-27 13:27 ` [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release Lv Yunlong
2021-04-27 13:48   ` Sylwester Nawrocki
2021-05-05  9:31   ` Hans Verkuil
2021-05-06  7:19     ` lyl2019
2021-05-06  7:23       ` Hans Verkuil

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