From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: Logan Gunthorpe <logang@deltatee.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
Keith Busch <keith.busch@intel.com>,
Myron Stowe <myron.stowe@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Jonathan Corbet <corbet@lwn.net>,
"David S. Miller" <davem@davemloft.net>,
Andrew Morton <akpm@linux-foundation.org>,
Emil Velikov <emil.l.velikov@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Guenter Roeck <linux@roeck-us.net>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Linus Walleij <linus.walleij@linaro.org>,
Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>,
Stefan Berger <stefanb@linux.vnet.ibm.com>,
Wei Zhang <wzhang@fb.com>,
linux-doc@vger.kernel.org, linux-pci@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-nvme@lists.infradead.org,
Stephen Bates <stephen.bates@microsemi.com>,
Kurt Schwemmer <kurt.schwemmer@microsemi.com>
Subject: Re: [PATCH] switchtec: cleanup cdev init
Date: Tue, 21 Feb 2017 11:37:53 -0700 [thread overview]
Message-ID: <20170221183753.GB13138@obsidianresearch.com> (raw)
In-Reply-To: <2cd5df88-c018-3e76-fd08-483fec374932@deltatee.com>
On Sun, Feb 19, 2017 at 09:22:35PM -0700, Logan Gunthorpe wrote:
> Really, in any situation where there's a cdev and a device in the same
> structure, the life cycles of the two become linked but their reference
> counts are not and that is the problem here.
Yes, the cdev must hold a kref on the containing struct otherwise
userspace can trigger a use after free. This cannot be fixed with an
approach inside the open/release function either as the cdev core code
itself relies on the memory to exist.
I've suggested something like this before:
https://lkml.org/lkml/2015/7/8/1066
So I hope this will make it in, it is a step in the right direction.
If it does, would you make another patch to go further? I think
cdev_init should take enough arguments to hold the enclosing kref, API
wise there should be no API to init a cdev without the caller
specifying the enclosing struct's kref. That is the only way we will
stamp this bug-class out.
Eg look at kernel/time/posix-clock.c, it is wrong in the same way as
well - the kref_put in posix_clock_release is not enough to make it
work, clk->cdev is referenced after posix_clock_release returns by the
cdev core so this has a use-after-free.
Jason
next prev parent reply other threads:[~2017-02-21 18:39 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-02 18:05 [PATCH v2 0/4] New Microsemi PCI Switch Management Driver Logan Gunthorpe
2017-02-02 18:06 ` [PATCH v2 1/4] MicroSemi Switchtec management interface driver Logan Gunthorpe
2017-02-10 14:51 ` Greg Kroah-Hartman
2017-02-10 16:48 ` Logan Gunthorpe
2017-02-10 16:55 ` Greg Kroah-Hartman
2017-02-10 17:03 ` Logan Gunthorpe
2017-02-10 17:09 ` Greg Kroah-Hartman
2017-02-10 18:00 ` Logan Gunthorpe
2017-02-10 17:57 ` [PATCH] switchtec: cleanup cdev init Logan Gunthorpe
2017-02-18 20:22 ` Logan Gunthorpe
2017-02-19 21:43 ` Dan Williams
2017-02-20 4:22 ` Logan Gunthorpe
2017-02-21 18:37 ` Jason Gunthorpe [this message]
2017-02-10 14:54 ` [PATCH v2 1/4] MicroSemi Switchtec management interface driver Greg Kroah-Hartman
2017-02-24 0:35 ` Bjorn Helgaas
2017-02-24 18:32 ` Logan Gunthorpe
2017-02-02 18:06 ` [PATCH v2 2/4] switchtec: Add user interface documentation Logan Gunthorpe
2017-02-02 18:06 ` [PATCH v2 3/4] switchtec: Add sysfs attributes to the Switchtec driver Logan Gunthorpe
2017-02-10 14:54 ` Greg Kroah-Hartman
2017-02-23 22:43 ` Bjorn Helgaas
2017-02-23 22:56 ` Logan Gunthorpe
2017-02-24 22:45 ` Bjorn Helgaas
2017-02-02 18:06 ` [PATCH v2 4/4] switchtec: Add IOCTLs " Logan Gunthorpe
2017-02-09 23:16 ` [PATCH v2 0/4] New Microsemi PCI Switch Management Driver Wei Zhang
2017-02-09 23:46 ` Wei Zhang
2017-02-10 14:54 ` Greg Kroah-Hartman
2017-02-10 16:14 ` Jens Axboe
2017-02-17 20:36 ` Logan Gunthorpe
2017-02-23 20:36 ` Logan Gunthorpe
2017-02-23 20:51 ` Sinan Kaya
2017-02-23 20:54 ` Jens Axboe
2017-02-23 20:56 ` Logan Gunthorpe
2017-02-23 20:52 ` Jens Axboe
2017-02-23 20:55 ` Greg Kroah-Hartman
2017-02-23 22:14 ` Bjorn Helgaas
2017-02-23 22:19 ` Logan Gunthorpe
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=20170221183753.GB13138@obsidianresearch.com \
--to=jgunthorpe@obsidianresearch.com \
--cc=akpm@linux-foundation.org \
--cc=bhelgaas@google.com \
--cc=corbet@lwn.net \
--cc=dan.j.williams@intel.com \
--cc=davem@davemloft.net \
--cc=emil.l.velikov@gmail.com \
--cc=geert+renesas@glider.be \
--cc=gregkh@linuxfoundation.org \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=keith.busch@intel.com \
--cc=konishi.ryusuke@lab.ntt.co.jp \
--cc=kurt.schwemmer@microsemi.com \
--cc=linus.walleij@linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=logang@deltatee.com \
--cc=mchehab@kernel.org \
--cc=myron.stowe@gmail.com \
--cc=stefanb@linux.vnet.ibm.com \
--cc=stephen.bates@microsemi.com \
--cc=wzhang@fb.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).