mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kylene Jo Hall <kjhall@us.ibm.com>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: Greg K-H <greg@kroah.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Add TPM hardware enablement driver
Date: Tue, 15 Mar 2005 17:59:39 -0600	[thread overview]
Message-ID: <1110931179.3885.29.camel@jo.austin.ibm.com> (raw)
In-Reply-To: <422FC42B.7@pobox.com>

Thanks for the helpful comments I am working on a patch to fix your
concerns but I have a couple of questions.  

On Wed, 2005-03-09 at 22:51 -0500, Jeff Garzik wrote:
<snip>

> > +	down(&chip->timer_manipulation_mutex);
> > +	chip->time_expired = 0;
> > +	init_timer(&chip->device_timer);
> > +	chip->device_timer.function = tpm_time_expired;
> > +	chip->device_timer.expires = jiffies + 2 * 60 * HZ;
> > +	chip->device_timer.data = (unsigned long) &chip->time_expired;
> > +	add_timer(&chip->device_timer);
> 
> very wrong.  you init_timer() when you initialize 'chip'... once.  then 
> during the device lifetime you add/mod/del the timer.
> 
> calling init_timer() could lead to corruption of state.
> 
> > +	up(&chip->timer_manipulation_mutex);
When calling mod_timer and an occasional del_singleshot_timer_sync is it
necessary to protect this with a mutex like I was doing or not?


> > +	pci_dev_get(chip->pci_dev);
> > +
> > +	spin_unlock(&driver_lock);
> > +
> > +	chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
> > +	if (chip->data_buffer == NULL) {
> > +		chip->num_opens--;
> > +		pci_dev_put(chip->pci_dev);
> > +		return -ENOMEM;
> > +	}
> 
> what is the purpose of this pci_dev_get/put?  attempting to prevent 
> hotplug or something?

We were doing reference counting since their is a pci_dev in the chip
structure which set to the file->private_data pointer. Not correct?

> 
> > +	}
> > +
> > +	down(&chip->buffer_mutex);
> > +
> > +	if (in_size > TPM_BUFSIZE)
> > +		in_size = TPM_BUFSIZE;
> > +
> > +	if (copy_from_user
> > +	    (chip->data_buffer, (void __user *) buf, in_size)) {
> > +		up(&chip->buffer_mutex);
> > +		return -EFAULT;
> > +	}
> > +
> > +	/* atomic tpm command send and result receive */
> > +	out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);
> 
> major bug?  in_size may be smaller than TPM_BUFSIZE
> 
Yes in_size might be but the chip->data_buffer will always be this size since it is malloc'd in open.  The operation needs to be atomic so the tpm_transmit function is sending the command to the device and receiving the result which might be bigger than in_size.  The result is reported back to userspace from this buffer on a read.

> > +
> > +ssize_t tpm_read(struct file * file, char __user * buf,
> > +		 size_t size, loff_t * off)
> > +{
> > +	struct tpm_chip *chip = file->private_data;
> > +	int ret_size = -ENODATA;
> > +
> > +	if (atomic_read(&chip->data_pending) != 0) {	/* Result available */
> > +		down(&chip->timer_manipulation_mutex);
> > +		del_singleshot_timer_sync(&chip->user_read_timer);
> > +		up(&chip->timer_manipulation_mutex);
> > +
> > +		down(&chip->buffer_mutex);
> > +
> > +		ret_size = atomic_read(&chip->data_pending);
> > +		atomic_set(&chip->data_pending, 0);
> > +
> > +		if (ret_size == 0)	/* timeout just occurred */
> > +			ret_size = -ETIME;
> > +		else if (ret_size > 0) {	/* relay data */
> > +			if (size < ret_size)
> > +				ret_size = size;
> > +
> > +			if (copy_to_user((void __user *) buf,
> > +					 chip->data_buffer, ret_size)) {
> > +				ret_size = -EFAULT;
> > +			}
> > +		}
> > +		up(&chip->buffer_mutex);
> > +	}
> > +
> > +	return ret_size;
> 
> POSIX violation -- when there is no data available, returning a 
> non-standard error is silly
> 
So read should just return 0 if no data available?


Thanks,
Kylie


  reply	other threads:[~2005-03-16  0:02 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-10  0:41 [BK PATCH] Add TPM driver support for 2.6.11 Greg KH
2005-03-10  0:42 ` [PATCH] Add TPM hardware enablement driver Greg KH
2005-03-10  0:42   ` [PATCH] tpm: fix cause of SMP stack traces Greg KH
2005-03-10  0:42     ` [PATCH] tpm_msc-build-fix Greg KH
2005-03-10  0:42       ` [PATCH] tpm_atmel build fix Greg KH
2005-03-10  0:42         ` [PATCH] tpm-build-fix Greg KH
2005-03-10  3:51   ` [PATCH] Add TPM hardware enablement driver Jeff Garzik
2005-03-15 23:59     ` Kylene Jo Hall [this message]
2005-03-17  0:32     ` Kylene Hall
2005-03-23  2:02       ` Jeff Garzik
2005-03-24  6:39         ` Greg KH
2005-03-24 21:04           ` Jeff Garzik
2005-03-24 21:33             ` Greg KH
2005-04-05 16:14               ` Kylene Jo Hall
2005-04-08 20:07                 ` Kylene Jo Hall
2005-04-09  8:31                   ` Ian Campbell
2005-04-27 22:15     ` [PATCH: 1 of 12] Fix concerns with TPM driver -- use enums Kylene Hall
2005-04-27 22:23       ` Greg KH
2005-04-27 22:15     ` [PATCH: 2 of 12 ] Fix TPM driver -- address missing const defs Kylene Hall
2005-04-27 22:16     ` [PATCH: 3 of 12] Fix TPM driver --remove unnecessary module stuff Kylene Hall
2005-04-27 22:16     ` [PATCH 4 of 12] Fix TPM driver -- read return code issue Kylene Hall
2005-04-27 22:16     ` [PATCH 5 of 12] Fix TPM driver -- large stack objects Kylene Hall
2005-04-27 22:18     ` [PATCH 6 of 12] Fix TPM driver -- how timer is initialized Kylene Hall
2005-04-27 22:18     ` [PATCH 7 of 12] Fix TPM driver -- use to_pci_dev Kylene Hall
2005-03-10 17:35   ` [PATCH] Add TPM hardware enablement driver Nish Aravamudan
2005-03-10 18:19     ` Nish Aravamudan
2005-03-10 19:09   ` [PATCH] char/tpm: use msleep(), clean-up timers, fix typo Nishanth Aravamudan
2005-03-10 21:04   ` [PATCH] Add TPM hardware enablement driver Alexey Dobriyan
2005-04-27 22:18     ` [PATCH 9 of 12] Fix TPM driver -- remove unnecessary __force Kylene Hall
2005-03-11 18:18   ` [PATCH] char/tpm: use msleep(), clean-up timers, fix typo Nishanth Aravamudan
2005-04-15 20:23     ` Kylene Hall
2005-04-15 20:44       ` Nish Aravamudan
2005-04-15 21:04         ` Greg KH
2005-04-15 21:47           ` Nish Aravamudan
2005-04-15 21:47           ` Nish Aravamudan

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=1110931179.3885.29.camel@jo.austin.ibm.com \
    --to=kjhall@us.ibm.com \
    --cc=greg@kroah.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®