Re: [tpmdd-devel] [PATCH RFC v2 5/5] tpm2: expose resource manager via a device link /dev/tpms<n>
From: James Bottomley
Date: Fri Jan 13 2017 - 14:20:55 EST
On Thu, 2017-01-12 at 11:39 -0700, Jason Gunthorpe wrote:
> On Thu, Jan 12, 2017 at 07:46:08PM +0200, Jarkko Sakkinen wrote:
>
> > struct tpm_chip {
> > - struct device dev;
> > - struct cdev cdev;
> > + struct device dev, devrm;
>
> Hum.. devrm adds a new kref but doesn't do anything with the release
> function, so that is going to use after free, ie here:
>
> > put_device(&chip->dev);
> > + put_device(&chip->devrm);
> > return ERR_PTR(rc);
>
> And other places.
>
> One solution is to get_device(chip->dev) after
> device_initialize(dev->rm) and add a devrm->dev.release function to
> do put_device(chip->dev)
Actually, no, the devrm is a completely lifetime managed device as part
of the chip structure. once you've done a device_del on it, it can be
kfreed because it's no longer visible to anything else. The fix is
simply not to do the put.
With that and the other errors, here's a v3
James
---