From patchwork Thu Jan 12 20:38:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 714653 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tzyKX04yHz9t2g for ; Fri, 13 Jan 2017 07:39:12 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cRm9K-0007zY-2X; Thu, 12 Jan 2017 20:39:06 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cRm9I-0007zT-NO for tpmdd-devel@lists.sourceforge.net; Thu, 12 Jan 2017 20:39:04 +0000 X-ACL-Warn: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5] helo=mx0a-001b2d01.pphosted.com) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1cRm9H-0000X5-S3 for tpmdd-devel@lists.sourceforge.net; Thu, 12 Jan 2017 20:39:04 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id v0CKXo9m126097 for ; Thu, 12 Jan 2017 15:38:58 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 27xcmtb013-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 12 Jan 2017 15:38:58 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Jan 2017 13:38:57 -0700 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 Jan 2017 13:38:56 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 45B0F1FF001F; Thu, 12 Jan 2017 13:38:34 -0700 (MST) Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v0CKctI38520174; Thu, 12 Jan 2017 13:38:55 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F2BC6E035; Thu, 12 Jan 2017 13:38:55 -0700 (MST) Received: from jarvis.ext.hansenpartnership.com (unknown [9.80.199.178]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTPS id 6AB116E040; Thu, 12 Jan 2017 13:38:54 -0700 (MST) From: James Bottomley To: Jarkko Sakkinen , tpmdd-devel@lists.sourceforge.net Date: Thu, 12 Jan 2017 12:38:52 -0800 In-Reply-To: <20170112174612.9314-4-jarkko.sakkinen@linux.intel.com> References: <20170112174612.9314-1-jarkko.sakkinen@linux.intel.com> <20170112174612.9314-4-jarkko.sakkinen@linux.intel.com> X-Mailer: Evolution 3.16.5 Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17011220-0008-0000-0000-0000068B8825 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006421; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000199; SDB=6.00806770; UDB=6.00392642; IPR=6.00584101; BA=6.00005052; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013906; XFM=3.00000011; UTC=2017-01-12 20:38:57 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17011220-0009-0000-0000-00003E979028 Message-Id: <1484253532.5807.16.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-12_14:, , 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-1701120270 X-Spam-Score: 0.0 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. X-Headers-End: 1cRm9H-0000X5-S3 Cc: linux-security-module@vger.kernel.org, open list Subject: Re: [tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net On Thu, 2017-01-12 at 19:46 +0200, Jarkko Sakkinen wrote: > +static int tpm2_map_response(struct tpm_chip *chip, u32 cc, u8 *rsp, > size_t len) > +{ > + struct tpm_space *space = &chip->work_space; > + u32 phandle; > + u32 vhandle; > + u32 attrs; > + int i; > + int rc; > + > + if (!tpm2_find_cc_attrs(chip, cc, &attrs)) { > + /* should never happen */ > + dev_err(&chip->dev, "TPM returned a different CC: > 0x%04x\n", > + cc); > + rc = -EFAULT; > + goto out_err; > + } > + > + if (!((attrs >> TPM2_CC_ATTR_RHANDLE) & 1)) > + return 0; > + > + phandle = be32_to_cpup((__be32 *)&rsp[TPM_HEADER_SIZE]); I think we have to check the command return code here. We can't blindly fish handles out of the response if the TPM returned an error because they won't exist and we'll pull rubbish from the buffer. Incremental patch below. Note I think we should use get_unaligned_be32 because we're pulling a 32 bit word from something that's on byte 6 (so misaligned): some architectures will trigger an unaligned trap for this (it's not a problem: they trap handle it, it just slows down processing a lot). James --- commit d17ad905ff7b114f7efd23f930e9a541ccdf7621 Author: James Bottomley Date: Wed Jan 11 22:01:29 2017 -0800 check return code ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 61422e6..8009ed4 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -90,6 +90,7 @@ enum tpm2_structures { }; enum tpm2_return_codes { + TPM2_RC_SUCCESS = 0x0000, TPM2_RC_HASH = 0x0083, /* RC_FMT1 */ TPM2_RC_HANDLE = 0x008B, TPM2_RC_INITIALIZE = 0x0100, /* RC_VER1 */ diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index ca55feb..44e5501 100644 --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -16,6 +16,7 @@ */ #include +#include #include "tpm.h" enum tpm2_handle_types { @@ -167,9 +168,13 @@ static int tpm2_map_response(struct tpm_chip *chip, u32 cc, u8 *rsp, size_t len) u32 phandle; u32 vhandle; u32 attrs; + u32 return_code = get_unaligned_be32((__be32 *)&rsp[6]); int i; int rc; + if (return_code != TPM2_RC_SUCCESS) + return 0; + if (!tpm2_find_cc_attrs(chip, cc, &attrs)) { /* should never happen */ dev_err(&chip->dev, "TPM returned a different CC: 0x%04x\n",