From patchwork Mon Oct 16 02:53:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Boshi X-Patchwork-Id: 10007555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF2BF60235 for ; Mon, 16 Oct 2017 02:54:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFEEC201F5 for ; Mon, 16 Oct 2017 02:54:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A17D7205AD; Mon, 16 Oct 2017 02:54:14 +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 EF3FC201F5 for ; Mon, 16 Oct 2017 02:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751714AbdJPCyN (ORCPT ); Sun, 15 Oct 2017 22:54:13 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8049 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751681AbdJPCyM (ORCPT ); Sun, 15 Oct 2017 22:54:12 -0400 Received: from 172.30.72.59 (EHLO DGGEMS413-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DJF01596; Mon, 16 Oct 2017 10:54:09 +0800 (CST) Received: from [127.0.0.1] (10.130.182.161) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.301.0; Mon, 16 Oct 2017 10:54:06 +0800 To: CC: , From: Boshi Wang Subject: [PATCH] keys, trusted: fix missing support for TPM 2.0 in trusted_update() Message-ID: <683216c3-d61a-1b24-c38c-b3f4348ce876@huawei.com> Date: Mon, 16 Oct 2017 10:53:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [10.130.182.161] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090205.59E41F51.00BD, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: c7b5a0e00d15b28c14acc1726df00025 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Call tpm_seal_trusted() in trusted_update() for TPM 2.0 chips. Signed-off-by: Boshi Wang Reviewed-by: Jarkko Sakkinen --- security/keys/trusted.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/security/keys/trusted.c b/security/keys/trusted.c index ddfaebf..563fe5f 100644 --- a/security/keys/trusted.c +++ b/security/keys/trusted.c @@ -1065,6 +1065,11 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) size_t datalen = prep->datalen; char *datablob; int ret = 0; + int tpm2; + + tpm2 = tpm_is_tpm2(TPM_ANY_NUM); + if (tpm2 < 0) + return tpm2; if (test_bit(KEY_FLAG_NEGATIVE, &key->flags)) return -ENOKEY; @@ -1110,7 +1115,10 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) dump_payload(p); dump_payload(new_p); - ret = key_seal(new_p, new_o); + if (tpm2) + ret = tpm_seal_trusted(TPM_ANY_NUM, new_p, new_o); + else + ret = key_seal(new_p, new_o); if (ret < 0) { pr_info("trusted_key: key_seal failed (%d)\n", ret); kzfree(new_p);