Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1733338 > unrolled thread

[PATCH V2] lightnvm: protect target type list with correct locks

Started byRakesh Pandit <rakesh@tuxera.com>
First post2017-09-16 20:50 +0200
Last post2017-09-21 13:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH V2] lightnvm: protect target type list with correct locks Rakesh Pandit <rakesh@tuxera.com> - 2017-09-16 20:50 +0200
    Re: [PATCH V2] lightnvm: protect target type list with correct locks Javier González <jg@lightnvm.io> - 2017-09-18 10:00 +0200
      Re: [PATCH V2] lightnvm: protect target type list with correct locks Matias Bjørling <mb@lightnvm.io> - 2017-09-21 13:20 +0200

#1733338 — [PATCH V2] lightnvm: protect target type list with correct locks

FromRakesh Pandit <rakesh@tuxera.com>
Date2017-09-16 20:50 +0200
Subject[PATCH V2] lightnvm: protect target type list with correct locks
Message-ID<uqqk9-5tm-5@gated-at.bofh.it>
nvm_tgt_types list was protected by wrong lock for NVM_INFO ioctl call
and can race with addition or removal of target types.  Also
unregistering target type was not protected correctly.

Fixes: 5cd907853 ("lightnvm: remove nested lock conflict with mm")
Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
---

V2: also add correct lock while unregistering and fix "Fixes" tag at
end.  Note I found these while investigating another issue and
skimming the core code but worth fixing.

 drivers/lightnvm/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 9f9a137..1b8338d 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -589,9 +589,9 @@ void nvm_unregister_tgt_type(struct nvm_tgt_type *tt)
 	if (!tt)
 		return;
 
-	down_write(&nvm_lock);
+	down_write(&nvm_tgtt_lock);
 	list_del(&tt->list);
-	up_write(&nvm_lock);
+	up_write(&nvm_tgtt_lock);
 }
 EXPORT_SYMBOL(nvm_unregister_tgt_type);
 
@@ -1190,7 +1190,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
 	info->version[1] = NVM_VERSION_MINOR;
 	info->version[2] = NVM_VERSION_PATCH;
 
-	down_write(&nvm_lock);
+	down_write(&nvm_tgtt_lock);
 	list_for_each_entry(tt, &nvm_tgt_types, list) {
 		struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter];
 
@@ -1203,7 +1203,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
 	}
 
 	info->tgtsize = tgt_iter;
-	up_write(&nvm_lock);
+	up_write(&nvm_tgtt_lock);
 
 	if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) {
 		kfree(info);
-- 
2.7.4

[toc] | [next] | [standalone]


#1733715

FromJavier González <jg@lightnvm.io>
Date2017-09-18 10:00 +0200
Message-ID<uqZ8e-3dr-13@gated-at.bofh.it>
In reply to#1733338

[Multipart message — attachments visible in raw view] — view raw

> On 16 Sep 2017, at 20.39, Rakesh Pandit <rakesh@tuxera.com> wrote:
> 
> nvm_tgt_types list was protected by wrong lock for NVM_INFO ioctl call
> and can race with addition or removal of target types.  Also
> unregistering target type was not protected correctly.
> 
> Fixes: 5cd907853 ("lightnvm: remove nested lock conflict with mm")
> Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
> ---
> 
> V2: also add correct lock while unregistering and fix "Fixes" tag at
> end.  Note I found these while investigating another issue and
> skimming the core code but worth fixing.
> 
> drivers/lightnvm/core.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index 9f9a137..1b8338d 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -589,9 +589,9 @@ void nvm_unregister_tgt_type(struct nvm_tgt_type *tt)
> 	if (!tt)
> 		return;
> 
> -	down_write(&nvm_lock);
> +	down_write(&nvm_tgtt_lock);
> 	list_del(&tt->list);
> -	up_write(&nvm_lock);
> +	up_write(&nvm_tgtt_lock);
> }
> EXPORT_SYMBOL(nvm_unregister_tgt_type);
> 
> @@ -1190,7 +1190,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
> 	info->version[1] = NVM_VERSION_MINOR;
> 	info->version[2] = NVM_VERSION_PATCH;
> 
> -	down_write(&nvm_lock);
> +	down_write(&nvm_tgtt_lock);
> 	list_for_each_entry(tt, &nvm_tgt_types, list) {
> 		struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter];
> 
> @@ -1203,7 +1203,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
> 	}
> 
> 	info->tgtsize = tgt_iter;
> -	up_write(&nvm_lock);
> +	up_write(&nvm_tgtt_lock);
> 
> 	if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) {
> 		kfree(info);
> --
> 2.7.4

LGTM.

Reviewed-by: Javier González <javier@cnexlabs.com>

[toc] | [prev] | [next] | [standalone]


#1736544

FromMatias Bjørling <mb@lightnvm.io>
Date2017-09-21 13:20 +0200
Message-ID<us7Gq-gp-7@gated-at.bofh.it>
In reply to#1733715
On 09/18/2017 09:53 AM, Javier González wrote:
>> On 16 Sep 2017, at 20.39, Rakesh Pandit <rakesh@tuxera.com> wrote:
>>
>> nvm_tgt_types list was protected by wrong lock for NVM_INFO ioctl call
>> and can race with addition or removal of target types.  Also
>> unregistering target type was not protected correctly.
>>
>> Fixes: 5cd907853 ("lightnvm: remove nested lock conflict with mm")
>> Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
>> ---
>>
>> V2: also add correct lock while unregistering and fix "Fixes" tag at
>> end.  Note I found these while investigating another issue and
>> skimming the core code but worth fixing.
>>
>> drivers/lightnvm/core.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
>> index 9f9a137..1b8338d 100644
>> --- a/drivers/lightnvm/core.c
>> +++ b/drivers/lightnvm/core.c
>> @@ -589,9 +589,9 @@ void nvm_unregister_tgt_type(struct nvm_tgt_type *tt)
>> 	if (!tt)
>> 		return;
>>
>> -	down_write(&nvm_lock);
>> +	down_write(&nvm_tgtt_lock);
>> 	list_del(&tt->list);
>> -	up_write(&nvm_lock);
>> +	up_write(&nvm_tgtt_lock);
>> }
>> EXPORT_SYMBOL(nvm_unregister_tgt_type);
>>
>> @@ -1190,7 +1190,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
>> 	info->version[1] = NVM_VERSION_MINOR;
>> 	info->version[2] = NVM_VERSION_PATCH;
>>
>> -	down_write(&nvm_lock);
>> +	down_write(&nvm_tgtt_lock);
>> 	list_for_each_entry(tt, &nvm_tgt_types, list) {
>> 		struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter];
>>
>> @@ -1203,7 +1203,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
>> 	}
>>
>> 	info->tgtsize = tgt_iter;
>> -	up_write(&nvm_lock);
>> +	up_write(&nvm_tgtt_lock);
>>
>> 	if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) {
>> 		kfree(info);
>> --
>> 2.7.4
> 
> LGTM.
> 
> Reviewed-by: Javier González <javier@cnexlabs.com>
> 

Thanks Rakesh.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web