[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190508144422.13171-38-kirill.shutemov@linux.intel.com>
Date: Wed, 8 May 2019 17:43:57 +0300
From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
To: Andrew Morton <akpm@...ux-foundation.org>, x86@...nel.org,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>, Borislav Petkov <bp@...en8.de>,
Peter Zijlstra <peterz@...radead.org>,
Andy Lutomirski <luto@...capital.net>,
David Howells <dhowells@...hat.com>
Cc: Kees Cook <keescook@...omium.org>,
Dave Hansen <dave.hansen@...el.com>,
Kai Huang <kai.huang@...ux.intel.com>,
Jacob Pan <jacob.jun.pan@...ux.intel.com>,
Alison Schofield <alison.schofield@...el.com>,
linux-mm@...ck.org, kvm@...r.kernel.org, keyrings@...r.kernel.org,
linux-kernel@...r.kernel.org,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>
Subject: [PATCH, RFC 37/62] keys/mktme: Do not allow key creation in unsafe topologies
From: Alison Schofield <alison.schofield@...el.com>
MKTME feature depends upon at least one online CPU capable of
programming each memory controller in the platform.
An unsafe topology for MKTME is a memory only package or a package
with no online CPUs. Key creation with unsafe topologies will fail
with EINVAL and a warning will be logged one time.
For example:
[ ] MKTME: no online CPU in proximity domain
[ ] MKTME: topology does not support key creation
These are recoverable errors. CPUs may be brought online that are
capable of programming a previously unprogrammable memory controller,
or an unprogrammable memory controller may be removed from the
platform.
Signed-off-by: Alison Schofield <alison.schofield@...el.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@...ux.intel.com>
---
security/keys/mktme_keys.c | 39 ++++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)
diff --git a/security/keys/mktme_keys.c b/security/keys/mktme_keys.c
index f5fc6cccc81b..734e1d28eb24 100644
--- a/security/keys/mktme_keys.c
+++ b/security/keys/mktme_keys.c
@@ -26,6 +26,7 @@ cpumask_var_t mktme_leadcpus; /* One lead CPU per pconfig target */
static bool mktme_storekeys; /* True if key payloads may be stored */
unsigned long *mktme_bitmap_user_type; /* Shows presence of user type keys */
struct mktme_payload *mktme_key_store; /* Payload storage if allowed */
+bool mktme_allow_keys; /* True when topology supports keys */
/* 1:1 Mapping between Userspace Keys (struct key) and Hardware KeyIDs */
struct mktme_mapping {
@@ -278,33 +279,55 @@ static void mktme_destroy_key(struct key *key)
percpu_ref_kill(&encrypt_count[keyid]);
}
+static void mktme_update_pconfig_targets(void);
/* Key Service Method to create a new key. Payload is preparsed. */
int mktme_instantiate_key(struct key *key, struct key_preparsed_payload *prep)
{
struct mktme_payload *payload = prep->payload.data[0];
unsigned long flags;
+ int ret = -ENOKEY;
int keyid;
spin_lock_irqsave(&mktme_lock, flags);
+
+ /* Topology supports key creation */
+ if (mktme_allow_keys)
+ goto get_key;
+
+ /* Topology unknown, check it. */
+ if (!mktme_hmat_evaluate()) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
+ /* Keys are now allowed. Update the programming targets. */
+ mktme_update_pconfig_targets();
+ mktme_allow_keys = true;
+
+get_key:
keyid = mktme_reserve_keyid(key);
spin_unlock_irqrestore(&mktme_lock, flags);
if (!keyid)
- return -ENOKEY;
+ goto out;
if (percpu_ref_init(&encrypt_count[keyid], mktme_percpu_ref_release,
0, GFP_KERNEL))
- goto err_out;
+ goto out_free_key;
- if (!mktme_program_keyid(keyid, payload)) {
- mktme_store_payload(keyid, payload);
- return MKTME_PROG_SUCCESS;
- }
+ ret = mktme_program_keyid(keyid, payload);
+ if (ret == MKTME_PROG_SUCCESS)
+ goto out;
+
+ /* Key programming failed */
percpu_ref_exit(&encrypt_count[keyid]);
-err_out:
+
+out_free_key:
spin_lock_irqsave(&mktme_lock, flags);
mktme_release_keyid(keyid);
+out_unlock:
spin_unlock_irqrestore(&mktme_lock, flags);
- return -ENOKEY;
+out:
+ return ret;
}
/* Make sure arguments are correct for the TYPE of key requested */
--
2.20.1
Powered by blists - more mailing lists