linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: keyslot-manager: fix error return code of blk_ksm_evict_key()
@ 2021-03-09  9:18 Jia-Ju Bai
  2021-03-09 11:45 ` Satya Tangirala
  0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2021-03-09  9:18 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-kernel, 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")
Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 block/keyslot-manager.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c
index 2c4a55bea6ca..4dd5da0645bc 100644
--- a/block/keyslot-manager.c
+++ b/block/keyslot-manager.c
@@ -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;
-- 
2.17.1


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

* Re: [PATCH] block: keyslot-manager: fix error return code of blk_ksm_evict_key()
  2021-03-09  9:18 [PATCH] block: keyslot-manager: fix error return code of blk_ksm_evict_key() Jia-Ju Bai
@ 2021-03-09 11:45 ` Satya Tangirala
  2021-03-09 13:36   ` Jia-Ju Bai
  0 siblings, 1 reply; 3+ messages in thread
From: Satya Tangirala @ 2021-03-09 11:45 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: axboe, linux-block, linux-kernel

On Tue, Mar 09, 2021 at 01:18:12AM -0800, Jia-Ju Bai wrote:
> 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")
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  block/keyslot-manager.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c
> index 2c4a55bea6ca..4dd5da0645bc 100644
> --- a/block/keyslot-manager.c
> +++ b/block/keyslot-manager.c
> @@ -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;
> -- 
> 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?

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

* Re: [PATCH] block: keyslot-manager: fix error return code of blk_ksm_evict_key()
  2021-03-09 11:45 ` Satya Tangirala
@ 2021-03-09 13:36   ` Jia-Ju Bai
  0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2021-03-09 13:36 UTC (permalink / raw)
  To: Satya Tangirala; +Cc: axboe, linux-block, linux-kernel



On 2021/3/9 19:45, Satya Tangirala wrote:
> On Tue, Mar 09, 2021 at 01:18:12AM -0800, Jia-Ju Bai wrote:
>> 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")
>> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>> ---
>>   block/keyslot-manager.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/block/keyslot-manager.c b/block/keyslot-manager.c
>> index 2c4a55bea6ca..4dd5da0645bc 100644
>> --- a/block/keyslot-manager.c
>> +++ b/block/keyslot-manager.c
>> @@ -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;
>> -- 
>> 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

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

end of thread, other threads:[~2021-03-09 13:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-09  9:18 [PATCH] block: keyslot-manager: fix error return code of blk_ksm_evict_key() Jia-Ju Bai
2021-03-09 11:45 ` Satya Tangirala
2021-03-09 13:36   ` Jia-Ju Bai

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).