From: Maxime Ripard <maxime.ripard@free-electrons.com>
To: Benoit Parrot <bparrot@ti.com>
Cc: "Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Rob Herring" <robh+dt@kernel.org>,
"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
linux-media@vger.kernel.org, devicetree@vger.kernel.org,
"Cyprian Wronka" <cwronka@cadence.com>,
"Neil Webb" <neilw@cadence.com>,
"Richard Sproul" <sproul@cadence.com>,
"Alan Douglas" <adouglas@cadence.com>,
"Steve Creaney" <screaney@cadence.com>,
"Thomas Petazzoni" <thomas.petazzoni@free-electrons.com>,
"Boris Brezillon" <boris.brezillon@free-electrons.com>,
"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
"Hans Verkuil" <hans.verkuil@cisco.com>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>
Subject: Re: [PATCH v3 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver
Date: Thu, 14 Sep 2017 13:54:29 +0200 [thread overview]
Message-ID: <20170914115429.cjulb2s74xsppx5j@flea.lan> (raw)
In-Reply-To: <20170912182339.GA27713@ti.com>
[-- Attachment #1: Type: text/plain, Size: 1729 bytes --]
Hi Benoit,
Thanks for your comments,
On Tue, Sep 12, 2017 at 01:23:39PM -0500, Benoit Parrot wrote:
> > +static int csi2rx_probe(struct platform_device *pdev)
> > +{
> > + struct v4l2_async_subdev **subdevs;
> > + struct csi2rx_priv *csi2rx;
> > + unsigned int i;
> > + int ret;
> > +
> > + /*
> > + * Since the v4l2_subdev structure is embedded in our
> > + * csi2rx_priv structure, and that the structure is exposed to
> > + * the user-space, we cannot just use the devm_variant
> > + * here. Indeed, that would lead to a use-after-free in a
> > + * open() - unbind - close() pattern.
> > + */
> > + csi2rx = kzalloc(sizeof(*csi2rx), GFP_KERNEL);
> > + if (!csi2rx)
> > + return -ENOMEM;
> > + platform_set_drvdata(pdev, csi2rx);
> > + csi2rx->dev = &pdev->dev;
[snip]
> > +
> > + subdevs = devm_kzalloc(csi2rx->dev, sizeof(*subdevs), GFP_KERNEL);
> > + if (!subdevs) {
> > + ret = -ENOMEM;
> > + goto err_free_priv;
> > + }
> > + subdevs[0] = &csi2rx->asd;
> > +
>
> Shouldn't the comment related to lifetime of memory allocation be
> also applied here? A reference to the "subdevs" pointer is taken
> internally so it might suffer the same fate. Not sure how many
> "struct v4l2_async_subdev **subdevs" we would end up needing but
> since here we are only dealing with one, why not just make it a
> member of the struct csi2rx_priv object.
As far as I know, only the notifier will use that array. The notifier
will be removed before that array is de-allocated, and the user-space
never has access to it, so I'm not sure the same issue arises here.
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
prev parent reply other threads:[~2017-09-14 11:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-04 13:03 [PATCH v3 0/2] media: v4l: Add support for the Cadence MIPI-CSI2 RX Maxime Ripard
2017-09-04 13:03 ` [PATCH v3 1/2] dt-bindings: media: Add Cadence MIPI-CSI2 RX Device Tree bindings Maxime Ripard
2017-09-05 14:46 ` Sakari Ailus
2017-09-14 18:40 ` Laurent Pinchart
2017-09-04 13:03 ` [PATCH v3 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver Maxime Ripard
2017-09-12 18:23 ` Benoit Parrot
2017-09-12 19:13 ` Benoit Parrot
2017-09-14 11:57 ` Maxime Ripard
2017-09-14 11:54 ` Maxime Ripard [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=20170914115429.cjulb2s74xsppx5j@flea.lan \
--to=maxime.ripard@free-electrons.com \
--cc=adouglas@cadence.com \
--cc=boris.brezillon@free-electrons.com \
--cc=bparrot@ti.com \
--cc=cwronka@cadence.com \
--cc=devicetree@vger.kernel.org \
--cc=hans.verkuil@cisco.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mchehab@kernel.org \
--cc=neilw@cadence.com \
--cc=niklas.soderlund@ragnatech.se \
--cc=robh+dt@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=screaney@cadence.com \
--cc=sproul@cadence.com \
--cc=thomas.petazzoni@free-electrons.com \
/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