From patchwork Thu May 25 21:11:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9749151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 25F8860246 for ; Thu, 25 May 2017 21:11:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17A7C283C8 for ; Thu, 25 May 2017 21:11:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CBF8283CD; Thu, 25 May 2017 21:11:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6DE21283C8 for ; Thu, 25 May 2017 21:11:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dE02c-0004yd-Vg; Thu, 25 May 2017 21:11:30 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dE02b-0004yM-4r for tpmdd-devel@lists.sourceforge.net; Thu, 25 May 2017 21:11:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From; bh=uwUOdwz3SGJkTkdOGnJe/ljupVT6+nxeM7vTmKMsAZw=; b=DRojIOhoN84KmB/y/Atg+Ba3qVOnCSAaAFo2KZMluDfNZc3VvkJbSsM/M/nChtoDLl7eLB2LUED0Asq66iDTfNNqFir/AFb5+RaVVTw7dKbbEXe1iMPOB4vquW44CC45VEnXy/4ypXSHbpLFH4BAvqeRGLi5PqMX+F2AJUuk/wM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Message-Id:Date:Subject:Cc:To:From; bh=uwUOdwz3SGJkTkdOGnJe/ljupVT6+nxeM7vTmKMsAZw=; b=Vv+hVa/y7QYWDOZ35OvGDXdQfzeGabzyQEl2YSTfHiyVDKQQBgluiVgEMLfP9/chgazkaIsE/A41FyaJlPCD7/p0xNQyjA+qE+SXhZwxmiNUpIac1uH0ZH2s7KnC3jZm8nbAshveoM8Q00oGAno92vopUZlTU8aYgRA1UPFT2/M=; X-ACL-Warn: Received: from mga02.intel.com ([134.134.136.20]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dE02V-0005AH-W4 for tpmdd-devel@lists.sourceforge.net; Thu, 25 May 2017 21:11:29 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 May 2017 14:11:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,393,1491289200"; d="scan'208";a="91861460" Received: from smattarx-mobl3.amr.corp.intel.com (HELO localhost) ([10.254.188.244]) by orsmga002.jf.intel.com with ESMTP; 25 May 2017 14:11:13 -0700 From: Jarkko Sakkinen To: tpmdd-devel@lists.sourceforge.net Date: Thu, 25 May 2017 14:11:04 -0700 Message-Id: <20170525211105.843-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.11.0 X-Headers-End: 1dE02V-0005AH-W4 Subject: [tpmdd-devel] [PATCH RFC] tpm: migrate pubek_show to struct tpm_buf X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: open list , linux-security-module@vger.kernel.org MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP Migrated pubek_show to struct tpm_buf. Signed-off-by: Jarkko Sakkinen --- RFC because I cannot test this ATM. drivers/char/tpm/tpm-sysfs.c | 49 ++++++++++++++++++++------------------------ drivers/char/tpm/tpm.h | 13 ------------ 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index 4bd0997cfa2d..bb5b2053137d 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -20,43 +20,37 @@ #include #include "tpm.h" -#define READ_PUBEK_RESULT_SIZE 314 #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) { + struct tpm_buf tpm_buf; u8 *data; - struct tpm_cmd_t tpm_cmd; - ssize_t err; - int i, rc; + ssize_t rc; + int i; char *str = buf; - struct tpm_chip *chip = to_tpm_chip(dev); + char anti_replay[20]; - tpm_cmd.header.in = tpm_readpubek_header; - err = tpm_transmit_cmd(chip, NULL, &tpm_cmd, READ_PUBEK_RESULT_SIZE, + rc = tpm_buf_init(&tpm_buf, TPM_TAG_RQU_COMMAND, TPM_ORD_READPUBEK); + if (rc) + return rc; + + /* The checksum is ignored so it doesn't matter what the contents are. + */ + 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 (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; + if (rc) { + tpm_buf_destroy(&tpm_buf); + return 0; + } + + data = &tpm_buf.data[10]; str += sprintf(str, "Algorithm: %02X %02X %02X %02X\n" @@ -80,8 +74,9 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr, 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 af05c1403c6e..5b79b7e06937 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -339,17 +339,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; @@ -383,8 +372,6 @@ struct tpm_startup_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;