From c6c70c074633569447be4bfd2b694a1c294015bd Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Mon, 30 Apr 2018 21:28:10 +0000 Subject: [PATCH] Fix use-after-free in nvme_qpair_destroy(). dma_tag_payload should not be destroyed before payload_dma_map, and seems it should be used there instead of dma_tag to match creation. Sponsored by: iXsystems, Inc. --- sys/dev/nvme/nvme_qpair.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sys/dev/nvme/nvme_qpair.c b/sys/dev/nvme/nvme_qpair.c index 576110d100ae..aa0fb81a9455 100644 --- a/sys/dev/nvme/nvme_qpair.c +++ b/sys/dev/nvme/nvme_qpair.c @@ -690,21 +690,22 @@ nvme_qpair_destroy(struct nvme_qpair *qpair) qpair->queuemem_map); } - if (qpair->dma_tag) - bus_dma_tag_destroy(qpair->dma_tag); - - if (qpair->dma_tag_payload) - bus_dma_tag_destroy(qpair->dma_tag_payload); - if (qpair->act_tr) free(qpair->act_tr, M_NVME); while (!TAILQ_EMPTY(&qpair->free_tr)) { tr = TAILQ_FIRST(&qpair->free_tr); TAILQ_REMOVE(&qpair->free_tr, tr, tailq); - bus_dmamap_destroy(qpair->dma_tag, tr->payload_dma_map); + bus_dmamap_destroy(qpair->dma_tag_payload, + tr->payload_dma_map); free(tr, M_NVME); } + + if (qpair->dma_tag) + bus_dma_tag_destroy(qpair->dma_tag); + + if (qpair->dma_tag_payload) + bus_dma_tag_destroy(qpair->dma_tag_payload); } static void