Skip to contentSkip to conversation

block: keyslot-manager: fix error return code of blk_ksm_evict_key()

PATCH In review Jia-Ju Bai 2 participants 3 messages Mar 9, 2021 Block layer

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 block: keyslot-manager: fix error return code of blk_ksm_evict_key()

When blk_ksm_find_keyslot() returns NULL to slot, no error return code of blk_ksm_evict_key() is assigned.
To fix this bug, err is assigned with -ENOENT in this case.

Fixes 1b2628397058 ("block: Keyslot Manager for Inline Encryption")
---
 block/keyslot-manager.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/keyslot-manager.c +3 -1
index 2c4a55bea6ca..4dd5da0645bc 100644
@@ -375,8 +375,10 @@ int blk_ksm_evict_key(struct blk_keyslot_manager *ksm,
 
 	blk_ksm_hw_enter(ksm);
 	slot = blk_ksm_find_keyslot(ksm, key);
-	if (!slot)
+	if (!slot) {
+		err = -ENOENT;
 		goto out_unlock;
+	}
 
 	if (WARN_ON_ONCE(atomic_read(&slot->slot_refs) != 0)) {
 		err = -EBUSY;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 30 lines · Jia-Ju Bai

When blk_ksm_find_keyslot() returns NULL to slot, no error return code of blk_ksm_evict_key() is assigned.
To fix this bug, err is assigned with -ENOENT in this case.

Fixes 1b2628397058 ("block: Keyslot Manager for Inline Encryption")
---
 block/keyslot-manager.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/keyslot-manager.c +3 -1
index 2c4a55bea6ca..4dd5da0645bc 100644
@@ -375,8 +375,10 @@ int blk_ksm_evict_key(struct blk_keyslot_manager *ksm,
 
 	blk_ksm_hw_enter(ksm);
 	slot = blk_ksm_find_keyslot(ksm, key);
-	if (!slot)
+	if (!slot) {
+		err = -ENOENT;
 		goto out_unlock;
+	}
 
 	if (WARN_ON_ONCE(atomic_read(&slot->slot_refs) != 0)) {
 		err = -EBUSY;
Signature · 1 line
2.17.1

This function was deliberately designed to return 0 on success *and also* if there's no keyslot found with the specified key - i.e. it returns 0 if the key is no longer programmed into the keyslot manager, which is what the callers care about, so I don't think there's a bug here.

Also if we were to apply this patch, we'd also need to change the callers to handle this new -ENOENT case (and not treat it as an error/not propogate -ENOENT in e.g. dm_keyslot_evict_callback()).

Is there a reason we want to change the behaviour of this function?

author
#2 lore raw
Quoted 26 lines · Satya Tangirala
Quoted 25 lines · Jia-Ju Bai

When blk_ksm_find_keyslot() returns NULL to slot, no error return code of blk_ksm_evict_key() is assigned.
To fix this bug, err is assigned with -ENOENT in this case.

Fixes 1b2628397058 ("block: Keyslot Manager for Inline Encryption")
---
  block/keyslot-manager.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
block/keyslot-manager.c +3 -1
index 2c4a55bea6ca..4dd5da0645bc 100644
@@ -375,8 +375,10 @@ int blk_ksm_evict_key(struct blk_keyslot_manager *ksm,
 
  	blk_ksm_hw_enter(ksm);
  	slot = blk_ksm_find_keyslot(ksm, key);
-	if (!slot)
+	if (!slot) {
+		err = -ENOENT;
  		goto out_unlock;
+	}
 
Quoted 9 lines
Quoted 5 lines
block/keyslot-manager.c +0 -0
  	if (WARN_ON_ONCE(atomic_read(&slot->slot_refs) != 0)) {
  		err = -EBUSY;
Signature · 1 line
2.17.1

This function was deliberately designed to return 0 on success *and also* if there's no keyslot found with the specified key - i.e. it returns 0 if the key is no longer programmed into the keyslot manager, which is what the callers care about, so I don't think there's a bug here.

Thanks for the reply and explanation!
It seems like a false positive here, and I am sorry for this false report.

Best wishes,
Jia-Ju Bai