From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750797AbdAWCCa (ORCPT ); Sun, 22 Jan 2017 21:02:30 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:60917 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750710AbdAWCC2 (ORCPT ); Sun, 22 Jan 2017 21:02:28 -0500 Subject: Re: [tpmdd-devel] [PATCH RFC v4 1/5] tpm: validate TPM 2.0 commands To: Jarkko Sakkinen , tpmdd-devel@lists.sourceforge.net References: <20170122234438.12102-1-jarkko.sakkinen@linux.intel.com> <20170122234438.12102-2-jarkko.sakkinen@linux.intel.com> Cc: open list , linux-security-module@vger.kernel.org From: Stefan Berger Date: Sun, 22 Jan 2017 21:02:17 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <20170122234438.12102-2-jarkko.sakkinen@linux.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: 17012302-0004-0000-0000-0000115C2663 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006481; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000200; SDB=6.00811307; UDB=6.00395538; IPR=6.00588723; BA=6.00005082; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014007; XFM=3.00000011; UTC=2017-01-23 02:02:25 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17012302-0005-0000-0000-00007C648A64 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-01-23_01:,, 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-1701230028 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/22/2017 06:44 PM, Jarkko Sakkinen wrote: > @@ -1025,8 +1029,60 @@ int tpm2_auto_startup(struct tpm_chip *chip) > } > } > > + rc = tpm2_get_tpm_pt(chip, TPM_PT_TOTAL_COMMANDS, &nr_commands, NULL); > + if (rc) > + goto out; > + > + /* sanity check */ > + if (nr_commands > INT_MAX) { > + rc = -E2BIG; > + goto out; > + } > + > + chip->cc_attrs_tbl = devm_kzalloc(&chip->dev, 4 * nr_commands, > + GFP_KERNEL); > + > + rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); > + if (rc) > + goto out; > + > + tpm_buf_append_u32(&buf, TPM2_CAP_COMMANDS); > + tpm_buf_append_u32(&buf, TPM2_CC_FIRST); > + tpm_buf_append_u32(&buf, nr_commands); > + > + rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 0, 0, NULL); You should probably pass the min_rsp_body_size as 5 + 4 + nr_commands * 4 > + if (rc < 0) { > + tpm_buf_destroy(&buf); > + goto out; > + } > + > + if (nr_commands != > + be32_to_cpup((__be32 *)&buf.data[TPM_HEADER_SIZE + 5])) { > + tpm_buf_destroy(&buf); > + goto out; > + } > + > + chip->nr_commands = nr_commands; > + > + attrs = (u32 *)&buf.data[TPM_HEADER_SIZE + 9]; > + for (i = 0; i < nr_commands; i++, attrs++) > + chip->cc_attrs_tbl[i] = be32_to_cpup(attrs); > + > + tpm_buf_destroy(&buf); > + > out: > if (rc > 0) > rc = -ENODEV; > return rc; > } > + > +int tpm2_find_cc(struct tpm_chip *chip, u32 cc) > +{ > + int i; > + > + for (i = 0; i < chip->nr_commands; i++) > + if (cc == (chip->cc_attrs_tbl[i] & GENMASK(15, 0))) > + return i; > + > + return -1; > +}