Received: by 10.223.164.202 with SMTP id h10csp192395wrb; Mon, 13 Nov 2017 05:03:45 -0800 (PST) X-Google-Smtp-Source: AGs4zMZukKjZH768qyPQa7i1Ds75cVCr20LF6uez8B+4B8i9SmrFxn3Br9Dg3fdPwTDXWoLT1fyO X-Received: by 10.98.28.5 with SMTP id c5mr3769060pfc.154.1510578225308; Mon, 13 Nov 2017 05:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510578225; cv=none; d=google.com; s=arc-20160816; b=uNFGcXN1mo/xXs6MCreVyBEQcwJ0aexfNbBRi8wsisKyObuM6IVzgBKV6aGeOxLi6W tk4U7EGTD1lA1Hf7HwshJk3Bx9jqqxiF3qHZxawdnrZfQ5NSQGT84k80K+KL8lBfFOK8 5sZGsH9rn9umxGH/Cb6JIkB1Tv5CqRg97IwigEBHg8hMot7RHcM6GSh9+1ErT0B9ss6d j18h1/hNW4Gu/9EaGASYXQng31KMfMqKo9sGa8Zf2nFy5LNedOlBNk1MrdO/FIr++nX0 4dMtRCbkcUS9tcGM4BcyU2jv23NJQz6Whd960KUHACbQCZsGxf//YL2eiRtnKLHc6/Pi Yfkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XzWcpHqUXbPlza8RngCwGOT2+FOw4l/PzTqDoSDQi00=; b=SslQeHRjs7CIbLzlGK8M4DZMX0jGtXGaOsw44eUbhnbnX20IwH4P3ym5exnUfwOM+d 0N+qKWOR0oLlMJQPVlJZZctVFUHKG6iQ8kxUdrpg3KGdLVGB3CymyA9V5akXCLwUhdaZ n3hWIf0FdvwKb0r+/FpSkI6SH/SrTmhMc8rPOuqtIO+7qhPrMg3O1pxsw25tkz6FlVcP +ykw4lqAf654xCsy/vnEjg69itl8QTbAh0NL7ul/WfH8aYeFBXdY2BAnSTiXOnnMd3xA jGls/s3YKjiJolCpIpTXcJB4V4awDl/mYnJkSD7FbnQDSzABODpxkYNNGQX9KwErOTvc yJlQ== 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 u4si15359675pfd.201.2017.11.13.05.03.32; Mon, 13 Nov 2017 05:03:45 -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 S1754659AbdKMNBc (ORCPT + 95 others); Mon, 13 Nov 2017 08:01:32 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50222 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753633AbdKMNB3 (ORCPT ); Mon, 13 Nov 2017 08:01:29 -0500 Received: from localhost (LFbn-1-12253-150.w90-92.abo.wanadoo.fr [90.92.67.150]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9BBB0AB5; Mon, 13 Nov 2017 13:01:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mimi Zohar , David Safford , Eric Biggers , David Howells , James Morris Subject: [PATCH 4.9 51/87] KEYS: trusted: sanitize all key material Date: Mon, 13 Nov 2017 13:56:08 +0100 Message-Id: <20171113125620.118365727@linuxfoundation.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171113125615.304035578@linuxfoundation.org> References: <20171113125615.304035578@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit ee618b4619b72527aaed765f0f0b74072b281159 upstream. As the previous patch did for encrypted-keys, zero sensitive any potentially sensitive data related to the "trusted" key type before it is freed. Notably, we were not zeroing the tpm_buf structures in which the actual key is stored for TPM seal and unseal, nor were we zeroing the trusted_key_payload in certain error paths. Cc: Mimi Zohar Cc: David Safford Signed-off-by: Eric Biggers Signed-off-by: David Howells Signed-off-by: James Morris Signed-off-by: Greg Kroah-Hartman --- security/keys/trusted.c | 50 +++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) --- a/security/keys/trusted.c +++ b/security/keys/trusted.c @@ -70,7 +70,7 @@ static int TSS_sha1(const unsigned char } ret = crypto_shash_digest(&sdesc->shash, data, datalen, digest); - kfree(sdesc); + kzfree(sdesc); return ret; } @@ -114,7 +114,7 @@ static int TSS_rawhmac(unsigned char *di if (!ret) ret = crypto_shash_final(&sdesc->shash, digest); out: - kfree(sdesc); + kzfree(sdesc); return ret; } @@ -165,7 +165,7 @@ static int TSS_authhmac(unsigned char *d paramdigest, TPM_NONCE_SIZE, h1, TPM_NONCE_SIZE, h2, 1, &c, 0, 0); out: - kfree(sdesc); + kzfree(sdesc); return ret; } @@ -246,7 +246,7 @@ static int TSS_checkhmac1(unsigned char if (memcmp(testhmac, authdata, SHA1_DIGEST_SIZE)) ret = -EINVAL; out: - kfree(sdesc); + kzfree(sdesc); return ret; } @@ -347,7 +347,7 @@ static int TSS_checkhmac2(unsigned char if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE)) ret = -EINVAL; out: - kfree(sdesc); + kzfree(sdesc); return ret; } @@ -564,7 +564,7 @@ static int tpm_seal(struct tpm_buf *tb, *bloblen = storedsize; } out: - kfree(td); + kzfree(td); return ret; } @@ -678,7 +678,7 @@ static int key_seal(struct trusted_key_p if (ret < 0) pr_info("trusted_key: srkseal failed (%d)\n", ret); - kfree(tb); + kzfree(tb); return ret; } @@ -703,7 +703,7 @@ static int key_unseal(struct trusted_key /* pull migratable flag out of sealed key */ p->migratable = p->key[--p->key_len]; - kfree(tb); + kzfree(tb); return ret; } @@ -1037,12 +1037,12 @@ static int trusted_instantiate(struct ke if (!ret && options->pcrlock) ret = pcrlock(options->pcrlock); out: - kfree(datablob); - kfree(options); + kzfree(datablob); + kzfree(options); if (!ret) rcu_assign_keypointer(key, payload); else - kfree(payload); + kzfree(payload); return ret; } @@ -1051,8 +1051,7 @@ static void trusted_rcu_free(struct rcu_ struct trusted_key_payload *p; p = container_of(rcu, struct trusted_key_payload, rcu); - memset(p->key, 0, p->key_len); - kfree(p); + kzfree(p); } /* @@ -1094,13 +1093,13 @@ static int trusted_update(struct key *ke ret = datablob_parse(datablob, new_p, new_o); if (ret != Opt_update) { ret = -EINVAL; - kfree(new_p); + kzfree(new_p); goto out; } if (!new_o->keyhandle) { ret = -EINVAL; - kfree(new_p); + kzfree(new_p); goto out; } @@ -1114,22 +1113,22 @@ static int trusted_update(struct key *ke ret = key_seal(new_p, new_o); if (ret < 0) { pr_info("trusted_key: key_seal failed (%d)\n", ret); - kfree(new_p); + kzfree(new_p); goto out; } if (new_o->pcrlock) { ret = pcrlock(new_o->pcrlock); if (ret < 0) { pr_info("trusted_key: pcrlock failed (%d)\n", ret); - kfree(new_p); + kzfree(new_p); goto out; } } rcu_assign_keypointer(key, new_p); call_rcu(&p->rcu, trusted_rcu_free); out: - kfree(datablob); - kfree(new_o); + kzfree(datablob); + kzfree(new_o); return ret; } @@ -1158,24 +1157,19 @@ static long trusted_read(const struct ke for (i = 0; i < p->blob_len; i++) bufp = hex_byte_pack(bufp, p->blob[i]); if ((copy_to_user(buffer, ascii_buf, 2 * p->blob_len)) != 0) { - kfree(ascii_buf); + kzfree(ascii_buf); return -EFAULT; } - kfree(ascii_buf); + kzfree(ascii_buf); return 2 * p->blob_len; } /* - * trusted_destroy - before freeing the key, clear the decrypted data + * trusted_destroy - clear and free the key's payload */ static void trusted_destroy(struct key *key) { - struct trusted_key_payload *p = key->payload.data[0]; - - if (!p) - return; - memset(p->key, 0, p->key_len); - kfree(key->payload.data[0]); + kzfree(key->payload.data[0]); } struct key_type key_type_trusted = { From 1583955878134123085@xxx Mon Nov 13 13:00:39 +0000 2017 X-GM-THRID: 1583955878134123085 X-Gmail-Labels: Inbox,Category Promotions,HistoricalUnread