lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 10 Nov 2014 11:00:16 -0700
From:	Jason Gunthorpe <jgunthorpe@...idianresearch.com>
To:	Jarkko Sakkinen <jarkko.sakkinen@...ux.intel.com>
Cc:	Peter Huewe <peterhuewe@....de>, Ashley Lai <ashley@...leylai.com>,
	Marcel Selhorst <tpmdd@...horst.net>,
	tpmdd-devel@...ts.sourceforge.net, linux-kernel@...r.kernel.org,
	josh.triplett@...el.com, christophe.ricard@...il.com,
	jason.gunthorpe@...idianresearch.com
Subject: Re: [PATCH v6 05/10] tpm: device class for tpm

On Mon, Nov 10, 2014 at 02:49:49PM +0200, Jarkko Sakkinen wrote:
  
> +static void tpm_dev_release(struct device *dev)
> +{
> +}
> +

These patches are so close to actually fixing many of the use-after-free
problems too :)

>  int tpm_dev_add_device(struct tpm_chip *chip)
>  {
>  	int rc;
>  
> -	chip->vendor.miscdev.fops = &tpm_fops;
> +	chip->dev.class = tpm_class;
> +	chip->dev.release = tpm_dev_release;
> +	chip->dev.parent = chip->pdev;
> +	dev_set_name(&chip->dev, chip->devname);
> +	rc = device_register(&chip->dev);

I think all of this should live in tpm-chip.c

I would also suggest using device_initialize during tpmm_alloc_chip
and device_add + cdev_add during tpm_register. That way the dev member
is always valid and we can immediately use put_device to do the free and
devm just does put_device.

>  void tpm_dev_del_device(struct tpm_chip *chip)
>  {
> -	if (chip->vendor.miscdev.name)
> -		misc_deregister(&chip->vendor.miscdev);
> +	if (get_device(&chip->dev) != NULL) {
> +		cdev_del(&chip->cdev);
> +		device_unregister(&chip->dev);
> +		put_device(&chip->dev);
> +	}

The get/put seems oddly placed - really the caller of del_device must
be holding the ref I don't see that del_device needs it..

Ultimately we want things so that when the ref count goes to 0 then
the chip will be freed - this means that get_device can never fail
since chip->dev will be deallocated memory.

> +struct class *tpm_class;
> +dev_t tpm_devt;

Also makes more sense to me in chip-chip

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ