All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [media] v4l2-device: fix potential NULL pointer dereference for subdev unregister path
@ 2014-04-30  4:25 Liu Ying
  2014-04-30 16:27 ` Laurent Pinchart
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Ying @ 2014-04-30  4:25 UTC (permalink / raw)
  To: linux-media
  Cc: m.chehab, a.hajda, laurent.pinchart, sakari.ailus, s.nawrocki,
	hans.verkuil

The pointer 'sd->v4l2_dev' is likely to be NULL and dereferenced in the subdev
unregister path.  The issue should happen if CONFIG_MEDIA_CONTROLLER is defined.

This patch fixes the issue by setting the pointer to be NULL after it will not
be derefereneced any more in the path.

Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>
Cc: Andrzej Hajda <a.hajda@samsung.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Cc: Hans Verkuil <hans.verkuil@cisco.com>
Cc: linux-media@vger.kernel.org
Signed-off-by: Liu Ying <Ying.Liu@freescale.com>
---
 drivers/media/v4l2-core/v4l2-device.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index 02d1b63..d98d96f 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -271,7 +271,6 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 
 	if (sd->internal_ops && sd->internal_ops->unregistered)
 		sd->internal_ops->unregistered(sd);
-	sd->v4l2_dev = NULL;
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
@@ -279,6 +278,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 		media_device_unregister_entity(&sd->entity);
 	}
 #endif
+	v4l2_dev = NULL;
 	video_unregister_device(sd->devnode);
 	module_put(sd->owner);
 }
-- 
1.7.9.5


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

* Re: [PATCH] [media] v4l2-device: fix potential NULL pointer dereference for subdev unregister path
  2014-04-30  4:25 [PATCH] [media] v4l2-device: fix potential NULL pointer dereference for subdev unregister path Liu Ying
@ 2014-04-30 16:27 ` Laurent Pinchart
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Pinchart @ 2014-04-30 16:27 UTC (permalink / raw)
  To: Liu Ying
  Cc: linux-media, m.chehab, a.hajda, sakari.ailus, s.nawrocki, hans.verkuil

Hi Liu,

Thank you for the patch.

On Wednesday 30 April 2014 12:25:21 Liu Ying wrote:
> The pointer 'sd->v4l2_dev' is likely to be NULL and dereferenced in the
> subdev unregister path.  The issue should happen if CONFIG_MEDIA_CONTROLLER
> is defined.
> 
> This patch fixes the issue by setting the pointer to be NULL after it will
> not be derefereneced any more in the path.

I'm not sure to understand the problem. Where do you see sd->v4l2_dev being 
(potentially) dereferenced after being set to NULL ?

> Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>
> Cc: Andrzej Hajda <a.hajda@samsung.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Sakari Ailus <sakari.ailus@iki.fi>
> Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
> Cc: Hans Verkuil <hans.verkuil@cisco.com>
> Cc: linux-media@vger.kernel.org
> Signed-off-by: Liu Ying <Ying.Liu@freescale.com>
> ---
>  drivers/media/v4l2-core/v4l2-device.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-device.c
> b/drivers/media/v4l2-core/v4l2-device.c index 02d1b63..d98d96f 100644
> --- a/drivers/media/v4l2-core/v4l2-device.c
> +++ b/drivers/media/v4l2-core/v4l2-device.c
> @@ -271,7 +271,6 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
> *sd)
> 
>  	if (sd->internal_ops && sd->internal_ops->unregistered)
>  		sd->internal_ops->unregistered(sd);
> -	sd->v4l2_dev = NULL;
> 
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	if (v4l2_dev->mdev) {
> @@ -279,6 +278,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
> *sd) media_device_unregister_entity(&sd->entity);
>  	}
>  #endif
> +	v4l2_dev = NULL;
>  	video_unregister_device(sd->devnode);
>  	module_put(sd->owner);
>  }

-- 
Regards,

Laurent Pinchart


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

end of thread, other threads:[~2014-04-30 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-30  4:25 [PATCH] [media] v4l2-device: fix potential NULL pointer dereference for subdev unregister path Liu Ying
2014-04-30 16:27 ` Laurent Pinchart

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.