tpmdd-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Nayna <nayna-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Jarkko Sakkinen
	<jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: "moderated list:TPM DEVICE DRIVER"
	<tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	open list <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd
Date: Thu, 17 Nov 2016 17:20:36 +0530	[thread overview]
Message-ID: <582D998C.40605@linux.vnet.ibm.com> (raw)
In-Reply-To: <20161112000242.63hgv5ujmkr7hy6a-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>



On 11/12/2016 05:32 AM, Jarkko Sakkinen wrote:
> On Fri, Nov 11, 2016 at 09:51:45AM +0530, Nayna wrote:
>>
>>
>> On 10/09/2016 03:44 PM, Jarkko Sakkinen wrote:
>>> Refactored tpm2_get_tpm_pt to tpm2_getcap_cmd, which means that it also
>>> takes capability ID as input. This is required to access
>>> TPM_CAP_HANDLES, which contains metadata needed for swapping transient
>>> data.
>>>
>>> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
>>> ---
>>>    drivers/char/tpm/tpm.h          |  6 +++-
>>>    drivers/char/tpm/tpm2-cmd.c     | 64 ++++++++++++++++++++---------------------
>>>    drivers/char/tpm/tpm_tis_core.c |  3 +-
>>>    3 files changed, 38 insertions(+), 35 deletions(-)
>>>
>>> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
>>> index 0fab6d5..8176f42 100644
>>> --- a/drivers/char/tpm/tpm.h
>>> +++ b/drivers/char/tpm/tpm.h
>>> @@ -85,6 +85,10 @@ enum tpm2_capabilities {
>>>    	TPM2_CAP_TPM_PROPERTIES = 6,
>>>    };
>>>
>>> +enum tpm2_properties {
>>> +	TPM2_PT_FAMILY_INDICATOR	= 0x100,
>>> +};
>>> +
>>>    enum tpm2_startup_types {
>>>    	TPM2_SU_CLEAR	= 0x0000,
>>>    	TPM2_SU_STATE	= 0x0001,
>>> @@ -485,7 +489,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
>>>    int tpm2_unseal_trusted(struct tpm_chip *chip,
>>>    			struct trusted_key_payload *payload,
>>>    			struct trusted_key_options *options);
>>> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
>>> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
>>>    			u32 *value, const char *desc);
>>>
>>>    int tpm2_auto_startup(struct tpm_chip *chip);
>>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>>> index 2900e18..fcf3d86 100644
>>> --- a/drivers/char/tpm/tpm2-cmd.c
>>> +++ b/drivers/char/tpm/tpm2-cmd.c
>>> @@ -111,13 +111,13 @@ struct tpm2_pcr_extend_in {
>>>    	u8				digest[TPM_DIGEST_SIZE];
>>>    } __packed;
>>>
>>> -struct tpm2_get_tpm_pt_in {
>>> +struct tpm2_getcap_in {
>>>    	__be32	cap_id;
>>>    	__be32	property_id;
>>>    	__be32	property_cnt;
>>>    } __packed;
>>>
>>> -struct tpm2_get_tpm_pt_out {
>>> +struct tpm2_getcap_out {
>>>    	u8	more_data;
>>>    	__be32	subcap_id;
>>>    	__be32	property_cnt;
>>> @@ -140,8 +140,8 @@ union tpm2_cmd_params {
>>>    	struct	tpm2_pcr_read_in	pcrread_in;
>>>    	struct	tpm2_pcr_read_out	pcrread_out;
>>>    	struct	tpm2_pcr_extend_in	pcrextend_in;
>>> -	struct	tpm2_get_tpm_pt_in	get_tpm_pt_in;
>>> -	struct	tpm2_get_tpm_pt_out	get_tpm_pt_out;
>>> +	struct	tpm2_getcap_in		getcap_in;
>>> +	struct	tpm2_getcap_out		getcap_out;
>>>    	struct	tpm2_get_random_in	getrandom_in;
>>>    	struct	tpm2_get_random_out	getrandom_out;
>>>    };
>>> @@ -435,16 +435,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max)
>>>    	return total ? total : -EIO;
>>>    }
>>>
>>> -#define TPM2_GET_TPM_PT_IN_SIZE \
>>> -	(sizeof(struct tpm_input_header) + \
>>> -	 sizeof(struct tpm2_get_tpm_pt_in))
>>> -
>>> -static const struct tpm_input_header tpm2_get_tpm_pt_header = {
>>> -	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
>>> -	.length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE),
>>> -	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
>>> -};
>>> -
>>>    /**
>>>     * Append TPMS_AUTH_COMMAND to the buffer. The buffer must be allocated with
>>>     * tpm_buf_alloc().
>>> @@ -750,35 +740,43 @@ out:
>>>    	return rc;
>>>    }
>>>
>>> +#define TPM2_GETCAP_IN_SIZE \
>>> +	(sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
>>> +
>>> +static const struct tpm_input_header tpm2_getcap_header = {
>>> +	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
>>> +	.length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
>>> +	.ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
>>> +};
>>> +
>>>    /**
>>> - * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property
>>> - * @chip:		TPM chip to use.
>>> - * @property_id:	property ID.
>>> - * @value:		output variable.
>>> + * tpm2_getcap_cmd() - execute a TPM2_GetCapability command
>>> + * @chip:		TPM chip to use
>>> + * @cap_id:		capability ID
>>> + * @property_id:	property ID
>>> + * @value:		value of the property
>>>     * @desc:		passed to tpm_transmit_cmd()
>>>     *
>>> - * 0 is returned when the operation is successful. If a negative number is
>>> - * returned it remarks a POSIX error code. If a positive number is returned
>>> - * it remarks a TPM error.
>>> + * Return: same as with tpm_transmit_cmd
>>>     */
>>> -ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,  u32 *value,
>>> -			const char *desc)
>>> +ssize_t tpm2_getcap_cmd(struct tpm_chip *chip, u32 cap_id, u32 property_id,
>>> +			u32 *value, const char *desc)
>>
>> This function currently returns single value "u32 *value" as output data.
>>
>> Some calling function expect list of values from capabilities output.
>> For eg., get_active_banks() use TPM_CAP_PCRS capability to retrieve list of
>> active banks. And this capability returns array of pcr selections(which is a
>> struct representing each active PCR bank)
>>
>> I was thinking, can we define output parameter as struct of cap_id and union
>> of expected cap_data ?
>
> Unless you have major concerns about performance, which I think are not
> relevant here, calling this in a loop is perfectly adequate and a lot of
> simpler than having a generic version (with moreData handling and
> everything).
>
> I would rather see uses of struct cap_t to shrink than to expand. The
> same goes for other horrific unions that exist today in the driver.

I agree with the idea of not using union.

I tested this for capability TPM2_CAP_PCRS. It seems TPM2_CAP_PCRS 
capability always returns full PCR allocation, and more_data as 0, So, I 
think the idea of looping over based on more_data may not work for this 
capability.

I was thinking in place of having u32 *value returning actual value, can 
we have it as void *value, where getcap_cmd will memcpy its out 
parameter content after subcap_id to value, and then calling function 
typecast to expected type and use it.

Please let me know if I am missing something in using this function.

Thanks & Regards,
    - Nayna


>
> /Jarkko
>


------------------------------------------------------------------------------

  parent reply	other threads:[~2016-11-17 11:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-09 10:14 [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
     [not found] ` <1476008057-2395-1-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-10-09 10:14   ` [PATCH RFC 1/2] tpm: move TPM 2.0 command and response constants to tpm2-cmd.c Jarkko Sakkinen
2016-10-09 10:14   ` [PATCH RFC 2/2] tpm: refactor tpm2_get_tpm_pt to tpm2_getcap_cmd Jarkko Sakkinen
     [not found]     ` <1476008057-2395-3-git-send-email-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-11-11  4:21       ` Nayna
2016-11-12  0:02         ` [tpmdd-devel] " Jarkko Sakkinen
2016-11-14 23:48           ` Jarkko Sakkinen
2016-11-24 13:42             ` Nayna
     [not found]               ` <5836EE61.4010200-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-11-25  8:09                 ` Jarkko Sakkinen
     [not found]           ` <20161112000242.63hgv5ujmkr7hy6a-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-11-17 11:50             ` Nayna [this message]
     [not found]               ` <582D998C.40605-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-11-17 17:42                 ` Jarkko Sakkinen
2016-11-18 12:12                   ` [tpmdd-devel] " Nayna
2016-11-18 16:13                     ` Jarkko Sakkinen
     [not found]                       ` <20161118161224.7sq4dbcnyzumbvds-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-11-22  9:08                         ` Nayna
2016-11-22 11:03                           ` [tpmdd-devel] " Jarkko Sakkinen
2016-11-04  7:28 ` [PATCH RFC 0/2] Generalize tpm2_get_tpm_pt to tpm2_get_cap Jarkko Sakkinen
2016-11-11  4:42   ` Nayna

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=582D998C.40605@linux.vnet.ibm.com \
    --to=nayna-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
    --cc=jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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;
as well as URLs for NNTP newsgroup(s).