Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1573093

Re: [tpmdd-devel] [PATCH] tpm: fix type issues in tpm_getcap()

Path csiph.com!1.us.feeder.erje.net!feeder.erje.net!2.eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Nayna <nayna@linux.vnet.ibm.com>
Newsgroups linux.kernel
Subject Re: [tpmdd-devel] [PATCH] tpm: fix type issues in tpm_getcap()
Date Fri, 03 Feb 2017 14:50:02 +0100
Message-ID <t6Mps-2cV-13@gated-at.bofh.it> (permalink)
References <t67mj-x1-23@gated-at.bofh.it>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
MIME-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Tm-As-Gconf 00
X-Content-Scanned Fidelis XPS MAILER
X-Cbid 17020313-0020-0000-0000-00000B44464B
X-Ibm-Spammodules-Versions BY=3.00006549; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000201; SDB=6.00816665; UDB=6.00398832; IPR=6.00594101; BA=6.00005113; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014167; XFM=3.00000011; UTC=2017-02-03 13:49:22
X-Ibm-Av-Detection SAVI=unused REMOTE=unused XFE=unused
X-Cbparentid 17020313-0021-0000-0000-000059CBBB66
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:,, definitions=2017-02-03_09:,, signatures=0
X-Proofpoint-Spam-Details rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=9 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702030136
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 133
Organization linux.* mail to news gateway
X-Original-Cc open list <linux-kernel@vger.kernel.org>, linux-security-module@vger.kernel.org
X-Original-Date Fri, 3 Feb 2017 19:18:53 +0530
X-Original-Message-ID <58948A45.5020105@linux.vnet.ibm.com>
X-Original-References <20170201175347.2035-1-jarkko.sakkinen@linux.intel.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1573093

Show key headers only | View raw



On 02/01/2017 11:23 PM, Jarkko Sakkinen wrote:
> There are two type issues associated with tpm_getcap().
>
> You must not do arithmetic with __be32 or __le32 types because sometimes
> it results incorrect results. Calculations must be done only with data
> that is in CPU byte order. This commit migrates tpm_getcap() to struct
> tpm_buf in order to sort out these issues.
>
> The second issue is with struct cap_t as the size of the type bool is
> assumed to be one byte. This commit sorts out the issue by changing the
> type to u8.
>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
> v2:
> - Use struct tpm_buf.
> - Merge the type change of 'owned' to this patch.
>   drivers/char/tpm/tpm-interface.c | 33 ++++++++++++++++++---------------
>   drivers/char/tpm/tpm.h           | 15 +--------------
>   2 files changed, 19 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 423938e..7af1e8c 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -480,31 +480,34 @@ 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, size_t min_cap_length)
>   {
> -	struct tpm_cmd_t tpm_cmd;
> +	struct tpm_buf buf;
>   	int rc;
>
> -	tpm_cmd.header.in = tpm_getcap_header;
> +	rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_CAP);

I think there is a problem here of twice converting to be32 for both tag 
and ordinal.

Both TPM_ORD_GET_CAP and TPM_TAG_RQU_COMMAND are already defined as:
#define TPM_ORD_GET_CAP cpu_to_be32(101)
#define TPM_TAG_RQU_COMMAND  cpu_to_be16(193)

and again converted to BE in tpm_buf_init().

Thanks & Regards,
    - Nayna

> +	if (rc)
> +		return rc;
> +
>   	if (subcap_id == TPM_CAP_VERSION_1_1 ||
>   	    subcap_id == TPM_CAP_VERSION_1_2) {
> -		tpm_cmd.params.getcap_in.cap = cpu_to_be32(subcap_id);
> -		/*subcap field not necessary */
> -		tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(0);
> -		tpm_cmd.header.in.length -= cpu_to_be32(sizeof(__be32));
> +		tpm_buf_append_u32(&buf, subcap_id);
> +		tpm_buf_append_u32(&buf, 0);
>   	} else {
>   		if (subcap_id == TPM_CAP_FLAG_PERM ||
>   		    subcap_id == TPM_CAP_FLAG_VOL)
> -			tpm_cmd.params.getcap_in.cap =
> -				cpu_to_be32(TPM_CAP_FLAG);
> +			tpm_buf_append_u32(&buf, TPM_CAP_FLAG);
>   		else
> -			tpm_cmd.params.getcap_in.cap =
> -				cpu_to_be32(TPM_CAP_PROP);
> -		tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
> -		tpm_cmd.params.getcap_in.subcap = cpu_to_be32(subcap_id);
> +			tpm_buf_append_u32(&buf, TPM_CAP_PROP);
> +
> +		tpm_buf_append_u32(&buf, 4);
> +		tpm_buf_append_u32(&buf, subcap_id);
>   	}
> -	rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
> -			      min_cap_length, 0, desc);
> +
> +	rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, min_cap_length, 0,
> +			      desc);
>   	if (!rc)
> -		*cap = tpm_cmd.params.getcap_out.cap;
> +		*cap = *(cap_t *)&buf.data[TPM_HEADER_SIZE + 4];
> +
> +	tpm_buf_destroy(&buf);
>   	return rc;
>   }
>   EXPORT_SYMBOL_GPL(tpm_getcap);
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index bff37be..709e7d4 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -281,7 +281,7 @@ struct permanent_flags_t {
>   typedef union {
>   	struct	permanent_flags_t perm_flags;
>   	struct	stclear_flags_t	stclear_flags;
> -	bool	owned;
> +	u8	owned;
>   	__be32	num_pcrs;
>   	struct	tpm_version_t	tpm_version;
>   	struct	tpm_version_1_2_t tpm_version_1_2;
> @@ -307,17 +307,6 @@ enum tpm_sub_capabilities {
>   	TPM_CAP_PROP_TIS_DURATION = 0x120,
>   };
>
> -struct	tpm_getcap_params_in {
> -	__be32	cap;
> -	__be32	subcap_size;
> -	__be32	subcap;
> -} __packed;
> -
> -struct	tpm_getcap_params_out {
> -	__be32	cap_size;
> -	cap_t	cap;
> -} __packed;
> -
>   struct	tpm_readpubek_params_out {
>   	u8	algorithm[4];
>   	u8	encscheme[2];
> @@ -367,10 +356,8 @@ struct tpm_startup_in {
>   } __packed;
>
>   typedef union {
> -	struct	tpm_getcap_params_out getcap_out;
>   	struct	tpm_readpubek_params_out readpubek_out;
>   	u8	readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)];
> -	struct	tpm_getcap_params_in getcap_in;
>   	struct	tpm_pcrread_in	pcrread_in;
>   	struct	tpm_pcrread_out	pcrread_out;
>   	struct	tpm_pcrextend_in pcrextend_in;
>

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[PATCH] tpm: fix type issues in tpm_getcap() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-02-01 19:00 +0100
  Re: [PATCH] tpm: fix type issues in tpm_getcap() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-02-01 19:20 +0100
    Re: [PATCH] tpm: fix type issues in tpm_getcap() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-02-01 19:40 +0100
  Re: [PATCH] tpm: fix type issues in tpm_getcap() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-02-01 19:50 +0100
  Re: [PATCH] tpm: fix type issues in tpm_getcap() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-02-02 15:00 +0100
  Re: [tpmdd-devel] [PATCH] tpm: fix type issues in tpm_getcap() Nayna <nayna@linux.vnet.ibm.com> - 2017-02-03 14:00 +0100
    Re: [tpmdd-devel] [PATCH] tpm: fix type issues in tpm_getcap() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-02-03 19:20 +0100
      Re: [tpmdd-devel] [PATCH] tpm: fix type issues in tpm_getcap() Nayna <nayna@linux.vnet.ibm.com> - 2017-02-03 19:50 +0100
        Re: [tpmdd-devel] [PATCH] tpm: fix type issues in tpm_getcap() Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-02-03 20:10 +0100
  Re: [tpmdd-devel] [PATCH] tpm: fix type issues in tpm_getcap() Nayna <nayna@linux.vnet.ibm.com> - 2017-02-03 14:50 +0100

csiph-web