lightnvm: protect target type list with correct locks
authorRakesh Pandit <rakesh@tuxera.com>
Fri, 13 Oct 2017 12:45:52 +0000 (14:45 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 13 Oct 2017 14:34:57 +0000 (08:34 -0600)
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>
Reviewed-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/lightnvm/core.c

index c490711cf0f4a374c4c1396c219972c001595daf..ee2b6d77199019a3ecb990f048a8876cc4de2190 100644 (file)
@@ -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);
 
@@ -1195,7 +1195,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];
 
@@ -1208,7 +1208,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);