Spdk/module/bdev
Mike Gerdts b240c2b103 lvol: lvol destruction race leads to null deref
As an lvolstore is being destroyed, _vbdev_lvs_remove() starts an
interation through the lvols to delete each one, ultimately leading to
the destruction of the lvolstore with a call to lvs_free(). The callback
passed to vbdev_lvs_destruct() is always called asynchronously via
spdk_io_device_unregister() in bs_free().

When the lvolstore resides on bdevs that perform async IO (i.e. most
bdevs other than malloc), this gives a small window when the lvol bdev
is not registered but a lookup with spdk_lvol_get_by_uuid() or
spdk_lvol_get_by_names() will succeed. If rpc_bdev_lvol_delete() runs
during this window, it can get a reference to an lvol that has just been
unregistered and lvol->blob may be NULL. This lvol is then passed to
vbdev_lvol_destroy().

Before this fix, vbdev_lvol_destroy() would call:

   spdk_blob_is_degraded(lvol->blob);

Which would then lead to a NULL pointer dereference, as
spdk_blob_is_degraded() assumes a valid blob is passed. While a NULL
check would avoid this particular problem, a NULL blob is not
necessarily caused by the condition described above. It would better to
flag the lvstore's destruction before returning from
vbdev_lvs_destruct() and use that flag to prevent operations on the
lvolstore that is being deleted. Such a flag already exists in the form
of 'lvs_bdev->req != NULL', but that is set too late to close this race.

This fix introduces lvs_bdev->removal_in_progress which is set prior to
returning from vbdev_lvs_unload() and vbdev_lvs_destruct(). It is
checked by vbdev_lvol_destroy() before trying to destroy the lvol.  Now,
any lvol destruction initiated by something other than
vbdev_lvs_destruct() while an lvolstore unload or destroy is in progress
will fail with -ENODEV.

Fixes issue: #2998

Signed-off-by: Mike Gerdts <mgerdts@nvidia.com>
Change-Id: I4d861879097703b0d8e3180e6de7ad6898f340fd
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17891
Community-CI: Mellanox Build Bot
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
2023-05-09 17:58:11 +08:00
..
aio so_ver: increase all major versions 2023-01-24 08:37:21 +00:00
compress accel: move accel_module.h to include/spdk 2023-05-09 17:58:11 +08:00
crypto bdev/crypto: Put accel buffer when write completes 2023-05-09 17:58:11 +08:00
daos bdev/daos: using SPDK_CONTAINEROF instead of container_of 2023-05-09 17:58:11 +08:00
delay bdev/delay: add uuid option 2023-03-08 08:46:16 +00:00
error bdev/error: add option to provide UUID for error bdev 2023-05-09 17:58:11 +08:00
ftl module/bdev: Use error_response() rather than bool_response(false) for JSON RPCs 2023-01-31 21:40:09 +00:00
gpt bdev_gpt: use unique partition GUID as bdev UUID 2023-05-09 17:58:11 +08:00
iscsi bdev/iscsi: fix use-after-free in bdev_iscsi_command_cb() 2023-03-16 07:24:56 +00:00
lvol lvol: lvol destruction race leads to null deref 2023-05-09 17:58:11 +08:00
malloc bdev/malloc: report accel sequence support 2023-05-09 17:58:11 +08:00
null bdev: delete UUID generation from ephemeral bdevs 2023-05-09 17:58:11 +08:00
nvme bdev_nvme: fix heap-use-after-free when detaching controller 2023-05-09 17:58:11 +08:00
ocf Revert "deprecation: remove Open CAS Framework" 2023-05-09 17:58:11 +08:00
passthru bdev: remove spdk_bdev_ext_io_opts from spdk_bdev_io 2023-02-16 10:09:35 +00:00
raid module/raid: specify memory domain support per raid module 2023-05-09 17:58:11 +08:00
rbd bdev/rbd: Do not submit IOs through thread sending. 2023-05-09 17:58:11 +08:00
split so_ver: increase all major versions 2023-01-24 08:37:21 +00:00
uring include: add libgen.h to stdinc.h 2023-05-09 17:58:11 +08:00
virtio so_ver: increase all major versions 2023-01-24 08:37:21 +00:00
xnvme bdev/xnvme: Use bdev_unregister_by_name() to delete a xnvme bdev 2023-01-31 21:40:09 +00:00
zone_block module/bdev: Use error_response() rather than bool_response(false) for JSON RPCs 2023-01-31 21:40:09 +00:00
Makefile bdev/pmem: Removed bdev pmem implementation 2023-03-09 09:21:23 +00:00