nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] libnvdimm: fix updating of kernel key during nvdimm key update
@ 2018-10-12 18:23 Dave Jiang
  2018-10-12 18:23 ` [PATCH 2/5] libnvdimm: fix incorrect output when nvdimm disable failed Dave Jiang
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Dave Jiang @ 2018-10-12 18:23 UTC (permalink / raw)
  To: dan.j.williams; +Cc: linux-nvdimm

There are several issues WRT kernel key update when we are doing nvdimm
security key update.

1. The kernel key created needs to have proper permission for update
2. We need to check key_update() return value and make sure it didn't fail
3. We need to not hold the key->sem when calling key_update() since it will
   call down_write() when doing modification to the key.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/nvdimm/security.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/nvdimm/security.c b/drivers/nvdimm/security.c
index 776c440a02ef..ef83bdf47c31 100644
--- a/drivers/nvdimm/security.c
+++ b/drivers/nvdimm/security.c
@@ -27,7 +27,7 @@ static struct key *make_kernel_key(struct key *key)
 
 	new_key = key_alloc(&key_type_logon, key->description,
 			GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
-			KEY_POS_SEARCH, KEY_ALLOC_NOT_IN_QUOTA, NULL);
+			KEY_POS_ALL, KEY_ALLOC_NOT_IN_QUOTA, NULL);
 	if (IS_ERR(new_key))
 		return NULL;
 
@@ -419,11 +419,19 @@ int nvdimm_security_change_key(struct nvdimm *nvdimm,
 		dev_warn(dev, "key update failed: %d\n", rc);
 
 	if (old_key) {
+		up_read(&old_key->sem);
 		/* copy new payload to old payload */
-		if (rc == 0)
-			key_update(make_key_ref(old_key, 1), new_data,
+		if (rc == 0) {
+			rc = key_update(make_key_ref(old_key, 1), new_data,
 					old_key->datalen);
-		up_read(&old_key->sem);
+			if (rc < 0) {
+				dev_warn(dev,
+					"kernel key update failed: %d\n", rc);
+				key_invalidate(old_key);
+				key_put(old_key);
+				nvdimm->key = NULL;
+			}
+		}
 	}
 	up_read(&key->sem);
 

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-10-12 19:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-12 18:23 [PATCH 1/5] libnvdimm: fix updating of kernel key during nvdimm key update Dave Jiang
2018-10-12 18:23 ` [PATCH 2/5] libnvdimm: fix incorrect output when nvdimm disable failed Dave Jiang
2018-10-12 19:22   ` Dan Williams
2018-10-12 18:24 ` [PATCH 3/5] libnvdimm: remove driver attached check for secure erase Dave Jiang
2018-10-12 19:23   ` Dan Williams
2018-10-12 18:24 ` [PATCH 4/5] libnvdimm: remove code to pull user key when there's no kernel key Dave Jiang
2018-10-12 19:26   ` Dan Williams
2018-10-12 18:24 ` [PATCH 5/5] libnvdimm: address state where dimm is unlocked in preOS Dave Jiang
2018-10-12 19:28   ` Dan Williams
2018-10-12 19:19 ` [PATCH 1/5] libnvdimm: fix updating of kernel key during nvdimm key update Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).