Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp670909ybh; Sat, 3 Aug 2019 07:23:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8/wHRvuQNTUvWT/yGyh8dT+le0+hhKqlPh91rlew4CCbMW8cl9MXOjrizdiSC8YCkDZ1L X-Received: by 2002:a63:2157:: with SMTP id s23mr12147203pgm.167.1564842216842; Sat, 03 Aug 2019 07:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564842216; cv=none; d=google.com; s=arc-20160816; b=BUQ0Gfw84TfgHB/6lzJkjal8unwJKytLRMmT6iBRzDCf7SELdGtRGid5YbmgLMYwQv uNKLxuoJr0hkBBG1SbiTFR+ft1Z6x9Y2SbT1p61MtCfV9duCVXo9O8FK+riMxWZmU4MZ gPEVRm0cnYHNOMdkMPsajC4eHOv9axBQofVgFGRzTfOvDh6rkKO1yaeRBKZgPqJoWiIk vj9zjiwaURv1PvMpG1sN3im3w+2ZM09QZQguCIKQjhzalIVBGXr2JHFadiWGToLesTUW JxT0GRzlDsV5D+0h/QHHsrerZ3naDozjxf+hZGknv2BkY5swvlvmjhwrLW+aCjzNyxVf ql3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=QK1xuQuDBxwVtHaabPEvuD4SxHA5sS15IPoPbsQQ3mI=; b=kC9C+X0mkN1gP2lhRrHI5leGHboJr/PWj3a+KwCTQj98Jfm3jKpuyw68shOKeLyogn VQn6IPBGrc0b+lDNP0snbH8XljQcd3x83xTope69SSpehXjxiODoNlBPRR6iKXZWcasP 1HpGZq5K2DFjAEQocV8sU+1fRgolM1ZLJLpy/UcET7C1PQd5vXG2jCaxuCb2BC554TYJ LTpG1bMjk88WqbuIfsdVXPXiObJLUdJ5ADDoL2dQ8EO64iec6jOLUw+wjRSI+y4YoKKW s4BO5xSekBAGxkTgzeh64D+Sza0QaGtz0Tcv969+RrYYnZnm6TOE4YQotlak4JKoTUgi xkjA== 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 l70si40192081pge.446.2019.08.03.07.23.22; Sat, 03 Aug 2019 07:23:36 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729255AbfHBPLX (ORCPT + 99 others); Fri, 2 Aug 2019 11:11:23 -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 Content-Type: text/plain X-Originating-IP: [10.204.65.154] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.1