[PATCH 3/6] libnvdimm/security: Drop direct dependency on key_type_encrypted
From: Dan Williams
Date: Tue Mar 19 2019 - 02:19:12 EST
Lookup the key type by name and protect libnvdimm from encrypted_keys.ko
module load failures.
Cc: Vishal Verma <vishal.l.verma@xxxxxxxxx>
Cc: Dave Jiang <dave.jiang@xxxxxxxxx>
Cc: Keith Busch <keith.busch@xxxxxxxxx>
Cc: Ira Weiny <ira.weiny@xxxxxxxxx>
Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx>
---
drivers/nvdimm/security.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/nvdimm/security.c b/drivers/nvdimm/security.c
index f8bb746a549f..7f9e412f743a 100644
--- a/drivers/nvdimm/security.c
+++ b/drivers/nvdimm/security.c
@@ -48,12 +48,17 @@ static void nvdimm_put_key(struct key *key)
static struct key *nvdimm_request_key(struct nvdimm *nvdimm)
{
struct key *key = NULL;
+ struct key_type *type;
static const char NVDIMM_PREFIX[] = "nvdimm:";
char desc[NVDIMM_KEY_DESC_LEN + sizeof(NVDIMM_PREFIX)];
struct device *dev = &nvdimm->dev;
sprintf(desc, "%s%s", NVDIMM_PREFIX, nvdimm->dimm_id);
- key = request_key(&key_type_encrypted, desc, "");
+ type = key_type_lookup("encrypted");
+ if (IS_ERR(type))
+ return (struct key *) type;
+
+ key = request_key(type, desc, "");
if (IS_ERR(key)) {
if (PTR_ERR(key) == -ENOKEY)
dev_dbg(dev, "request_key() found no key\n");
@@ -88,7 +93,7 @@ static struct key *nvdimm_lookup_user_key(struct nvdimm *nvdimm,
return NULL;
key = key_ref_to_ptr(keyref);
- if (key->type != &key_type_encrypted) {
+ if (strcmp(key->type->name, "encrypted") != 0) {
key_put(key);
return NULL;
}
@@ -452,3 +457,5 @@ void nvdimm_security_overwrite_query(struct work_struct *work)
__nvdimm_security_overwrite_query(nvdimm);
nvdimm_bus_unlock(&nvdimm->dev);
}
+
+MODULE_SOFTDEP("pre: encrypted_keys");