Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1460216

Re: [PATCH] fs/char_dev: fix cdev_put() vs f_op->release() use-after-free

From Dan Williams <dan.j.williams@intel.com>
Newsgroups linux.kernel
Subject Re: [PATCH] fs/char_dev: fix cdev_put() vs f_op->release() use-after-free
Date 2016-08-11 09:30 +0200
Message-ID <s4SBb-IX-5@gated-at.bofh.it> (permalink)
References <s4Qg1-6CV-1@gated-at.bofh.it> <s4Qzo-70w-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Aug 10, 2016 at 10:16 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> 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.

Ah, ok.  I missed that cdev_put() drops a parent kobj ref, NULL in my
case.  So that "put_device(dev)" above can just be delegated to
cdev_put() and I can remove the kref behind dax_dev_put().  Thank you
for straightening me out!

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH] fs/char_dev: fix cdev_put() vs f_op->release()  use-after-free Dan Williams <dan.j.williams@intel.com> - 2016-08-11 07:00 +0200
  Re: [PATCH] fs/char_dev: fix cdev_put() vs f_op->release()  use-after-free Al Viro <viro@ZenIV.linux.org.uk> - 2016-08-11 07:20 +0200
    Re: [PATCH] fs/char_dev: fix cdev_put() vs f_op->release() use-after-free Dan Williams <dan.j.williams@intel.com> - 2016-08-11 09:30 +0200

csiph-web