All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Stefan Berger" <stefanb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Jason Gunthorpe
	<jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Cc: dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org
Subject: Re: [PATCH v5 4/5] Initialize TPM and get durations and timeouts
Date: Fri, 12 Feb 2016 18:14:42 -0500	[thread overview]
Message-ID: <201602122314.u1CNEjZV000390@d03av04.boulder.ibm.com> (raw)
In-Reply-To: <20160212224642.GA4781-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 3150 bytes --]

Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> wrote on 02/12/2016 
05:46:42 PM:

> 
> On Fri, Feb 12, 2016 at 05:23:16PM -0500, Stefan Berger wrote:
> 
> >    > I don't see how that can happen. Looking at the tpm cdev, it is
> 
> >    Well, following my tests, it does happen.
> 
> How are you testing for use-after-free bugs? Did you test the kapi
> interface? Did you get it in *exactly* the right configuration to
> cause this?

I think there are two cases that matter for the final unwind:

1) server side closes last
2) client side closes last

Any other cases?

Here's what happens in these cases:

1) we unwind with vtpm_delete_device_pair + vtpm_delete_vtpm_dev [see 
below]. The chip an vtpm_dev are freed, in that order by just these 
functions.

2) we unwind in tpm_release and the following kicks it off:

http://lxr.free-electrons.com/source/drivers/char/tpm/tpm-dev.c#L169

169         put_device(priv->chip->pdev);
170         kfree(priv);
171         return 0;
172 }
173 

The above put_device (in the front-end) releases vtpm_dev first and then 
after tpm_release finishes the chip is released (following the cdev's 
end). 

Once tpm_release happened, we closed the file descriptor and there's no 
more code doing other business in either the front or backend drivers 
other than unwinding.

   Stefan

> 
> >    > So, we have a situation where tpm_unregister can return, release 
the
> >    > kref on the vtpm and still have outstanding users, which will 
result
> >    > in a use after-free.
> 
> >    Maybe you should give it a try ... I don't see these problems and 
any
> >    change seems like ill-fixing it. What will be accessed after
> >    tpm_unregister? The only case we have tpm_unregister is here:
> 
> >    static void vtpm_delete_device_pair(structvtpm_dev *vtpm_dev)
> >    {
> >            tpm_chip_unregister(vtpm_dev->chip);
> >            vtpm_fops_undo_open(vtpm_dev);
> >            vtpm_delete_vtpm_dev(vtpm_dev);
> >    }
> 
> >    followed by:
> 
> >    static inline voidvtpm_delete_vtpm_dev(struct vtpm_dev *vtpm_dev)
> >    {
> >            put_device(&vtpm_dev->chip->dev); /* frees chip */
> >            device_unregister(&vtpm_dev->dev); /* does put_device */
> >    }
> 
> >    I don't see a problem with that.
> 
> device_unregister will put_device(vtpmt_dev) which will kfree it since
> no refs are left.
> 
> tpm_chip is still alive because the cdev/kapi are still holding a ref
> on it.
> 
> The cdev/kapi can still call vtpm_tpm_op_send which will then deref
> chip->priv which is the free'd vtpm_dev.
> 
> Any attempt to test for this scenario is very likely to hit the
> STATE_OPENED_BIT test and exit without crashing. However that is just
> a user-after free getting lucky. Testing is not a substitute for
> proper analysis.
> 
> Show me an analysis of what in cdev/kapi is holding the kref on
> vtpm_dev if you still think this can't happen.
> 
> As I said, the only kref the tpm core takes on vtpm_dev is dropped
> by tpm_chip_unregister.
> 
> Jason
> 



[-- Attachment #1.2: Type: text/html, Size: 6115 bytes --]

[-- Attachment #2: Type: text/plain, Size: 413 bytes --]

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140

[-- Attachment #3: Type: text/plain, Size: 192 bytes --]

_______________________________________________
tpmdd-devel mailing list
tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

  parent reply	other threads:[~2016-02-12 23:14 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-08 19:27 [PATCH v5 0/5] Multi-instance vTPM driver Stefan Berger
     [not found] ` <1454959628-30582-1-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-08 19:27   ` [PATCH v5 1/5] Implement tpm_chip_free Stefan Berger
     [not found]     ` <1454959628-30582-2-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-09  5:28       ` Jason Gunthorpe
2016-02-08 19:27   ` [PATCH v5 2/5] Implement driver for supporting multiple emulated TPMs Stefan Berger
2016-02-08 19:27   ` [PATCH v5 3/5] Make tpm_startup() available Stefan Berger
     [not found]     ` <1454959628-30582-4-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-09  5:29       ` Jason Gunthorpe
     [not found]         ` <20160209052957.GC12657-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-09 11:22           ` Stefan Berger
2016-02-08 19:27   ` [PATCH v5 4/5] Initialize TPM and get durations and timeouts Stefan Berger
     [not found]     ` <1454959628-30582-5-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-09  5:33       ` Jason Gunthorpe
     [not found]         ` <20160209053323.GD12657-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-09 16:19           ` Stefan Berger
     [not found]         ` <201602091626.u19GQpga021574@d01av02.pok.ibm.com>
     [not found]           ` <201602091626.u19GQpga021574-prK0F/7GlgzImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-09 16:52             ` Jason Gunthorpe
     [not found]               ` <20160209165228.GA14611-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-09 17:45                 ` Stefan Berger
2016-02-10  3:56                 ` Jarkko Sakkinen
     [not found]                   ` <20160210035620.GB7161-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-10  5:15                     ` Stefan Berger
     [not found]                   ` <201602100515.u1A5FonT015847@d03av04.boulder.ibm.com>
     [not found]                     ` <201602100515.u1A5FonT015847-2xHzGjyANq4+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-10  8:12                       ` Jarkko Sakkinen
     [not found]                   ` <201602100515.u1A5FpFi002736@d03av02.boulder.ibm.com>
     [not found]                     ` <201602100515.u1A5FpFi002736-nNA/7dmquNI+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-10 16:28                       ` Jason Gunthorpe
     [not found]                         ` <20160210162809.GB20730-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-10 21:45                           ` Stefan Berger
     [not found]                         ` <201602102145.u1ALjSAs001597@d03av04.boulder.ibm.com>
     [not found]                           ` <201602102145.u1ALjSAs001597-2xHzGjyANq4+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-10 22:23                             ` Jason Gunthorpe
     [not found]                               ` <20160210222313.GA7047-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-11  0:38                                 ` Stefan Berger
     [not found]                               ` <201602110038.u1B0cuE0030670@d03av05.boulder.ibm.com>
     [not found]                                 ` <201602110038.u1B0cuE0030670-3MP/CPU4Muo+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-11  7:04                                   ` Jarkko Sakkinen
     [not found]                                     ` <20160211070426.GB9307-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-11 15:24                                       ` Stefan Berger
     [not found]                                         ` <201602111521.u1BFLS3f007520-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-11 16:51                                           ` Stefan Berger
     [not found]                                     ` <201602111534.u1BFYvRs019573@d01av03.pok.ibm.com>
     [not found]                                       ` <201602111534.u1BFYvRs019573-CUdSWdNILC7ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-11 18:12                                         ` Jason Gunthorpe
     [not found]                                           ` <20160211181208.GA6285-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-11 19:10                                             ` Stefan Berger
     [not found]                                           ` <201602111911.u1BJB2nK017410@d01av03.pok.ibm.com>
     [not found]                                             ` <201602111911.u1BJB2nK017410-CUdSWdNILC7ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-11 19:48                                               ` Jason Gunthorpe
     [not found]                                                 ` <20160211194810.GA24211-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-11 22:10                                                   ` Stefan Berger
     [not found]                                                 ` <201602112210.u1BMAYPe015452@d03av01.boulder.ibm.com>
     [not found]                                                   ` <201602112210.u1BMAYPe015452-Rn83F4s8Lwc+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-11 22:18                                                     ` Jason Gunthorpe
     [not found]                                                       ` <20160211221822.GA16304-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-11 22:26                                                         ` Stefan Berger
     [not found]                                                       ` <201602112226.u1BMQZ59031657@d01av02.pok.ibm.com>
     [not found]                                                         ` <201602112226.u1BMQZ59031657-prK0F/7GlgzImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-11 23:56                                                           ` Jason Gunthorpe
     [not found]                                                             ` <20160211235611.GB16304-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-12  3:56                                                               ` Stefan Berger
     [not found]                                                                 ` <201602120356.u1C3usEe002034-2xHzGjyANq4+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-12 18:13                                                                   ` Stefan Berger
     [not found]                                                                 ` <201602121813.u1CIDu4O015272@d01av01.pok.ibm.com>
     [not found]                                                                   ` <201602121813.u1CIDu4O015272-4ZtxiNBBw+3ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-12 18:34                                                                     ` Jason Gunthorpe
     [not found]                                                                       ` <20160212183415.GA4289-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-14  6:37                                                                         ` Stefan Berger
     [not found]                                                                           ` <201602140637.u1E6baNX028563-2xHzGjyANq4+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-16 16:44                                                                             ` Stefan Berger
     [not found]                                                                           ` <201602161648.u1GGmdZv000468@d01av03.pok.ibm.com>
     [not found]                                                                             ` <201602161648.u1GGmdZv000468-CUdSWdNILC7ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-16 18:00                                                                               ` Jason Gunthorpe
     [not found]                                                                                 ` <20160216180028.GA4967-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-16 19:26                                                                                   ` Stefan Berger
     [not found]                                                                                 ` <201602161927.u1GJRJL6016216@d01av01.pok.ibm.com>
     [not found]                                                                                   ` <201602161927.u1GJRJL6016216-4ZtxiNBBw+3ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-17  4:47                                                                                     ` Jason Gunthorpe
     [not found]                                                                                       ` <20160217044750.GB25049-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-18  3:52                                                                                         ` Stefan Berger
     [not found]                                                             ` <201602120353.u1C3rYif023135@d01av05.pok.ibm.com>
     [not found]                                                               ` <201602120353.u1C3rYif023135-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-12 18:40                                                                 ` Jason Gunthorpe
     [not found]                                                                   ` <20160212184051.GB4289-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-12 20:31                                                                     ` Stefan Berger
     [not found]                                                                   ` <201602122031.u1CKVIOp028400@d03av03.boulder.ibm.com>
     [not found]                                                                     ` <201602122031.u1CKVIOp028400-MijUUJkLaQs+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-12 20:39                                                                       ` Jason Gunthorpe
     [not found]                                                                         ` <20160212203956.GB10540-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-12 20:44                                                                           ` Stefan Berger
     [not found]                                                                         ` <201602122044.u1CKiMbR023495@d03av03.boulder.ibm.com>
     [not found]                                                                           ` <201602122044.u1CKiMbR023495-MijUUJkLaQs+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-12 21:15                                                                             ` Jason Gunthorpe
     [not found]                                                                               ` <20160212211538.GA20737-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-12 22:23                                                                                 ` Stefan Berger
     [not found]                                                                                   ` <201602122223.u1CMNJXl023711-4ZtxiNBBw+3ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-12 22:47                                                                                     ` Stefan Berger
     [not found]                                                                                   ` <201602122247.u1CMlFni023527@d03av04.boulder.ibm.com>
     [not found]                                                                                     ` <201602122247.u1CMlFni023527-2xHzGjyANq4+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-12 23:19                                                                                       ` Jason Gunthorpe
     [not found]                                                                               ` <201602122223.u1CMNKL2004615@d03av02.boulder.ibm.com>
     [not found]                                                                                 ` <201602122223.u1CMNKL2004615-nNA/7dmquNI+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-12 22:46                                                                                   ` Jason Gunthorpe
     [not found]                                                                                     ` <20160212224642.GA4781-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-12 23:14                                                                                       ` Stefan Berger [this message]
     [not found]                                                                                     ` <201602122314.u1CNEk6P028695@d01av01.pok.ibm.com>
     [not found]                                                                                       ` <201602122314.u1CNEk6P028695-4ZtxiNBBw+3ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-12 23:21                                                                                         ` Jason Gunthorpe
     [not found]               ` <201602091745.u19HjeEv001740@d03av02.boulder.ibm.com>
     [not found]                 ` <201602091745.u19HjeEv001740-nNA/7dmquNI+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-09 18:01                   ` Jason Gunthorpe
     [not found]                     ` <20160209180152.GA17475-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-09 18:11                       ` Stefan Berger
     [not found]                     ` <201602091812.u19ICTww018943@d03av01.boulder.ibm.com>
     [not found]                       ` <201602091812.u19ICTww018943-Rn83F4s8Lwc+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-09 18:20                         ` Jason Gunthorpe
     [not found]                           ` <20160209182013.GA19018-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-09 19:22                             ` Stefan Berger
     [not found]                           ` <201602091922.u19JMQ6r025254@d03av05.boulder.ibm.com>
     [not found]                             ` <201602091922.u19JMQ6r025254-3MP/CPU4Muo+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-09 19:36                               ` Jason Gunthorpe
2016-02-08 19:27   ` [PATCH v5 5/5] A test program for vTPM device creation Stefan Berger

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=201602122314.u1CNEjZV000390@d03av04.boulder.ibm.com \
    --to=stefanb-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
    --cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.