Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp811277ybn; Wed, 2 Oct 2019 06:36:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQ3s0S3Sk+37MSq/2y0rMmH77bT97TKPN+kBupx8JC1mOnzK8PcNXG5fR6M4v+7Na/psZg X-Received: by 2002:a50:98c6:: with SMTP id j64mr3879147edb.34.1570023391164; Wed, 02 Oct 2019 06:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570023391; cv=none; d=google.com; s=arc-20160816; b=KEQuzWQc7KhrVRzO21kiMhAtVcWMUBKKLfK2GiaRNGipRTybi1fCBdapoEvepp+E2F GkjoIKe2U+m6dcrhWwmPf7UG1TDUIrfvV96/2rufnUvlAt1GB4updRMtvXu4dk/2Ejk+ RD7llj0eD9PL+72Ab1y1VQNvjsUFCxKnbz3IXefZyF5KwFQGSMtesa/yBZwPpd3vX+Bb XomeitNh9PDzw2+prpyDrmnyOgZWHt/5O4bf3K6GGWMWh7Mi6+SGsJ6F/RyQNK97Enpm ZTQnjnLWGB2u+pydYdxQI10VeiM+UrEBK8ZhiWatZRbljgeUgpf5Da/7Z7EYv2XBOxpB Rkbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XabjDaV4HZw5JRWAlAzdvRUEiPwZyRoTGye4TG0dZOg=; b=hJq3u2A3GXdB2y9C2ZX6Sr0P+1KIMY5dLoPJqbTHeOg0qnKUWrJx4yJ3a3YmMCMrjL VMZuN31q6z+hcm2CSM7EhfCxaJfG7Wmn0bfjJKxyyOY8suDHadzpVQWmd3Yl08d0IOBC NJcOorsa3bDYRYDySZz1x3fJhG+fH3XOXMGm6gG1Qwycur65WppULqUDWy3RJ4N2ZVFH CQdR3MOZxbxG2OhT6/t5wWIeiA7k++ZF140dl+eG4cNSCJn6Qy4byIRMGqJCVf7bX1f3 YPq33o6cWjUNR/ftSKbBHDciPVSA7sbPDxZmPUNCo7MKVOCfa9GN7x5Qwkv3dBBIAy2F sM+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t7si10938022ejo.302.2019.10.02.06.36.07; Wed, 02 Oct 2019 06:36:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727632AbfJBNO5 (ORCPT + 99 others); Wed, 2 Oct 2019 09:14:57 -0400 Received: from mga17.intel.com ([192.55.52.151]:39472 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727134AbfJBNO5 (ORCPT ); Wed, 2 Oct 2019 09:14:57 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Oct 2019 06:14:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,574,1559545200"; d="scan'208";a="203589788" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.158]) by orsmga002.jf.intel.com with ESMTP; 02 Oct 2019 06:14:53 -0700 From: Jarkko Sakkinen To: linux-stabley@vger.kernel.org Cc: Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , linux-integrity@vger.kernel.org (open list:TPM DEVICE DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/3] tpm: migrate pubek_show to struct tpm_buf Date: Wed, 2 Oct 2019 16:14:42 +0300 Message-Id: <20191002131445.7793-2-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191002131445.7793-1-jarkko.sakkinen@linux.intel.com> References: <20191002131445.7793-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit da379f3c1db0c9a1fd27b11d24c9894b5edc7c75 upstream Migrated pubek_show to struct tpm_buf and cleaned up its implementation. Previously the output parameter structure was declared but left completely unused. Now it is used to refer different fields of the output. We can move it to tpm-sysfs.c as it does not have any use outside of that file. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-sysfs.c | 87 ++++++++++++++++++++---------------- drivers/char/tpm/tpm.h | 13 ------ 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index 86f38d239476..83a77a445538 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -20,44 +20,48 @@ #include #include "tpm.h" -#define READ_PUBEK_RESULT_SIZE 314 +struct tpm_readpubek_out { + u8 algorithm[4]; + u8 encscheme[2]; + u8 sigscheme[2]; + __be32 paramsize; + u8 parameters[12]; + __be32 keysize; + u8 modulus[256]; + u8 checksum[20]; +} __packed; + #define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256) #define TPM_ORD_READPUBEK 124 -static const struct tpm_input_header tpm_readpubek_header = { - .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), - .length = cpu_to_be32(30), - .ordinal = cpu_to_be32(TPM_ORD_READPUBEK) -}; + static ssize_t pubek_show(struct device *dev, struct device_attribute *attr, char *buf) { - u8 *data; - struct tpm_cmd_t tpm_cmd; - ssize_t err; - int i, rc; + struct tpm_buf tpm_buf; + struct tpm_readpubek_out *out; + ssize_t rc; + int i; char *str = buf; struct tpm_chip *chip = to_tpm_chip(dev); + char anti_replay[20]; - memset(&tpm_cmd, 0, sizeof(tpm_cmd)); - - tpm_cmd.header.in = tpm_readpubek_header; - err = tpm_transmit_cmd(chip, NULL, &tpm_cmd, READ_PUBEK_RESULT_SIZE, - READ_PUBEK_RESULT_MIN_BODY_SIZE, 0, - "attempting to read the PUBEK"); - if (err) - goto out; - - /* - ignore header 10 bytes - algorithm 32 bits (1 == RSA ) - encscheme 16 bits - sigscheme 16 bits - parameters (RSA 12->bytes: keybit, #primes, expbit) - keylenbytes 32 bits - 256 byte modulus - ignore checksum 20 bytes - */ - data = tpm_cmd.params.readpubek_out_buffer; + memset(&anti_replay, 0, sizeof(anti_replay)); + + rc = tpm_buf_init(&tpm_buf, TPM_TAG_RQU_COMMAND, TPM_ORD_READPUBEK); + if (rc) + return rc; + + tpm_buf_append(&tpm_buf, anti_replay, sizeof(anti_replay)); + + rc = tpm_transmit_cmd(chip, NULL, tpm_buf.data, PAGE_SIZE, + READ_PUBEK_RESULT_MIN_BODY_SIZE, 0, + "attempting to read the PUBEK"); + if (rc) { + tpm_buf_destroy(&tpm_buf); + return 0; + } + + out = (struct tpm_readpubek_out *)&tpm_buf.data[10]; str += sprintf(str, "Algorithm: %02X %02X %02X %02X\n" @@ -68,21 +72,26 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr, "%02X %02X %02X %02X\n" "Modulus length: %d\n" "Modulus:\n", - data[0], data[1], data[2], data[3], - data[4], data[5], - data[6], data[7], - data[12], data[13], data[14], data[15], - data[16], data[17], data[18], data[19], - data[20], data[21], data[22], data[23], - be32_to_cpu(*((__be32 *) (data + 24)))); + out->algorithm[0], out->algorithm[1], out->algorithm[2], + out->algorithm[3], + out->encscheme[0], out->encscheme[1], + out->sigscheme[0], out->sigscheme[1], + out->parameters[0], out->parameters[1], + out->parameters[2], out->parameters[3], + out->parameters[4], out->parameters[5], + out->parameters[6], out->parameters[7], + out->parameters[8], out->parameters[9], + out->parameters[10], out->parameters[11], + be32_to_cpu(out->keysize)); for (i = 0; i < 256; i++) { - str += sprintf(str, "%02X ", data[i + 28]); + str += sprintf(str, "%02X ", out->modulus[i]); if ((i + 1) % 16 == 0) str += sprintf(str, "\n"); } -out: + rc = str - buf; + tpm_buf_destroy(&tpm_buf); return rc; } static DEVICE_ATTR_RO(pubek); diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 4bb9b4aa9b49..d53d12f3df6d 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -351,17 +351,6 @@ enum tpm_sub_capabilities { TPM_CAP_PROP_TIS_DURATION = 0x120, }; -struct tpm_readpubek_params_out { - u8 algorithm[4]; - u8 encscheme[2]; - u8 sigscheme[2]; - __be32 paramsize; - u8 parameters[12]; /*assuming RSA*/ - __be32 keysize; - u8 modulus[256]; - u8 checksum[20]; -} __packed; - typedef union { struct tpm_input_header in; struct tpm_output_header out; @@ -391,8 +380,6 @@ struct tpm_getrandom_in { } __packed; typedef union { - struct tpm_readpubek_params_out readpubek_out; - u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)]; struct tpm_pcrread_in pcrread_in; struct tpm_pcrread_out pcrread_out; struct tpm_getrandom_in getrandom_in; -- 2.20.1