All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Kent Yoder <key@linux.vnet.ibm.com>
Cc: James Morris <jmorris@namei.org>,
	linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	tpmdd-devel@lists.sourceforge.net,
	Peter Huewe <peter.huewe@infineon.com>,
	Bryan Freed <bfreed@chromium.org>,
	David Safford <safford@linux.vnet.ibm.com>
Subject: Re: [GIT PULL] New TPM driver, hwrng driver and fixes
Date: Fri, 27 Jul 2012 15:09:17 -0700	[thread overview]
Message-ID: <5013118D.2030601@zytor.com> (raw)
In-Reply-To: <20120727203000.GA22684@linux.vnet.ibm.com>

On 07/27/2012 01:30 PM, Kent Yoder wrote:

> +
> +	do {
> +		tpm_cmd.header.in = tpm_getrandom_header;
> +		tpm_cmd.params.getrandom_in.num_bytes = cpu_to_be32(num_bytes);
> +
> +		err = transmit_cmd(chip, &tpm_cmd,
> +				   TPM_GETRANDOM_RESULT_SIZE + num_bytes,
> +				   "attempting get random");
> +		if (err) {
> +			/* err can be positive if it came from the TPM itself,
> +			 * so return a negative value here instead. */
> +			err = -EFAULT;

-EFAULT is definitely wrong (that means a bad pointer was passed), you
can use -EIO instead.

However, I would suggest:

	err = total ? total : -EIO;

... so you report the number of bytes successfully received if we got
any.  However, since you *also* do that on the retry line,

> +			goto out_err;
> +		}
> +
> +		recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len);
> +		memcpy(dest, tpm_cmd.params.getrandom_out.rng_data, recd);
> +
> +		dest += recd;
> +		total += recd;
> +		num_bytes -= recd;
> +	} while (retries-- && total < max);
> +
> +	err = total;

Should we return something other than 0 if we run out of retries here, too?

Perhaps we should just do the same "err = total ? total : -EIO;" here
and the above statement can just turn into a break;.

> -	ret = my_get_random(hash, SHA1_DIGEST_SIZE);
> +	ret = tpm_get_random(TPM_ANY_NUM, hash, SHA1_DIGEST_SIZE);
>  	if (ret < 0)
>  		return ret;

You are still not checking the return values correctly!

This needs to be something like:

	ret = tpm_get_random(TPM_ANY_NUM, hash, SHA1_DIGEST_SIZE);
	if (ret != SHA1_DIGEST_SIZE)
		return -EIO;	/* Or whatever is appropriate here */


	-hpa

  reply	other threads:[~2012-07-27 22:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-27 18:14 [GIT PULL] New TPM driver, hwrng driver and fixes Kent Yoder
2012-07-27 18:24 ` H. Peter Anvin
2012-07-27 19:36   ` Kent Yoder
2012-07-27 20:30   ` Kent Yoder
2012-07-27 22:09     ` H. Peter Anvin [this message]
2012-07-28  0:45       ` Kent Yoder
2012-07-30 20:51         ` Kent Yoder
2012-07-30 20:52           ` H. Peter Anvin
2012-08-13 20:44 ` H. Peter Anvin
2012-08-14 16:37   ` Kent Yoder

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=5013118D.2030601@zytor.com \
    --to=hpa@zytor.com \
    --cc=bfreed@chromium.org \
    --cc=jmorris@namei.org \
    --cc=key@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=peter.huewe@infineon.com \
    --cc=safford@linux.vnet.ibm.com \
    --cc=tpmdd-devel@lists.sourceforge.net \
    /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.