mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: tpmdd-devel@lists.sourceforge.net,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6] tpm: Check size of response before accessing data
Date: Tue, 17 Jan 2017 17:27:47 -0500	[thread overview]
Message-ID: <bc4ff967-1a5f-8e3e-c26e-07a13460a3a8@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170117144905.4haeudj3v5ycohr3@intel.com>

On 01/17/2017 09:49 AM, Jarkko Sakkinen wrote:
> On Mon, Jan 16, 2017 at 04:41:11PM -0500, Stefan Berger wrote:
>
>> + * @min_rx_length: minimum expected length of response
> Please, rename as min_rsp_body_len and change the description
> accordingly.
>
>>    * @flags: tpm transmit flags - bitmap
>>    * @desc: command description used in the error message
>>    *
>> @@ -434,25 +435,34 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
>>    *     A positive number for a TPM error.
>>    */
>>   ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *cmd,
>> -			 int len, unsigned int flags, const char *desc)
>> +			 size_t cmd_length, size_t min_rx_length,
>> +			 unsigned int flags, const char *desc)
>>   {
>>   	const struct tpm_output_header *header;
>>   	int err;
>> +	ssize_t len;
>>   
>> -	len = tpm_transmit(chip, (const u8 *)cmd, len, flags);
>> +	len = tpm_transmit(chip, (const u8 *)cmd, cmd_length, flags);
>>   	if (len <  0)
>>   		return len;
>>   	else if (len < TPM_HEADER_SIZE)
>>   		return -EFAULT;
>>   
>>   	header = cmd;
>> +	if (len < be32_to_cpu(header->length))
>> +		return -EFAULT;
>>   
>>   	err = be32_to_cpu(header->return_code);
>>   	if (err != 0 && desc)
>>   		dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err,
>>   			desc);
>> +	if (err)
>> +		return err;
>>   
>> -	return err;
>> +	if (be32_to_cpu(header->length) < min_rx_length)
>> +		return -EFAULT;
>> +
>> +	return 0;
>>   }
>>   
>>   #define TPM_DIGEST_SIZE 20
>> @@ -468,7 +478,7 @@ static const struct tpm_input_header tpm_getcap_header = {
>>   };
>>   
>>   ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
>> -		   const char *desc)
>> +		   const char *desc, size_t min_cap_length)
> tpm_getcap update should be its own commit.

tpm_getcap needs to pass something as min_rsp_body_length to 
tpm_transmit_cmd. What would it pass?

  reply	other threads:[~2017-01-17 22:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-16 21:41 Stefan Berger
2017-01-17 14:49 ` Jarkko Sakkinen
2017-01-17 22:27   ` Stefan Berger [this message]
2017-01-18 13:36     ` Jarkko Sakkinen
2017-01-18 13:53       ` Stefan Berger
2017-01-19 10:44         ` Jarkko Sakkinen

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=bc4ff967-1a5f-8e3e-c26e-07a13460a3a8@linux.vnet.ibm.com \
    --to=stefanb@linux.vnet.ibm.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --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 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®