mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-23 20:24:12 +08:00
nvmet-rdma: fix possible bad dereference when freeing rsps
[ Upstream commit 73964c1d07
]
It is possible that the host connected and saw a cm established
event and started sending nvme capsules on the qp, however the
ctrl did not yet see an established event. This is why the
rsp_wait_list exists (for async handling of these cmds, we move
them to a pending list).
Furthermore, it is possible that the ctrl cm times out, resulting
in a connect-error cm event. in this case we hit a bad deref [1]
because in nvmet_rdma_free_rsps we assume that all the responses
are in the free list.
We are freeing the cmds array anyways, so don't even bother to
remove the rsp from the free_list. It is also guaranteed that we
are not racing anything when we are releasing the queue so no
other context accessing this array should be running.
[1]:
--
Workqueue: nvmet-free-wq nvmet_rdma_free_queue_work [nvmet_rdma]
[...]
pc : nvmet_rdma_free_rsps+0x78/0xb8 [nvmet_rdma]
lr : nvmet_rdma_free_queue_work+0x88/0x120 [nvmet_rdma]
Call trace:
nvmet_rdma_free_rsps+0x78/0xb8 [nvmet_rdma]
nvmet_rdma_free_queue_work+0x88/0x120 [nvmet_rdma]
process_one_work+0x1ec/0x4a0
worker_thread+0x48/0x490
kthread+0x158/0x160
ret_from_fork+0x10/0x18
--
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
e9c0aa6c3d
commit
73c50bd104
@ -473,12 +473,8 @@ nvmet_rdma_alloc_rsps(struct nvmet_rdma_queue *queue)
|
||||
return 0;
|
||||
|
||||
out_free:
|
||||
while (--i >= 0) {
|
||||
struct nvmet_rdma_rsp *rsp = &queue->rsps[i];
|
||||
|
||||
list_del(&rsp->free_list);
|
||||
nvmet_rdma_free_rsp(ndev, rsp);
|
||||
}
|
||||
while (--i >= 0)
|
||||
nvmet_rdma_free_rsp(ndev, &queue->rsps[i]);
|
||||
kfree(queue->rsps);
|
||||
out:
|
||||
return ret;
|
||||
@ -489,12 +485,8 @@ static void nvmet_rdma_free_rsps(struct nvmet_rdma_queue *queue)
|
||||
struct nvmet_rdma_device *ndev = queue->dev;
|
||||
int i, nr_rsps = queue->recv_queue_size * 2;
|
||||
|
||||
for (i = 0; i < nr_rsps; i++) {
|
||||
struct nvmet_rdma_rsp *rsp = &queue->rsps[i];
|
||||
|
||||
list_del(&rsp->free_list);
|
||||
nvmet_rdma_free_rsp(ndev, rsp);
|
||||
}
|
||||
for (i = 0; i < nr_rsps; i++)
|
||||
nvmet_rdma_free_rsp(ndev, &queue->rsps[i]);
|
||||
kfree(queue->rsps);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user