From patchwork Fri Dec 30 19:02:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nayna X-Patchwork-Id: 709861 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 3tqwpV4Wmdz9t1F for ; Sat, 31 Dec 2016 06:02:58 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cN2S9-00037v-0J; Fri, 30 Dec 2016 19:02:57 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cN2S7-00037i-O3 for tpmdd-devel@lists.sourceforge.net; Fri, 30 Dec 2016 19:02:55 +0000 X-ACL-Warn: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5] helo=mx0a-001b2d01.pphosted.com) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1cN2S4-0004nB-3o for tpmdd-devel@lists.sourceforge.net; Fri, 30 Dec 2016 19:02:55 +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 uBUIweOg104285 for ; Fri, 30 Dec 2016 14:02:46 -0500 Received: from e23smtp01.au.ibm.com (e23smtp01.au.ibm.com [202.81.31.143]) by mx0b-001b2d01.pphosted.com with ESMTP id 27nncqbkdu-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 30 Dec 2016 14:02:46 -0500 Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 31 Dec 2016 05:02:43 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 31 Dec 2016 05:02:40 +1000 Received: from d23relay09.au.ibm.com (d23relay09.au.ibm.com [9.185.63.181]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 67E962CE8056 for ; Sat, 31 Dec 2016 06:02:40 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uBUJ2eZo5571018 for ; Sat, 31 Dec 2016 06:02:40 +1100 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uBUJ2dQ5000614 for ; Sat, 31 Dec 2016 06:02:40 +1100 Received: from c365f16u1b3.pok.stglabs.ibm.com (c365f16u1b3.pok.stglabs.ibm.com [9.47.77.42]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id uBUJ2WId000354; Sat, 31 Dec 2016 06:02:37 +1100 From: Nayna Jain To: tpmdd-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 30 Dec 2016 14:02:29 -0500 X-Mailer: git-send-email 2.5.0 In-Reply-To: <1483124550-9529-1-git-send-email-nayna@linux.vnet.ibm.com> References: <1483124550-9529-1-git-send-email-nayna@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16123019-1617-0000-0000-00000194991D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16123019-1618-0000-0000-000047755134 Message-Id: <1483124550-9529-2-git-send-email-nayna@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-12-30_14:, , 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-1612300297 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: 1cN2S4-0004nB-3o Subject: [tpmdd-devel] [PATCH v2 1/2] tpm: implement TPM 2.0 capability to get active PCR banks 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: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net 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 | 5 +++ drivers/char/tpm/tpm2-cmd.c | 79 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 1ae9768..3d8121e 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -43,6 +43,7 @@ enum tpm_const { TPM_NUM_DEVICES = 65536, TPM_RETRY = 50, /* 5 seconds */ TPM_NUM_EVENT_LOG_FILES = 3, + TPM2_MAX_PCR_BANKS = 7, }; enum tpm_timeout { @@ -127,6 +128,7 @@ enum tpm2_permanent_handles { }; enum tpm2_capabilities { + TPM2_CAP_PCRS = 5, TPM2_CAP_TPM_PROPERTIES = 6, }; @@ -187,6 +189,8 @@ struct tpm_chip { const struct attribute_group *groups[3]; unsigned int groups_cnt; + + enum tpm2_algorithms active_banks[TPM2_MAX_PCR_BANKS]; #ifdef CONFIG_ACPI acpi_handle acpi_dev_handle; char ppi_version[TPM_PPI_VERSION_LEN + 1]; @@ -545,4 +549,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..dd03fd8 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -83,6 +83,25 @@ struct tpm2_get_tpm_pt_out { __be32 value; } __packed; +struct tpm2_tpms_pcr_selection { + __be16 hash_alg; + u8 size_of_select; + u8 pcr_select[3]; +} __packed; + +struct tpm2_getcap_in { + __be32 cap_id; + __be32 property_id; + __be32 property_cnt; +} __packed; + +struct tpm2_getcap_out { + u8 more_data; + __be32 subcap_id; + __be32 count; + char cap_data[0]; +} __packed; + struct tpm2_get_random_in { __be16 size; } __packed; @@ -100,6 +119,8 @@ union tpm2_cmd_params { 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; }; @@ -993,8 +1014,66 @@ int tpm2_auto_startup(struct tpm_chip *chip) } } + rc = tpm2_get_pcr_allocation(chip); + out: if (rc > 0) rc = -ENODEV; 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_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_cmd cmd; + struct tpm2_tpms_pcr_selection pcr_selection; + void *marker; + unsigned int count = 0; + int rc; + int i; + + cmd.header.in = tpm2_getcap_header; + cmd.params.getcap_in.cap_id = cpu_to_be32(TPM2_CAP_PCRS); + cmd.params.getcap_in.property_id = cpu_to_be32(0); + cmd.params.getcap_in.property_cnt = cpu_to_be32(1); + + rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), 0, + "get tpm pcr allocation"); + if (rc < 0) + goto out; + + count = be32_to_cpu(cmd.params.getcap_out.count); + if (count > TPM2_MAX_PCR_BANKS) { + dev_err(&chip->dev, + "%s: Error: Invalid active PCR banks count\n", + __func__); + return -ENODEV; + } + + marker = &cmd.params.getcap_out.cap_data; + 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_tpms_pcr_selection); + } + +out: + if (count < TPM2_MAX_PCR_BANKS) + chip->active_banks[count] = 0; + return rc; +}