Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp230045ima; Fri, 1 Feb 2019 02:24:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN52DFpFuxQv0UkBmoZvNAccXHxLw6wG/91RqvnHj6yaPeYcabkBWQikVRwZIXqOQ6QIb4gi X-Received: by 2002:a17:902:2b8a:: with SMTP id l10mr36695322plb.70.1549016644050; Fri, 01 Feb 2019 02:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549016644; cv=none; d=google.com; s=arc-20160816; b=0focdkCehMpYHwJ7wTI4zX38nhuBSmUMKU9J3wdLOw0KdLySEz3w4ltFy/FQ/okaKm 1uebAPGiuz2qs7fTqj4/8BKsyrJy1BHQSF3Q9/0NH/izZwYv+E8C8cbs1HgTWSoeo62n Z6hfNqA7NZtRJNkeBlw4ETQKOhhU4YLSQ9MOgsZlB4pqWKPp/MrcKH+UTKZMVixCbH4Q PvqWcisqDwU+4IZFpKzN+tp0PErfuhrwbnhXJPcjYUA7TelXEY78Z7rK59mnABUojGVk refz3CN6TKjiwR+QHZAT6KkIQgn39H/aA6chl49hwbaKROZBjelj8CHlFQ1ioBCaZujX Zt2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=f3MG8PUGawZI9xG51Xmk6CaLexnwen26I5N8SIsJDYw=; b=N/bHD/cEbbEdOpTTxK0AdHCBq8Yk4Ie6p32lLsiuqxqMwqjfxEPkTB/SwuTjQLgerJ HWw8SO6Px89XwEzRaG9APuiAYovyA3FsL1hYOeTbKK/NIOsTYwMFHIMAn0cUlD7Tskg0 /MJSCUr3AYmo1ttd1FJgrU8STqsTeBbZdDBLAx2Pv85GosKdag7z/D0M1j9d70ZbHimq fijpJirp0EnWLgw0BrBHHqJaonvV0QcI/7kH8u4QMy0HRKXOpnPiqVbLtXWVCQSK2fkj UyZRFexKlS9HzUAZ6chAUomoUrXwVtosNoLClguKGyGyWmm13PEf/6cIMW0WxsK4Lwgx ZP9g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si7112477pfa.99.2019.02.01.02.23.48; Fri, 01 Feb 2019 02:24:04 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729597AbfBAKRV (ORCPT + 99 others); Fri, 1 Feb 2019 05:17:21 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:32854 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726116AbfBAKRV (ORCPT ); Fri, 1 Feb 2019 05:17:21 -0500 Received: from lhreml709-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 2B6C2D340E138F36CE91; Fri, 1 Feb 2019 10:17:20 +0000 (GMT) Received: from roberto-HP-EliteDesk-800-G2-DM-65W.huawei.com (10.204.65.141) by smtpsuk.huawei.com (10.201.108.32) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 1 Feb 2019 10:17:13 +0000 From: Roberto Sassu To: , , , , CC: , , , , , Roberto Sassu Subject: [PATCH v9 5/6] KEYS: trusted: explicitly use tpm_chip structure from tpm_default_chip() Date: Fri, 1 Feb 2019 11:06:40 +0100 Message-ID: <20190201100641.26936-6-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190201100641.26936-1-roberto.sassu@huawei.com> References: <20190201100641.26936-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.204.65.141] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When crypto agility support will be added to the TPM driver, users of the driver have to retrieve the allocated banks from chip->allocated_banks and use this information to prepare the array of tpm_digest structures to be passed to tpm_pcr_extend(). This patch retrieves a tpm_chip pointer from tpm_default_chip() so that the pointer can be used to prepare the array of tpm_digest structures. Signed-off-by: Roberto Sassu --- security/keys/trusted.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/security/keys/trusted.c b/security/keys/trusted.c index 4d98f4f87236..5b852263eae1 100644 --- a/security/keys/trusted.c +++ b/security/keys/trusted.c @@ -34,6 +34,7 @@ static const char hmac_alg[] = "hmac(sha1)"; static const char hash_alg[] = "sha1"; +static struct tpm_chip *chip; struct sdesc { struct shash_desc shash; @@ -362,7 +363,7 @@ int trusted_tpm_send(unsigned char *cmd, size_t buflen) int rc; dump_tpm_buf(cmd); - rc = tpm_send(NULL, cmd, buflen); + rc = tpm_send(chip, cmd, buflen); dump_tpm_buf(cmd); if (rc > 0) /* Can't return positive return codes values to keyctl */ @@ -384,10 +385,10 @@ static int pcrlock(const int pcrnum) if (!capable(CAP_SYS_ADMIN)) return -EPERM; - ret = tpm_get_random(NULL, hash, SHA1_DIGEST_SIZE); + ret = tpm_get_random(chip, hash, SHA1_DIGEST_SIZE); if (ret != SHA1_DIGEST_SIZE) return ret; - return tpm_pcr_extend(NULL, pcrnum, hash) ? -EINVAL : 0; + return tpm_pcr_extend(chip, pcrnum, hash) ? -EINVAL : 0; } /* @@ -400,7 +401,7 @@ static int osap(struct tpm_buf *tb, struct osapsess *s, unsigned char ononce[TPM_NONCE_SIZE]; int ret; - ret = tpm_get_random(NULL, ononce, TPM_NONCE_SIZE); + ret = tpm_get_random(chip, ononce, TPM_NONCE_SIZE); if (ret != TPM_NONCE_SIZE) return ret; @@ -496,7 +497,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype, if (ret < 0) goto out; - ret = tpm_get_random(NULL, td->nonceodd, TPM_NONCE_SIZE); + ret = tpm_get_random(chip, td->nonceodd, TPM_NONCE_SIZE); if (ret != TPM_NONCE_SIZE) goto out; ordinal = htonl(TPM_ORD_SEAL); @@ -606,7 +607,7 @@ static int tpm_unseal(struct tpm_buf *tb, ordinal = htonl(TPM_ORD_UNSEAL); keyhndl = htonl(SRKHANDLE); - ret = tpm_get_random(NULL, nonceodd, TPM_NONCE_SIZE); + ret = tpm_get_random(chip, nonceodd, TPM_NONCE_SIZE); if (ret != TPM_NONCE_SIZE) { pr_info("trusted_key: tpm_get_random failed (%d)\n", ret); return ret; @@ -751,7 +752,7 @@ static int getoptions(char *c, struct trusted_key_payload *pay, int i; int tpm2; - tpm2 = tpm_is_tpm2(NULL); + tpm2 = tpm_is_tpm2(chip); if (tpm2 < 0) return tpm2; @@ -920,7 +921,7 @@ static struct trusted_key_options *trusted_options_alloc(void) struct trusted_key_options *options; int tpm2; - tpm2 = tpm_is_tpm2(NULL); + tpm2 = tpm_is_tpm2(chip); if (tpm2 < 0) return NULL; @@ -970,7 +971,7 @@ static int trusted_instantiate(struct key *key, size_t key_len; int tpm2; - tpm2 = tpm_is_tpm2(NULL); + tpm2 = tpm_is_tpm2(chip); if (tpm2 < 0) return tpm2; @@ -1011,7 +1012,7 @@ static int trusted_instantiate(struct key *key, switch (key_cmd) { case Opt_load: if (tpm2) - ret = tpm_unseal_trusted(NULL, payload, options); + ret = tpm_unseal_trusted(chip, payload, options); else ret = key_unseal(payload, options); dump_payload(payload); @@ -1021,13 +1022,13 @@ static int trusted_instantiate(struct key *key, break; case Opt_new: key_len = payload->key_len; - ret = tpm_get_random(NULL, payload->key, key_len); + ret = tpm_get_random(chip, payload->key, key_len); if (ret != key_len) { pr_info("trusted_key: key_create failed (%d)\n", ret); goto out; } if (tpm2) - ret = tpm_seal_trusted(NULL, payload, options); + ret = tpm_seal_trusted(chip, payload, options); else ret = key_seal(payload, options); if (ret < 0) @@ -1225,17 +1226,26 @@ static int __init init_trusted(void) { int ret; + chip = tpm_default_chip(); + if (!chip) + return -ENOENT; ret = trusted_shash_alloc(); if (ret < 0) - return ret; + goto err_put; ret = register_key_type(&key_type_trusted); if (ret < 0) - trusted_shash_release(); + goto err_release; + return 0; +err_release: + trusted_shash_release(); +err_put: + put_device(&chip->dev); return ret; } static void __exit cleanup_trusted(void) { + put_device(&chip->dev); trusted_shash_release(); unregister_key_type(&key_type_trusted); } -- 2.17.1