linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel@collabora.com>
To: Hans Verkuil <hverkuil@xs4all.nl>,
	Dafna Hirschfeld <dafna.hirschfeld@collabora.com>,
	linux-media@vger.kernel.org
Cc: dafna3@gmail.com, helen.koike@collabora.com, stable@vger.kernel.org
Subject: Re: [PATCH v3] media: v4l2-core: fix a use-after-free bug of sd->devnode
Date: Fri, 31 Jan 2020 12:42:51 -0300	[thread overview]
Message-ID: <262a2c7a1ad470f8d386bb26da2258608c49f9a7.camel@collabora.com> (raw)
In-Reply-To: <fe36e4a9-2369-3150-b823-97fb4bf1afe4@xs4all.nl>

On Thu, 2020-01-16 at 12:57 +0100, Hans Verkuil wrote:
> On 11/20/19 1:22 PM, Dafna Hirschfeld wrote:
> > sd->devnode is released after calling
> > v4l2_subdev_release. Therefore it should be set
> > to NULL so that the subdev won't hold a pointer
> > to a released object. This fixes a reference
> > after free bug in function
> > v4l2_device_unregister_subdev
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: 0e43734d4c46e ("media: v4l2-subdev: add release() internal op")
> > Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
> > Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> > ---
> > changes since v2:
> > - since this is a regresion fix, I added Fixes and Cc to stable tags,
> > - change the commit title and log to be more clear.
> > 
> >  drivers/media/v4l2-core/v4l2-device.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
> > index 63d6b147b21e..2b3595671d62 100644
> > --- a/drivers/media/v4l2-core/v4l2-device.c
> > +++ b/drivers/media/v4l2-core/v4l2-device.c
> > @@ -177,6 +177,7 @@ static void v4l2_subdev_release(struct v4l2_subdev *sd)
> >  {
> >  	struct module *owner = !sd->owner_v4l2_dev ? sd->owner : NULL;
> >  
> > +	sd->devnode = NULL;
> >  	if (sd->internal_ops && sd->internal_ops->release)
> >  		sd->internal_ops->release(sd);
> 
> I'd move the sd->devnode = NULL; line here. That way the
> sd->internal_ops->release(sd) callback can still use it.
> 

Hi everyone,

Please note this fix is useful to fix a kernel oops
when rkisp1 driver is removed.

Can we get a v4 addressing Hans' feedback?

Thanks,
Ezequiel

> Unless I am missing something?
> 
> >  	module_put(owner);
> > 
> 
> Regards,
> 
> 	Hans



      parent reply	other threads:[~2020-01-31 15:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 12:22 [PATCH v3] media: v4l2-core: fix a use-after-free bug of sd->devnode Dafna Hirschfeld
2020-01-16 11:57 ` Hans Verkuil
2020-01-17 10:35   ` Dafna Hirschfeld
2020-01-17 10:46     ` Hans Verkuil
2020-01-17 10:52       ` Dafna Hirschfeld
2020-01-31 15:42   ` Ezequiel Garcia [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=262a2c7a1ad470f8d386bb26da2258608c49f9a7.camel@collabora.com \
    --to=ezequiel@collabora.com \
    --cc=dafna.hirschfeld@collabora.com \
    --cc=dafna3@gmail.com \
    --cc=helen.koike@collabora.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).