From patchwork Mon Mar 18 23:45:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10858649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 634371575 for ; Mon, 18 Mar 2019 23:58:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3629929412 for ; Mon, 18 Mar 2019 23:58:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28FD229452; Mon, 18 Mar 2019 23:58:01 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE64B29412 for ; Mon, 18 Mar 2019 23:58:00 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 78140211DF228; Mon, 18 Mar 2019 16:57:55 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6F97B21B02822 for ; Mon, 18 Mar 2019 16:57:53 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Mar 2019 16:57:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,495,1544515200"; d="scan'208";a="152911954" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga002.fm.intel.com with ESMTP; 18 Mar 2019 16:57:52 -0700 Subject: [PATCH] security/keys/trusted: Allow operation without hardware TPM From: Dan Williams To: jarkko.sakkinen@linux.intel.com Date: Mon, 18 Mar 2019 16:45:13 -0700 Message-ID: <155295271345.1945351.6465460744078693578.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org, James Bottomley , Roberto Sassu , linux-kernel@vger.kernel.org, Mimi Zohar , David Howells , keyrings@vger.kernel.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Rather than fail initialization of the trusted.ko module, arrange for the module to load, but rely on trusted_instantiate() to fail trusted-key operations. Fixes: 240730437deb ("KEYS: trusted: explicitly use tpm_chip structure...") Cc: Roberto Sassu Cc: Jarkko Sakkinen Cc: James Bottomley Cc: Jarkko Sakkinen Cc: Mimi Zohar Cc: David Howells Signed-off-by: Dan Williams --- security/keys/trusted.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/security/keys/trusted.c b/security/keys/trusted.c index bcc9c6ead7fd..d959597a688e 100644 --- a/security/keys/trusted.c +++ b/security/keys/trusted.c @@ -45,6 +45,13 @@ struct sdesc { static struct crypto_shash *hashalg; static struct crypto_shash *hmacalg; +static struct device *chip_dev(struct tpm_chip *chip) +{ + if (chip) + return &chip->dev; + return NULL; +} + static struct sdesc *init_sdesc(struct crypto_shash *alg) { struct sdesc *sdesc; @@ -1224,6 +1231,14 @@ static int __init init_digests(void) int ret; int i; + /* + * Hardware tpm operations are disabled, but allow the software + * module to initialize, and depend on trusted_instantiate() to + * fail any attempts to access the missing hardware. + */ + if (!chip) + return 0; + ret = tpm_get_random(chip, digest, TPM_MAX_DIGEST_SIZE); if (ret < 0) return ret; @@ -1246,8 +1261,6 @@ static int __init init_trusted(void) int ret; chip = tpm_default_chip(); - if (!chip) - return -ENOENT; ret = init_digests(); if (ret < 0) goto err_put; @@ -1263,13 +1276,13 @@ static int __init init_trusted(void) err_free: kfree(digests); err_put: - put_device(&chip->dev); + put_device(chip_dev(chip)); return ret; } static void __exit cleanup_trusted(void) { - put_device(&chip->dev); + put_device(chip_dev(chip)); kfree(digests); trusted_shash_release(); unregister_key_type(&key_type_trusted);