Commit 88d31ea2 authored by Rakesh Pandit's avatar Rakesh Pandit Committed by Jens Axboe

lightnvm: protect target type list with correct locks

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: 5cd90785 ("lightnvm: remove nested lock conflict with mm")
Signed-off-by: default avatarRakesh Pandit <rakesh@tuxera.com>
Reviewed-by: default avatarJavier González <javier@cnexlabs.com>
Signed-off-by: default avatarMatias Bjørling <m@bjorling.me>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent bb6aa6f0
...@@ -589,9 +589,9 @@ void nvm_unregister_tgt_type(struct nvm_tgt_type *tt) ...@@ -589,9 +589,9 @@ void nvm_unregister_tgt_type(struct nvm_tgt_type *tt)
if (!tt) if (!tt)
return; return;
down_write(&nvm_lock); down_write(&nvm_tgtt_lock);
list_del(&tt->list); list_del(&tt->list);
up_write(&nvm_lock); up_write(&nvm_tgtt_lock);
} }
EXPORT_SYMBOL(nvm_unregister_tgt_type); EXPORT_SYMBOL(nvm_unregister_tgt_type);
...@@ -1195,7 +1195,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) ...@@ -1195,7 +1195,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
info->version[1] = NVM_VERSION_MINOR; info->version[1] = NVM_VERSION_MINOR;
info->version[2] = NVM_VERSION_PATCH; info->version[2] = NVM_VERSION_PATCH;
down_write(&nvm_lock); down_write(&nvm_tgtt_lock);
list_for_each_entry(tt, &nvm_tgt_types, list) { list_for_each_entry(tt, &nvm_tgt_types, list) {
struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter]; 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) ...@@ -1208,7 +1208,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
} }
info->tgtsize = tgt_iter; info->tgtsize = tgt_iter;
up_write(&nvm_lock); up_write(&nvm_tgtt_lock);
if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) { if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) {
kfree(info); kfree(info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment