From patchwork Fri Aug 2 15:07:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 11073735 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 4D1051399 for ; Fri, 2 Aug 2019 15:11:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CDC328845 for ; Fri, 2 Aug 2019 15:11:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E2952886A; Fri, 2 Aug 2019 15:11:24 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E68C28845 for ; Fri, 2 Aug 2019 15:11:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729002AbfHBPLW (ORCPT ); Fri, 2 Aug 2019 11:11:22 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:33109 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726044AbfHBPLW (ORCPT ); Fri, 2 Aug 2019 11:11:22 -0400 Received: from LHREML711-CAH.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id D994141B3E5806BD2DD0; Fri, 2 Aug 2019 16:11:20 +0100 (IST) Received: from roberto-HP-EliteDesk-800-G2-DM-65W.huawei.com (10.204.65.154) by smtpsuk.huawei.com (10.201.108.34) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 2 Aug 2019 16:11:13 +0100 From: Roberto Sassu To: , , , , CC: , , , , , , , Roberto Sassu Subject: [PATCH v2] KEYS: trusted: allow module init if TPM is inactive or deactivated Date: Fri, 2 Aug 2019 17:07:33 +0200 Message-ID: <20190802150733.1972-1-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.204.65.154] X-CFilter-Loop: Reflected Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Commit c78719203fc6 ("KEYS: trusted: allow trusted.ko to initialize w/o a TPM") allows the trusted module to be loaded even a TPM is not found to avoid module dependency problems. However, trusted module initialization can still fail if the TPM is inactive or deactivated. This patch ignores tpm_get_random() errors in init_digests() and returns -EFAULT in pcrlock() if the TPM didn't return random data. Signed-off-by: Roberto Sassu --- security/keys/trusted.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/security/keys/trusted.c b/security/keys/trusted.c index 9a94672e7adc..34f04ffcf2e5 100644 --- a/security/keys/trusted.c +++ b/security/keys/trusted.c @@ -389,6 +389,10 @@ static int pcrlock(const int pcrnum) if (!capable(CAP_SYS_ADMIN)) return -EPERM; + /* This happens if the TPM didn't return random data */ + if (!digests) + return -EFAULT; + return tpm_pcr_extend(chip, pcrnum, digests) ? -EINVAL : 0; } @@ -1233,10 +1237,8 @@ static int __init init_digests(void) int i; ret = tpm_get_random(chip, digest, TPM_MAX_DIGEST_SIZE); - if (ret < 0) - return ret; - if (ret < TPM_MAX_DIGEST_SIZE) - return -EFAULT; + if (ret < 0 || ret < TPM_MAX_DIGEST_SIZE) + return 0; digests = kcalloc(chip->nr_allocated_banks, sizeof(*digests), GFP_KERNEL);