linux/drivers/nvme/target
Israel Rukshin 21780d1fd6 nvmet: Fix controller use after free
commit 1a3f540d63 upstream.

After nvmet_install_queue() sets sq->ctrl calling to nvmet_sq_destroy()
reduces the controller refcount. In case nvmet_install_queue() fails,
calling to nvmet_ctrl_put() is done twice (at nvmet_sq_destroy and
nvmet_execute_io_connect/nvmet_execute_admin_connect) instead of once for
the queue which leads to use after free of the controller. Fix this by set
NULL at sq->ctrl in case of a failure at nvmet_install_queue().

The bug leads to the following Call Trace:

[65857.994862] refcount_t: underflow; use-after-free.
[65858.108304] Workqueue: events nvmet_rdma_release_queue_work [nvmet_rdma]
[65858.115557] RIP: 0010:refcount_warn_saturate+0xe5/0xf0
[65858.208141] Call Trace:
[65858.211203]  nvmet_sq_destroy+0xe1/0xf0 [nvmet]
[65858.216383]  nvmet_rdma_release_queue_work+0x37/0xf0 [nvmet_rdma]
[65858.223117]  process_one_work+0x167/0x370
[65858.227776]  worker_thread+0x49/0x3e0
[65858.232089]  kthread+0xf5/0x130
[65858.235895]  ? max_active_store+0x80/0x80
[65858.240504]  ? kthread_bind+0x10/0x10
[65858.244832]  ret_from_fork+0x1f/0x30
[65858.249074] ---[ end trace f82d59250b54beb7 ]---

Fixes: bb1cc74790 ("nvmet: implement valid sqhd values in completions")
Fixes: 1672ddb8d6 ("nvmet: Add install_queue callout")
Signed-off-by: Israel Rukshin <israelr@mellanox.com>
Reviewed-by: Max Gurtovoy <maxg@mellanox.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-02-11 04:35:08 -08:00
..
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile nvmet: introduce target-side trace 2019-06-21 11:15:46 +02:00
admin-cmd.c nvmet: fix a wrong error status returned in error log page 2019-09-12 08:50:46 -07:00
configfs.c nvmet: Fix use-after-free bug when a port is removed 2019-07-31 17:57:06 -07:00
core.c nvmet-file: fix nvmet_file_flush() always returning an error 2019-07-31 17:57:21 -07:00
discovery.c nvmet: Use PTR_ERR_OR_ZERO() in nvmet_init_discovery() 2019-09-12 08:50:46 -07:00
fabrics-cmd.c nvmet: Fix controller use after free 2020-02-11 04:35:08 -08:00
fc.c nvme: introduce nvme_is_fabrics to check fabrics cmd 2019-06-21 11:08:38 +02:00
fcloop.c nvme_fc: add module to ops template to allow module references 2020-01-09 10:19:41 +01:00
io-cmd-bdev.c nvmet: change ppl to lpp 2019-09-23 13:59:49 -07:00
io-cmd-file.c nvmet-file: clamp-down file namespace lba_shift 2019-04-25 16:51:19 +02:00
loop.c nvmet-loop: fix possible leakage during error flow 2019-10-15 22:47:28 +09:00
nvmet.h nvmet: Fix use-after-free bug when a port is removed 2019-07-31 17:57:06 -07:00
rdma.c nvmet: rename nvme_completion instances from rsp to cqe 2019-04-25 16:41:26 +02:00
tcp.c nvmet-tcp: remove superflous check on request sgl 2019-09-25 12:53:14 -07:00
trace.c nvmet: trace: parse Get LBA Status command in detail 2019-08-29 12:55:01 -07:00
trace.h nvmet: introduce target-side trace 2019-06-21 11:15:46 +02:00