From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753216AbdARNue (ORCPT ); Wed, 18 Jan 2017 08:50:34 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:55845 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753148AbdARNub (ORCPT ); Wed, 18 Jan 2017 08:50:31 -0500 Subject: Re: [PATCH v4 1/2] tpm: implement TPM 2.0 capability to get active PCR banks To: Jarkko Sakkinen References: <1484729090-16012-1-git-send-email-nayna@linux.vnet.ibm.com> <1484729090-16012-2-git-send-email-nayna@linux.vnet.ibm.com> <20170118134522.ftikno7gy3vttv6w@intel.com> Cc: tpmdd-devel@lists.sourceforge.net, peterhuewe@gmx.de, tpmdd@selhorst.net, jgunthorpe@obsidianresearch.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org From: Nayna Date: Wed, 18 Jan 2017 19:19:06 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20170118134522.ftikno7gy3vttv6w@intel.com> 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: 17011813-0024-0000-0000-000015BB36EE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006456; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000199; SDB=6.00809338; UDB=6.00394265; IPR=6.00586696; BA=6.00005071; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013964; XFM=3.00000011; UTC=2017-01-18 13:49:36 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17011813-0025-0000-0000-0000480C9CF1 Message-Id: <587F7252.4070808@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-01-18_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701180188 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/18/2017 07:15 PM, Jarkko Sakkinen wrote: > On Wed, Jan 18, 2017 at 03:44:49AM -0500, Nayna Jain wrote: >> This patch implements the TPM 2.0 capability TPM_CAP_PCRS to >> retrieve the active PCR banks from the TPM. This is needed >> to enable extending all active banks as recommended by TPM 2.0 >> TCG Specification. >> >> Signed-off-by: Nayna Jain >> --- >> drivers/char/tpm/tpm.h | 4 ++++ >> drivers/char/tpm/tpm2-cmd.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 61 insertions(+) >> >> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h >> index 1ae9768..dddd573 100644 >> --- a/drivers/char/tpm/tpm.h >> +++ b/drivers/char/tpm/tpm.h >> @@ -127,6 +127,7 @@ enum tpm2_permanent_handles { >> }; >> >> enum tpm2_capabilities { >> + TPM2_CAP_PCRS = 5, >> TPM2_CAP_TPM_PROPERTIES = 6, >> }; >> >> @@ -187,6 +188,8 @@ struct tpm_chip { >> >> const struct attribute_group *groups[3]; >> unsigned int groups_cnt; >> + >> + u16 active_banks[7]; >> #ifdef CONFIG_ACPI >> acpi_handle acpi_dev_handle; >> char ppi_version[TPM_PPI_VERSION_LEN + 1]; >> @@ -545,4 +548,5 @@ int tpm2_auto_startup(struct tpm_chip *chip); >> void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); >> unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); >> int tpm2_probe(struct tpm_chip *chip); >> +ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip); >> #endif >> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c >> index 6eda239..75a7546 100644 >> --- a/drivers/char/tpm/tpm2-cmd.c >> +++ b/drivers/char/tpm/tpm2-cmd.c >> @@ -998,3 +998,60 @@ int tpm2_auto_startup(struct tpm_chip *chip) >> rc = -ENODEV; >> return rc; >> } >> + >> +struct tpm2_pcr_selection { >> + __be16 hash_alg; >> + u8 size_of_select; >> + u8 pcr_select[3]; >> +} __packed; >> + >> +/** >> + * tpm2_get_pcr_allocation() - get TPM active PCR banks. >> + * >> + * @chip: TPM chip to use. >> + * >> + * Return: Same as with tpm_transmit_cmd. >> + */ >> +ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) >> +{ >> + struct tpm2_pcr_selection pcr_selection; >> + struct tpm_buf buf; >> + void *marker; >> + unsigned int count = 0; > > You shouldn't initialize 'count'. It is initialized for reason below: > >> + int rc; >> + int i; >> + >> + rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); >> + if (rc) >> + return rc; >> + >> + tpm_buf_append_u32(&buf, TPM2_CAP_PCRS); >> + tpm_buf_append_u32(&buf, 0); >> + tpm_buf_append_u32(&buf, 1); >> + >> + rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 0, >> + "get tpm pcr allocation"); >> + if (rc < 0) >> + goto out; if tpm_transmit_cmd()fails, it jumps to out: where count is used in if(..). Thanks & Regards, - Nayna >> + >> + count = be32_to_cpup( >> + (__be32 *)&buf.data[TPM_HEADER_SIZE + 5]); >> + >> + if (count > ARRAY_SIZE(chip->active_banks)) >> + return -ENODEV; >> + >> + marker = &buf.data[TPM_HEADER_SIZE + 9]; >> + for (i = 0; i < count; i++) { >> + memcpy(&pcr_selection, marker, sizeof(pcr_selection)); >> + chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg); >> + marker = marker + sizeof(struct tpm2_pcr_selection); >> + } >> + >> +out: >> + if (count < ARRAY_SIZE(chip->active_banks)) >> + chip->active_banks[count] = 0; >> + >> + tpm_buf_destroy(&buf); >> + >> + return rc; >> +} >> -- >> 2.5.0 > > Otherwise, > > Reviewed-by: Jarkko Sakkinen > > /Jarkko >