From: Al Viro <viro@ZenIV.linux.org.uk>
To: Dan Williams <dan.j.williams@intel.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-nvdimm@ml01.01.org
Subject: Re: [PATCH] fs/char_dev: fix cdev_put() vs f_op->release() use-after-free
Date: Thu, 11 Aug 2016 06:16:50 +0100 [thread overview]
Message-ID: <20160811051650.GS2356@ZenIV.linux.org.uk> (raw)
In-Reply-To: <147089096242.9037.17705831938180576705.stgit@dwillia2-desk3.amr.corp.intel.com>
On Wed, Aug 10, 2016 at 09:49:22PM -0700, Dan Williams wrote:
> Where dax_dev_release() is the f_op->release() method, and is
> implemented to simply drop the final references on our driver objects:
>
> struct dax_dev *dax_dev = filp->private_data;
> struct device *dev = dax_dev->dev;
>
> dev_dbg(dax_dev->dev, "%s\n", __func__);
> put_device(dev);
> dax_dev_put(dax_dev);
>
> The dax_dev object embeds a 'struct cdev' which means f_op->release()
> may free cdev, so __fput() needs to drop the cdev reference before
> calling f_op->release().
NAK. You *can't* free a structure that contains kobj with currently
positive refcount. Ever. If you embed a struct kobj into something,
you must use the refcount of that kobj (or one of its ancestors) to
control the lifetime of containing object. If your dax_dev_put() can
trigger freeing of dax_dev despite the still-positive refcount of
embedded cdev.kobj, it is fundamentally broken.
next prev parent reply other threads:[~2016-08-11 5:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-11 4:49 [PATCH] fs/char_dev: fix cdev_put() vs f_op->release() use-after-free Dan Williams
2016-08-11 5:16 ` Al Viro [this message]
2016-08-11 7:24 ` Dan Williams
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=20160811051650.GS2356@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=dan.j.williams@intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@ml01.01.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