linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Jens Wiklander <jens.wiklander@linaro.org>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	Arnd Bergmann <arnd@arndb.de>, Rob Herring <robh+dt@kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	valentin.manea@huawei.com, jean-michel.delorme@st.com,
	emmanuel.michel@st.com, javier@javigon.com,
	Mark Rutland <mark.rutland@arm.com>,
	Michal Simek <michal.simek@xilinx.com>
Subject: Re: [PATCH v4 3/5] tee: generic TEE subsystem
Date: Wed, 8 Jul 2015 17:16:12 -0600	[thread overview]
Message-ID: <20150708231612.GB20068@obsidianresearch.com> (raw)
In-Reply-To: <20150708223325.GA5843@kroah.com>

On Wed, Jul 08, 2015 at 03:33:25PM -0700, Greg Kroah-Hartman wrote:
> > The basic issue is that cdev_del doesn't seem to be synchronizing.
> > 
> > The use after free race is then something like:
> > 
> >    struct tpm_chip {
> >  	struct device dev;
> > 	struct cdev cdev;
> 
> Oops, right there's your problem.  You can't have two reference counted
> objects trying to manage the memory of a single structure.  No matter
> what you do, it's going to be a pain to deal with this, so don't :)

Sure, generally, yes, but that isn't done for no reason, it is to make
open straightforward:

static int tpm_open(struct inode *inode, struct file *file)
{
	struct tpm_chip *chip =
		container_of(inode->i_cdev, struct tpm_chip, cdev);

We need to recover the tpm_chip associated with the char device
node, in a way that is holding a kref on it, without racing with
cdev_del/etc

This scheme does mean that if we have a struct file we have a kref on
the cdev, and if we have cdev then we have a kref on the tpm_chip,
which is really easy to use properly.

> > Ie we need cdev to hold a ref on tpm_chip->dev until cdev_put is
> > called.
> 
> No, separate them, make the cdev a pointer and all should be fine.

Okay, cdev_alloc takes care of the cdev lifetime.

Do you have a simple solution to replace container_of as well?

What would you think about something like:

 cdev_alloc(&chip->dev.kref)

?

Jason

  reply	other threads:[~2015-07-08 23:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 10:16 [PATCH v4 0/5] generic TEE subsystem Jens Wiklander
2015-07-08 10:16 ` [PATCH v4 1/5] arm/arm64: add smccc ARCH32 Jens Wiklander
2015-07-08 10:16 ` [PATCH v4 2/5] dt/bindings: add bindings for optee Jens Wiklander
2015-07-08 10:16 ` [PATCH v4 3/5] tee: generic TEE subsystem Jens Wiklander
2015-07-08 17:10   ` Jason Gunthorpe
2015-07-08 21:11     ` Greg Kroah-Hartman
2015-07-08 22:26       ` Jason Gunthorpe
2015-07-08 22:33         ` Greg Kroah-Hartman
2015-07-08 23:16           ` Jason Gunthorpe [this message]
2015-07-08 23:53             ` Greg Kroah-Hartman
2015-07-09  0:47               ` Dmitry Torokhov
2015-07-08 23:28           ` Dmitry Torokhov
2015-07-08 23:52             ` Greg Kroah-Hartman
2015-07-09  0:56               ` Dmitry Torokhov
2015-07-09 12:49     ` Jens Wiklander
2015-07-09 18:25       ` Jason Gunthorpe
2015-07-08 10:16 ` [PATCH v4 4/5] tee: add OP-TEE driver Jens Wiklander
2015-07-08 10:16 ` [PATCH v4 5/5] Documentation: tee subsystem and op-tee driver Jens Wiklander

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=20150708231612.GB20068@obsidianresearch.com \
    --to=jgunthorpe@obsidianresearch.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=emmanuel.michel@st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=javier@javigon.com \
    --cc=jean-michel.delorme@st.com \
    --cc=jens.wiklander@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=michal.simek@xilinx.com \
    --cc=robh+dt@kernel.org \
    --cc=valentin.manea@huawei.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;
as well as URLs for NNTP newsgroup(s).