Skip to content

Commit 8b77fa6

Browse files
Ruozhu LiChristoph Hellwig
authored andcommitted
nvme: fix use after free when disconnecting a reconnecting ctrl
A crash happens when trying to disconnect a reconnecting ctrl: 1) The network was cut off when the connection was just established, scan work hang there waiting for some IOs complete. Those I/Os were retried because we return BLK_STS_RESOURCE to blk in reconnecting. 2) After a while, I tried to disconnect this connection. This procedure also hangs because it tried to obtain ctrl->scan_lock. It should be noted that now we have switched the controller state to NVME_CTRL_DELETING. 3) In nvme_check_ready(), we always return true when ctrl->state is NVME_CTRL_DELETING, so those retrying I/Os were issued to the bottom device which was already freed. To fix this, when ctrl->state is NVME_CTRL_DELETING, issue cmd to bottom device only when queue state is live. If not, return host path error to the block layer Signed-off-by: Ruozhu Li <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent c7c15ae commit 8b77fa6

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

drivers/nvme/host/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
666666
struct request *rq)
667667
{
668668
if (ctrl->state != NVME_CTRL_DELETING_NOIO &&
669+
ctrl->state != NVME_CTRL_DELETING &&
669670
ctrl->state != NVME_CTRL_DEAD &&
670671
!test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) &&
671672
!blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH))

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ static inline bool nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
709709
return true;
710710
if (ctrl->ops->flags & NVME_F_FABRICS &&
711711
ctrl->state == NVME_CTRL_DELETING)
712-
return true;
712+
return queue_live;
713713
return __nvme_check_ready(ctrl, rq, queue_live);
714714
}
715715
int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,

0 commit comments

Comments
 (0)