Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4204354img; Tue, 26 Mar 2019 05:13:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmr8TkR3W/S1z3gpZXafbwqq+KZR9wUFKcI8g3U6luE2ykf2LWyWTJy+2sPHKX2Knjvju8 X-Received: by 2002:a17:902:bb98:: with SMTP id m24mr8985516pls.17.1553602380833; Tue, 26 Mar 2019 05:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553602380; cv=none; d=google.com; s=arc-20160816; b=aPFJ4V4pqMS2ubcGP48eA2+xMCNMfcyrWCaDb1s6v47Z8MAcJDYinTyu0fJ4uMzQKa wvNQczl1UR7DGyPCl11B58kVZGMLMTKCjABQFvXZx+mLzhQulVzeJHlfD8LiV+OZoHqo qj6ClluXmrh5Lf1cdszpX8Psyq/bp4dHkXHp6njToYTaHWCBA6tYxGft9YtR8CTAFi54 SkZ09HpmdiEIpaTtaMuAqwHo2aE2lYP37iWPkhrgihafMwVbT5eY9/7TaxNufFBNLcfd puzVcnf4QyeSYGadlaQkQSQ75jLKpPJBsL/BDbNO/ts9UWJEwVKA4Php8LDDdzLwP0YK J/7g== 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 :message-id:date:subject:cc:to:from; bh=czIdkQNMolpb3wM9tLI5bdbnRi2bbiKIh4S4YnVnklE=; b=Sc6sigB/vOtZI5CWbtVUC43A1rbFol42p0j/DGfXqm+FqXj3hN1F60Wbqq81FQT2lp 9IlfZeBsWIG2AsgfF761qLyqfTNeaFcpnW42Y/qEvZpKlEalwQCONPTH5AnGcs9Tsofp zuKfyAroDS98GRIncx2YMqieszL7akkjiv9bFy3RvdXArgtiCAWhCFE7twjLIRW4Jo1b sGobAnJioEFvLpo2957MyyJ2l3wESfiT+DkqUwmufr90cEIqQzNrfa5wsKlhPTPJXRLz aV91kY1AxV4Ng3ILP9M2WTW2b4OpoRrS/EFXKzxz7TEi/WeosG0p1HPduvEN7hIldnB9 Rfgg== 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 b189si15634128pfa.65.2019.03.26.05.12.45; Tue, 26 Mar 2019 05:13:00 -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 S1731267AbfCZMMD (ORCPT + 99 others); Tue, 26 Mar 2019 08:12:03 -0400 Received: from mga01.intel.com ([192.55.52.88]:14005 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbfCZMMD (ORCPT ); Tue, 26 Mar 2019 08:12:03 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Mar 2019 05:12:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,271,1549958400"; d="scan'208";a="128764842" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.182]) by orsmga008.jf.intel.com with ESMTP; 26 Mar 2019 05:11:59 -0700 From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: linux-security-module@vger.kernel.org, Jarkko Sakkinen , James Morris , James Bottomley , Mimi Zohar , David Howells , "Serge E. Hallyn" , keyrings@vger.kernel.org (open list:KEYS-TRUSTED), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3] KEYS: trusted: allow trusted.ko to initialize w/o a TPM Date: Tue, 26 Mar 2019 14:11:58 +0200 Message-Id: <20190326121158.13499-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.19.1 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 Allow trusted.ko to initialize w/o a TPM. This commit adds checks to the key type callbacks and exported functions to fail when a TPM is not available. Cc: James Morris Reported-by: Dan Williams Tested-by: Dan Williams Fixes: 240730437deb ("KEYS: trusted: explicitly use tpm_chip structure...") Signed-off-by: Jarkko Sakkinen --- v3: - remove unnecessary check for chip in init_trusted() v2: - Remove checks from the key type callbacks because the key type will not be registered. - Cc to James Morris because hopefully we can land this 5.1.0. security/keys/trusted.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/security/keys/trusted.c b/security/keys/trusted.c index ecec672d3a77..efdbf17f3915 100644 --- a/security/keys/trusted.c +++ b/security/keys/trusted.c @@ -135,6 +135,9 @@ int TSS_authhmac(unsigned char *digest, const unsigned char *key, int ret; va_list argp; + if (!chip) + return -ENODEV; + sdesc = init_sdesc(hashalg); if (IS_ERR(sdesc)) { pr_info("trusted_key: can't alloc %s\n", hash_alg); @@ -196,6 +199,9 @@ int TSS_checkhmac1(unsigned char *buffer, va_list argp; int ret; + if (!chip) + return -ENODEV; + bufsize = LOAD32(buffer, TPM_SIZE_OFFSET); tag = LOAD16(buffer, 0); ordinal = command; @@ -363,6 +369,9 @@ int trusted_tpm_send(unsigned char *cmd, size_t buflen) { int rc; + if (!chip) + return -ENODEV; + dump_tpm_buf(cmd); rc = tpm_send(chip, cmd, buflen); dump_tpm_buf(cmd); @@ -429,6 +438,9 @@ int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce) { int ret; + if (!chip) + return -ENODEV; + INIT_BUF(tb); store16(tb, TPM_TAG_RQU_COMMAND); store32(tb, TPM_OIAP_SIZE); @@ -1245,9 +1257,13 @@ static int __init init_trusted(void) { int ret; + /* encrypted_keys.ko depends on successful load of this module even if + * TPM is not used. + */ chip = tpm_default_chip(); if (!chip) - return -ENOENT; + return 0; + ret = init_digests(); if (ret < 0) goto err_put; @@ -1269,10 +1285,12 @@ static int __init init_trusted(void) static void __exit cleanup_trusted(void) { - put_device(&chip->dev); - kfree(digests); - trusted_shash_release(); - unregister_key_type(&key_type_trusted); + if (chip) { + put_device(&chip->dev); + kfree(digests); + trusted_shash_release(); + unregister_key_type(&key_type_trusted); + } } late_initcall(init_trusted); -- 2.19.1